Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DETA] fix backbone freeze/unfreeze function #27843

Merged
merged 8 commits into from Dec 11, 2023

Conversation

SangbumChoi
Copy link
Contributor

What does this PR do?

Fixes # (issue)

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

Since deta model does not have vision

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[4], line 1
----> 1 model.model.freeze_backbone()

File /opt/conda/lib/python3.10/site-packages/transformers/models/deta/modeling_deta.py:1419, in DetaModel.freeze_backbone(self)
   1418 def freeze_backbone(self):
-> 1419     for name, param in self.backbone.conv_encoder.model.named_parameters():
   1420         param.requires_grad_(False)

File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1695, in Module.__getattr__(self, name)
   1693     if name in modules:
   1694         return modules[name]
-> 1695 raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")

AttributeError: 'DetaBackboneWithPositionalEncodings' object has no attribute 'conv_encoder'

test can be done by

from transformers import DetaForObjectDetection

model = DetaForObjectDetection.from_pretrained("jozhang97/deta-swin-large")

model.model.freeze_backbone()

@amyeroberts Can you confirm this modification?

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Left a few nits for now 😉

src/transformers/models/deta/modeling_deta.py Outdated Show resolved Hide resolved
src/transformers/models/deta/modeling_deta.py Outdated Show resolved Hide resolved
SangbumChoi and others added 4 commits December 6, 2023 09:05
Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com>
Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com>
@SangbumChoi
Copy link
Contributor Author

SangbumChoi commented Dec 8, 2023

@ArthurZucker Hi Arthur, can you review this test case modification for DETA? a583fa7
Because I do not fully understand CircleCI when this testing function will be called in transformers
Now I think I understand the CI piplines.

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks you!

@ArthurZucker
Copy link
Collaborator

For the last CI you need to run make style with ruff==0.1.5

@SangbumChoi
Copy link
Contributor Author

root@9603895c7c37:/mnt/nas2/users/sbchoi/transformers# make style
ruff check examples tests src utils setup.py conftest.py --fix
ruff format examples tests src utils setup.py conftest.py
2706 files left unchanged
make autogenerate_code
make[1]: Entering directory '/mnt/nas2/users/sbchoi/transformers'
running deps_table_update
updating src/transformers/dependency_versions_table.py
make[1]: Leaving directory '/mnt/nas2/users/sbchoi/transformers'
make extra_style_checks
make[1]: Entering directory '/mnt/nas2/users/sbchoi/transformers'
python utils/custom_init_isort.py
python utils/sort_auto_mappings.py
python utils/check_doc_toc.py --fix_and_overwrite
make[1]: Leaving directory '/mnt/nas2/users/sbchoi/transformers'

running make style doesn't change anything, and the last CI seems irrelevant to this PR.

Would reformat: src/transformers/models/bloom/modeling_bloom.py
Would reformat: src/transformers/models/fuyu/image_processing_fuyu.py
Would reformat: src/transformers/models/mpt/modeling_mpt.py
3 files would be reformatted, 2416 files left unchanged

Exited with code exit status 1

did I missed something?
@ArthurZucker

@ArthurZucker
Copy link
Collaborator

It's alright just revert the changes and we'll be alright

@SangbumChoi
Copy link
Contributor Author

SangbumChoi commented Dec 11, 2023

@ArthurZucker Done by just syncing the fork of my original repo!

@ArthurZucker ArthurZucker merged commit 235be08 into huggingface:main Dec 11, 2023
17 checks passed
@ArthurZucker
Copy link
Collaborator

Thanks for the contribution! 🤗

iantbutler01 pushed a commit to LaconicAI/transformers that referenced this pull request Dec 16, 2023
* [DETA] fix freeze/unfreeze function

* Update src/transformers/models/deta/modeling_deta.py

Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com>

* Update src/transformers/models/deta/modeling_deta.py

Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com>

* add freeze/unfreeze test case in DETA

* fix type

* fix typo 2

---------

Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com>
staghado pushed a commit to staghado/transformers that referenced this pull request Jan 15, 2024
* [DETA] fix freeze/unfreeze function

* Update src/transformers/models/deta/modeling_deta.py

Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com>

* Update src/transformers/models/deta/modeling_deta.py

Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com>

* add freeze/unfreeze test case in DETA

* fix type

* fix typo 2

---------

Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants