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

Python suffix stripping in transformers.dynamic_model_utils.get_class_in_module strips additional characters #31061

Closed
2 of 4 tasks
gmastrapas opened this issue May 27, 2024 · 2 comments · Fixed by #31108
Closed
2 of 4 tasks
Labels
bug Should Fix This has been identified as a bug and should be fixed.

Comments

@gmastrapas
Copy link

System Info

  • transformers version: 4.41.1
  • Platform: macOS-14.4.1-x86_64-i386-64bit
  • Python version: 3.10.10
  • Huggingface_hub version: 0.23.2
  • Safetensors version: 0.4.2
  • Accelerate version: 0.28.0
  • Accelerate config: not found
  • PyTorch version (GPU?): 2.1.2 (False)
  • Tensorflow version (GPU?): 2.15.0 (False)
  • Flax version (CPU?/GPU?/TPU?): not installed (NA)
  • Jax version: not installed
  • JaxLib version: not installed
  • Using GPU in script?: No
  • Using distributed or parallel set-up in script?: No

Who can help?

No response

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

Try loading a model from the hub that has custom code files ending in p or y

For example

import torch
from transformers import AutoModel

model = AutoModel.from_pretrained(
    'BAAI/EVA-CLIP-18B', 
    torch_dtype=torch.float16,
    trust_remote_code=True,
)

Expected behavior

The model should be loading fine. But what happens is the following error

ValueError: The model class you are passing has a `config_class` attribute that is not consistent with the config class you passed (model has <class 'transformers_modules.BAAI.EVA-CLIP-18B.ecb774f7cbba81ad031555b951e126e78f978186.configuration_evaclip.EvaCLIPConfig'> and you passed <class 'transformers_modules.BAAI.EVA-CLIP-18B.ecb774f7cbba81ad031555b951e126e78f978186.configuration_evacli.EvaCLIPConfig'>. Fix one of those so they match!

Notice how the filename configuration_evaclip is cropped to configuration_evacli

The buggy code is here

name = os.path.normpath(module_path).rstrip(".py").replace(os.path.sep, ".")

rstrip removes all trailing characters that match these provided and not the .py suffix

@LysandreJik
Copy link
Member

cc @Rocketknight1

@LysandreJik LysandreJik added Should Fix This has been identified as a bug and should be fixed. bug labels May 27, 2024
@LysandreJik
Copy link
Member

Also cc @leot13 who is impacted by this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Should Fix This has been identified as a bug and should be fixed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants