Error loading model using AutoModel.from_pretrained

#96
by sjoshi-wm - opened

Unable to load jinaai/jina-embeddings-v3 with AutoModel.from_pretrained.

Env

einops                       0.8.0
huggingface-hub              0.26.2
sentence-transformers        3.3.1
transformers                 4.46.3

Getting the following error:

tokenizer_config.json:โ€‡100%
โ€‡1.15k/1.15kโ€‡[00:00<00:00,โ€‡75.8kB/s]
tokenizer.json:โ€‡100%
โ€‡17.1M/17.1Mโ€‡[00:00<00:00,โ€‡238MB/s]
special_tokens_map.json:โ€‡100%
โ€‡964/964โ€‡[00:00<00:00,โ€‡102kB/s]
config.json:โ€‡100%
โ€‡1.80k/1.80kโ€‡[00:00<00:00,โ€‡176kB/s]
configuration_xlm_roberta.py:โ€‡100%
โ€‡6.54k/6.54kโ€‡[00:00<00:00,โ€‡1.13MB/s]
modeling_lora.py:โ€‡100%
โ€‡15.4k/15.4kโ€‡[00:00<00:00,โ€‡1.50MB/s]

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
Cell In[6], line 12
      7 # load model and tokenizer
      8 tokenizer = AutoTokenizer.from_pretrained(
      9     MODEL_NAME, trust_remote_code=True
     10 )
---> 12 model = AutoModel.from_pretrained(
     13     MODEL_NAME, trust_remote_code=True, device_map='auto', torch_dtype=torch.float16
     14 )

File ~/anaconda3/envs/contextual_representation_experiments/lib/python3.9/site-packages/transformers/models/auto/auto_factory.py:553, in _BaseAutoModelClass.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
    551 if has_remote_code and trust_remote_code:
    552     class_ref = config.auto_map[cls.__name__]
--> 553     model_class = get_class_from_dynamic_module(
    554         class_ref, pretrained_model_name_or_path, code_revision=code_revision, **hub_kwargs, **kwargs
    555     )
    556     _ = hub_kwargs.pop("code_revision", None)
    557     cls.register(config.__class__, model_class, exist_ok=True)

File ~/anaconda3/envs/contextual_representation_experiments/lib/python3.9/site-packages/transformers/dynamic_module_utils.py:552, in get_class_from_dynamic_module(class_reference, pretrained_model_name_or_path, cache_dir, force_download, resume_download, proxies, token, revision, local_files_only, repo_type, code_revision, **kwargs)
    539 # And lastly we get the class inside our newly created module
    540 final_module = get_cached_module_file(
    541     repo_id,
    542     module_file + ".py",
   (...)
    550     repo_type=repo_type,
    551 )
--> 552 return get_class_in_module(class_name, final_module, force_reload=force_download)

File ~/anaconda3/envs/contextual_representation_experiments/lib/python3.9/site-packages/transformers/dynamic_module_utils.py:237, in get_class_in_module(class_name, module_path, force_reload)
    234 module_spec = importlib.util.spec_from_file_location(name, location=module_file)
    236 # Hash the module file and all its relative imports to check if we need to reload it
--> 237 module_files: List[Path] = [module_file] + sorted(map(Path, get_relative_import_files(module_file)))
    238 module_hash: str = hashlib.sha256(b"".join(bytes(f) + f.read_bytes() for f in module_files)).hexdigest()
    240 module: ModuleType

File ~/anaconda3/envs/contextual_representation_experiments/lib/python3.9/site-packages/transformers/dynamic_module_utils.py:128, in get_relative_import_files(module_file)
    126 new_imports = []
    127 for f in files_to_check:
--> 128     new_imports.extend(get_relative_imports(f))
    130 module_path = Path(module_file).parent
    131 new_import_files = [str(module_path / m) for m in new_imports]

File ~/anaconda3/envs/contextual_representation_experiments/lib/python3.9/site-packages/transformers/dynamic_module_utils.py:97, in get_relative_imports(module_file)
     87 def get_relative_imports(module_file: Union[str, os.PathLike]) -> List[str]:
     88     """
     89     Get the list of modules that are relatively imported in a module file.
     90 
   (...)
     95         `List[str]`: The list of relative imports in the module.
     96     """
---> 97     with open(module_file, "r", encoding="utf-8") as f:
     98         content = f.read()
    100     # Imports of the form `import .xxx`

FileNotFoundError: [Errno 2] No such file or directory: '/home/ec2-user/.cache/huggingface/modules/transformers_modules/jinaai/xlm-roberta-flash-implementation/54b019f80aa9a0ce328a34ecb6b1d607af7d58de/rotary.py'

I also have this error!

delete /home/yourusername/.cache/huggingface/modules/transformers_modules/jinaai, then retry

I also have this error!

!pip install flash-attn --no-build-isolation

This command fixed the error too

Sign up or log in to comment