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

Can not import name top_k_top_p_filtering #1409

Closed
chillestt opened this issue Mar 8, 2024 · 8 comments · Fixed by #1415
Closed

Can not import name top_k_top_p_filtering #1409

chillestt opened this issue Mar 8, 2024 · 8 comments · Fixed by #1415

Comments

@chillestt
Copy link

chillestt commented Mar 8, 2024

Hello everyone, I just came across this kind of error, I cannot import trl because of this kind of error:
ImportError: cannot import name 'top_k_top_p_filtering' from 'transformers' (/usr/local/lib/python3.10/dist-packages/transformers/__init__.py)
although I upgrade transformers library, it remained not working

from transformers import top_k_top_p_filtering

@polarbeargo
Copy link

polarbeargo commented Mar 9, 2024

Same here I encountered the same error this week. Last week can imported SFTTrainer without this error. Another developer also bumped into this error this week see this closed issue
git

@dangl00
Copy link

dangl00 commented Mar 9, 2024

Make sure that you have transformers version 4.38.2. Then, importing 'top_k_top_p_filtering' from"transformers.generation.utils" should work.

@SolanaO
Copy link

SolanaO commented Mar 9, 2024

I would like to continue finetuning starcoder2. So I have to install transformers from the source with
!pip install git+https://github.com/huggingface/transformers.git
I already SFT the model, but now I cannot import DPOTrainer. Using transformers 4.38.2 is not feasible as it doesn't recognize starcoder2. It does however solve the issue with DPOTrainer import -- but I need the newest version, which I think is 4.39.*

I tried to install top_k_top_p_filtering (cannot install DPOTRainer becuse of this) as suggested above but I get an error


ImportError Traceback (most recent call last)
in <cell line: 1>()
----> 1 from transformers.generation.utils import top_k_top_p_filtering

ImportError: cannot import name 'top_k_top_p_filtering' from 'transformers.generation.utils' (/usr/local/lib/python3.10/dist-packages/transformers/generation/utils.py)


NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.

What is the workaround for installing DPOTrainer for the latest transformer version? Thanks

@baba-bug
Copy link

baba-bug commented Jul 9, 2024

I use

pip install --upgrade trl

AND it worked for me

@vivekkaradbhajne23
Copy link

i also used

pip install --upgrade trl

and it worked for me

@rachitsaluja
Copy link

Upgrading it worked for me as well.

@GaoMengGladys
Copy link

Upgrading it didn't work for me.555

@rdhande92
Copy link

i also used

pip install --upgrade trl

and it worked for me

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 a pull request may close this issue.

9 participants