KhoomeiK/LlamaGym

ImportError: cannot import name 'top_k_top_p_filtering' from 'transformers' (/home/eito/AIExperiments/LlamaGym/myenv/lib/python3.10/site-packages/transformers/__init__.py)

Closed this issue · 4 comments

It seems my import fails, when I try and import Agent from llamagym:

from llamagym import Agent
(myenv) eito@clouddev-3:~/AIExperiments/LlamaGym$ python examples/my_example.py 
Traceback (most recent call last):
  File "/home/eito/AIExperiments/LlamaGym/examples/my_example.py", line 1, in <module>
    from llamagym import Agent
  File "/home/eito/AIExperiments/LlamaGym/myenv/lib/python3.10/site-packages/llamagym/__init__.py", line 1, in <module>
    from .agent import Agent
  File "/home/eito/AIExperiments/LlamaGym/myenv/lib/python3.10/site-packages/llamagym/agent.py", line 6, in <module>
    from trl import (
  File "/home/eito/AIExperiments/LlamaGym/myenv/lib/python3.10/site-packages/trl/__init__.py", line 5, in <module>
    from .core import set_seed
  File "/home/eito/AIExperiments/LlamaGym/myenv/lib/python3.10/site-packages/trl/core.py", line 25, in <module>
    from transformers import top_k_top_p_filtering
ImportError: cannot import name 'top_k_top_p_filtering' from 'transformers' (/home/eito/AIExperiments/LlamaGym/myenv/lib/python3.10/site-packages/transformers/__init__.py)

Are you finish this problem?

No still stuck

I solved this problem by following the steps:1. sudo apt install build-essential libffi-dev ; 2. I strictly follow the dependent version in file pyproject.toml for pip installation: "python = "^3.9"
torch = "^2.1.2"
transformers = "^4.36.2"
trl = "^0.7.9"
gymnasium = "^0.29.1"
peft = "^0.7.1"
accelerate = "^0.21.0"
bitsandbytes = "^0.40.0"
textworld = "^1.6.1"
scipy = "^1.12.0"
wandb = "^0.16.4"". Atfer this, I finish it.

Seems like a versioning issue with your transformers installation. Please use poetry with our provided pyproject.toml please :)