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

Fix import error from deprecation in transformers #1415

Merged
merged 2 commits into from
Mar 11, 2024
Merged

Conversation

lewtun
Copy link
Member

@lewtun lewtun commented Mar 11, 2024

The top_k_top_p_filtering() method will be deprecated (i.e. removed) from transformers >= 4.39 and the simplest solution is to copy the method directly into trl

Closes #1409

Copy link
Contributor

@younesbelkada younesbelkada left a comment

Choose a reason for hiding this comment

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

Thanks so much @lewtun !
It says:

ImportError: cannot import name 'TopKLogitsWarper' from 'transformers.generation_utils' (/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/transformers/generation_utils.py)

Do we need to guard the import for transformers main that have TopKLogitsWarper ?

@lewtun
Copy link
Member Author

lewtun commented Mar 11, 2024

Thanks so much @lewtun ! It says:

ImportError: cannot import name 'TopKLogitsWarper' from 'transformers.generation_utils' (/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/transformers/generation_utils.py)

Do we need to guard the import for transformers main that have TopKLogitsWarper ?

Both logits processors are present as far back as our min required transformers version (v31.0): https://huggingface.co/docs/transformers/v4.31.0/en/internal/generation_utils#transformers.TopPLogitsWarper

The new import path should work across all of them I think!

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

pacman100 added a commit to pacman100/trl that referenced this pull request Mar 11, 2024
Copy link
Contributor

@younesbelkada younesbelkada left a comment

Choose a reason for hiding this comment

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

Thanks so much @lewtun ! 🚀

@younesbelkada younesbelkada merged commit 7630f87 into main Mar 11, 2024
9 checks passed
@younesbelkada younesbelkada deleted the fix-imports branch March 11, 2024 12:23
younesbelkada added a commit that referenced this pull request Mar 13, 2024
* don't do mp casting

* don't use `prepare_for_kbit` when using fsdp+qlora or dsz3+qlora

* changes to enable fsdp+qlora and dsz3+qlora

* revert

* Update sft_trainer.py

* quality

* fix deprecation using changes from PR #1415

* fixes

* quality

* Update trl/trainer/sft_trainer.py

Co-authored-by: Younes Belkada <49240599+younesbelkada@users.noreply.github.com>

* quality

* relaunch tests

---------

Co-authored-by: Younes Belkada <49240599+younesbelkada@users.noreply.github.com>
@Haruka1307
Copy link

Thanks so much @lewtun ! It says:

ImportError: cannot import name 'TopKLogitsWarper' from 'transformers.generation_utils' (/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/transformers/generation_utils.py)

Do we need to guard the import for transformers main that have TopKLogitsWarper ?

Both logits processors are present as far back as our min required transformers version (v31.0): https://huggingface.co/docs/transformers/v4.31.0/en/internal/generation_utils#transformers.TopPLogitsWarper

The new import path should work across all of them I think!

I wonder the statement is
from transformers.generation import TopKLogitsWarper, TopPLogitsWarper
I check the source code updated in trl .
1710408796081

kashif pushed a commit that referenced this pull request Mar 14, 2024
* don't do mp casting

* don't use `prepare_for_kbit` when using fsdp+qlora or dsz3+qlora

* changes to enable fsdp+qlora and dsz3+qlora

* revert

* Update sft_trainer.py

* quality

* fix deprecation using changes from PR #1415

* fixes

* quality

* Update trl/trainer/sft_trainer.py

Co-authored-by: Younes Belkada <49240599+younesbelkada@users.noreply.github.com>

* quality

* relaunch tests

---------

Co-authored-by: Younes Belkada <49240599+younesbelkada@users.noreply.github.com>
kashif pushed a commit to fe1ixxu/trl that referenced this pull request Mar 15, 2024
* Fix import error from  deprecation in transformers

* Fix import path
kashif pushed a commit to fe1ixxu/trl that referenced this pull request Mar 15, 2024
* don't do mp casting

* don't use `prepare_for_kbit` when using fsdp+qlora or dsz3+qlora

* changes to enable fsdp+qlora and dsz3+qlora

* revert

* Update sft_trainer.py

* quality

* fix deprecation using changes from PR huggingface#1415

* fixes

* quality

* Update trl/trainer/sft_trainer.py

Co-authored-by: Younes Belkada <49240599+younesbelkada@users.noreply.github.com>

* quality

* relaunch tests

---------

Co-authored-by: Younes Belkada <49240599+younesbelkada@users.noreply.github.com>
lapp0 pushed a commit to lapp0/trl that referenced this pull request May 10, 2024
* Fix import error from  deprecation in transformers

* Fix import path
lapp0 pushed a commit to lapp0/trl that referenced this pull request May 10, 2024
* don't do mp casting

* don't use `prepare_for_kbit` when using fsdp+qlora or dsz3+qlora

* changes to enable fsdp+qlora and dsz3+qlora

* revert

* Update sft_trainer.py

* quality

* fix deprecation using changes from PR huggingface#1415

* fixes

* quality

* Update trl/trainer/sft_trainer.py

Co-authored-by: Younes Belkada <49240599+younesbelkada@users.noreply.github.com>

* quality

* relaunch tests

---------

Co-authored-by: Younes Belkada <49240599+younesbelkada@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.

Can not import name top_k_top_p_filtering
4 participants