cannot import name 'NEED_SETUP_CACHE_CLASSES_MAPPING'

#11
by uygarkurt - opened

Hi. Currently, I can load this model using HuggingFace from_pretrained with the transformers==4.44.2.

However, I need to use it with transformers>=4.53.0. When I do that, I get the following:

model = AutoModelForCausalLM.from_pretrained(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/transformers/models/auto/auto_factory.py", line 586, in from_pretrained
    model_class = get_class_from_dynamic_module(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "home.venv/lib/python3.12/site-packages/transformers/dynamic_module_utils.py", line 581, in get_class_from_dynamic_module
    return get_class_in_module(class_name, final_module, force_reload=force_download)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "home.venv/lib/python3.12/site-packages/transformers/dynamic_module_utils.py", line 276, in get_class_in_module
    module_spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/home/.cache/huggingface/modules/transformers_modules/Llama-3_3-Nemotron-Super-49B-v1_5/modeling_decilm.py", line 30, in <module>
    from transformers.generation.utils import NEED_SETUP_CACHE_CLASSES_MAPPING, GenerationMixin, GenerateOutput
ImportError: cannot import name 'NEED_SETUP_CACHE_CLASSES_MAPPING' from 'transformers.generation.utils' (home.venv/lib/python3.12/site-packages/transformers/generation/utils.py)

Is there any solution to it? Thank you.

uygarkurt changed discussion title from transformers>=4.53.0 Support to cannot import name 'NEED_SETUP_CACHE_CLASSES_MAPPING'

You can just delete the NEED_SETUP_CACHE_CLASSES_MAPPING references from the code. But then there will be no caching so decoding will be slow. I did some modifications and the caching seems to be working with the latest transformers version. My code is a bit messy right now, maybe i will do a pr later this week.

Sign up or log in to comment