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

Error when loading custom model with AutoModelForCausalLM in V4.39.1 #29828

Closed
2 of 4 tasks
Hajime-Y opened this issue Mar 23, 2024 · 5 comments · Fixed by #29854
Closed
2 of 4 tasks

Error when loading custom model with AutoModelForCausalLM in V4.39.1 #29828

Hajime-Y opened this issue Mar 23, 2024 · 5 comments · Fixed by #29854

Comments

@Hajime-Y
Copy link

System Info

Environment(transformers-cli env result):

  • transformers version: 4.39.1
  • Platform: Linux-6.1.58+-x86_64-with-glibc2.35
  • Python version: 3.10.12
  • Huggingface_hub version: 0.20.3
  • Safetensors version: 0.4.2
  • Accelerate version: 0.28.0
  • Accelerate config: not found
  • PyTorch version (GPU?): 2.2.1+cu121 (True)
  • Tensorflow version (GPU?): 2.15.0 (True)
  • Flax version (CPU?/GPU?/TPU?): 0.8.2 (cpu)
  • Jax version: 0.4.23
  • JaxLib version: 0.4.23
  • Using GPU in script?:
  • Using distributed or parallel set-up in script?:

Execution Environment: Google Colab

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

Description:
This is a bug report regarding the "Sharing custom models" feature.

Steps to reproduce:

  1. Following the documentation, I registered my custom architecture model to AutoClass using the following code and pushed it to the Hugging Face Hub. I confirmed that modeling_bit_llama.py exists in the Hub repository.
from mybitnet import BitLlamaConfig, BitLlamaForCausalLM

BitLlamaConfig.register_for_auto_class()
BitLlamaForCausalLM.register_for_auto_class("AutoModelForCausalLM")
trainer.push_to_hub()
  1. Then, I tried to load the model using AutoClass with the following code:
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

model_name = "HachiML/myBit-Llama2-jp-127M-test-17"

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto", trust_remote_code=True)
print(model)
  1. In version 4.38.x, no error occurred. However, in version 4.39.1, I encountered 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.HachiML.myBit-Llama2-jp-127M-test-17.91a53eeaa608293edf70e1734a05e8ebaccd3233.modeling_bit_llama.BitLlamaConfig'> and you passed <class 'transformers_modules.HachiML.myBit-Llama2-jp-127M-test-17.91a53eeaa608293edf70e1734a05e8ebaccd3233.modeling_bit_llama.BitLlamaConfig'>. Fix one of those so they match!

Expected behavior

Expected behavior:
The model should be successfully loaded using AutoClass in version 4.39.1, as it did in version 4.38.x.

Actual behavior:
In version 4.39.1, an error is raised when attempting to load the model using AutoClass, even though the same code worked in version 4.38.x.

Please let me know if you need any additional information or clarification. Thank you for your attention to this issue.

@amyeroberts
Copy link
Collaborator

Hi @Hajime-Y, thanks for reporting this issue!

cc @Rocketknight1 as it looks like it might be related to the loading of remote repos with . in their names

@Hajime-Y
Copy link
Author

Hajime-Y commented Mar 25, 2024

@Rocketknight1
Hi, I was mentioned that this issue might be related to the loading of remote repos with . in their names. Could you please take a look at this issue and provide any insights or suggestions on how to resolve it? Thank you for your help!

@Rocketknight1
Copy link
Member

Investigating!

@Rocketknight1
Copy link
Member

Filed a PR to fix this at #29854. @Hajime-Y can you test to confirm it fixes your problem? You can install the PR branch with pip install --upgrade git+https://github.com/huggingface/transformers.git@update_config_class_check

@Rocketknight1
Copy link
Member

@Hajime-Y this has now been merged, you can get it by installing transformers from main!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants