allenai / real-toxicity-prompts

Apache License 2.0
189 stars 25 forks source link

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

Open jakeazcona opened 2 years ago

jakeazcona commented 2 years ago

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 commented 2 years ago

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

tea-shaped commented 6 months ago

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!