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

ImportError: cannot import name 'calc_banned_bad_words_ids' from 'transformers.generation_utils' #3

Open
jakeazcona opened this issue Apr 22, 2022 · 2 comments

Comments

@jakeazcona
Copy link

jakeazcona commented Apr 22, 2022

Description

When following the installation guide all goes well. However, if I attempt to run
python -m scripts.run_prompts_experiment --help
(after changing the script name from run_prompts_experiments to run_prompts_experiment) I get the error shown below. Aparently the generations_util.py script does not contain a method called "calc_banned_bad_words_ids".

Full Error

  File "/opt/anaconda3/envs/rtp/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/opt/anaconda3/envs/rtp/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/[...]/allenai/real-toxicity-prompts/scripts/run_prompts_experiment.py", line 10, in <module>
    from generation.generation import gpt2, gpt3, gpt2_affect, gpt2_ctrl, openai_gpt, ctrl, xlm, pplm
  File "/Users/[...]/allenai/real-toxicity-prompts/generation/generation.py", line 18, in <module>
    from generation.gpt2_generation import GPT2Generation
  File "/Users/[...]/allenai/real-toxicity-prompts/generation/gpt2_generation.py", line 7, in <module>
    from transformers.generation_utils import top_k_top_p_filtering, calc_banned_bad_words_ids
ImportError: cannot import name 'calc_banned_bad_words_ids' from 'transformers.generation_utils' (/opt/anaconda3/envs/rtp/lib/python3.8/site-packages/transformers/generation_utils.py)

Things I have tried

I thought this was a versioning issue. So I attempted to install a prior version of transformers (4.12.5) but the error was the same

I also tried to (in the most hacky way, please don't judge) to add the method to the file itself in hopes of getting a different type of error... However I got another missing method error.

@hadarishav
Copy link

@jakeazcona I am having the same error. Were you able to fix it?

@tea-shaped
Copy link

tea-shaped commented Apr 14, 2024

This has been asked ages ago but I'm also running into this error. Did you ever get it fixed? Would really appreciate any pointers!

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

No branches or pull requests

3 participants