ValueError: Unrecognized configuration class

#42
by aligholami - opened

Just tried the first snippet provided here https://huggingface.co/CohereForAI/c4ai-command-r-v01 on Google Collab, but the AutoModelForCausalLM does not match the given config. Snippet:

# pip install 'transformers>=3.9.1'
from transformers import AutoTokenizer, AutoModelForCausalLM

model_id = "CohereForAI/c4ai-command-r-v01"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id)

# Format message with the command-r chat template
messages = [{"role": "user", "content": "Hello, how are you?"}]
input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
## <BOS_TOKEN><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Hello, how are you?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>

gen_tokens = model.generate(
    input_ids, 
    max_new_tokens=100, 
    do_sample=True, 
    temperature=0.3,
    )

gen_text = tokenizer.decode(gen_tokens[0])
print(gen_text)

Here is the full error:

/usr/local/lib/python3.10/dist-packages/transformers/models/auto/auto_factory.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
    562                 pretrained_model_name_or_path, *model_args, config=config, **hub_kwargs, **kwargs
    563             )
--> 564         raise ValueError(
    565             f"Unrecognized configuration class {config.__class__} for this kind of AutoModel: {cls.__name__}.\n"
    566             f"Model type should be one of {', '.join(c.__name__ for c in cls._model_mapping.keys())}."

ValueError: Unrecognized configuration class <class 'transformers_modules.CohereForAI.c4ai-command-r-v01.9c33b0976099d0f406f0d007613676fe42b78e3b.configuration_cohere.CohereConfig'> for this kind of AutoModel: AutoModelForCausalLM.
Model type should be one of BartConfig, BertConfig, BertGenerationConfig, BigBirdConfig, BigBirdPegasusConfig, BioGptConfig, BlenderbotConfig, BlenderbotSmallConfig, BloomConfig, CamembertConfig, LlamaConfig, CodeGenConfig, CpmAntConfig, CTRLConfig, Data2VecTextConfig, ElectraConfig, ErnieConfig, FalconConfig, FuyuConfig, GemmaConfig, GitConfig, GPT2Config, GPT2Config, GPTBigCodeConfig, GPTNeoConfig, GPTNeoXConfig, GPTNeoXJapaneseConfig, GPTJConfig, LlamaConfig, MarianConfig, MBartConfig, MegaConfig, MegatronBertConfig, MistralConfig, MixtralConfig, MptConfig, MusicgenConfig, MvpConfig, OpenLlamaConfig, OpenAIGPTConfig, OPTConfig, PegasusConfig, PersimmonConfig, PhiConfig, PLBartConfig, ProphetNetConfig, QDQBertConfig, Qwen2Config, ReformerConfig, RemBertConfig, RobertaConfig, RobertaPreLayerNormConfig, RoCBertConfig, RoFormerConfig, RwkvConfig, Speech2Text2Config, StableLmConfig, TransfoXLConfig, TrOCRConfig, WhisperConfig, XGLMConfig, XLMConfig, XLMProphetNetConfig, XLMRobertaConfig, XLMRobertaXLConfig, XLNetConfig, XmodConfig.

Hi,

This model is available from v4.39 on, so it's recommended to do pip install --upgrade transformers.

yes, switching to v4.39 fixes the issue. But not It gets stuck at loading checkpoint shards... and then the kernel crashes. Is this a RAM issue?

Cohere For AI org

Yeah it's a memory issue.
If you have Colab Pro, switch to runtime with A100 GPU then you should be able to load the model in 8-bit or 4-bit.

@shivi is there any way to achieve this without Colab Pro?

Cohere For AI org
edited Mar 29

You can also check JarvisLabs and Lambda for on-demand GPU access.

If you want to just try out the model then the easiest way would be to use Cohere's Chat API

Cohere For AI org

You can now also use this model on hugging face spaces: https://huggingface.co/spaces/CohereForAI/c4ai-command-r-v01.

Closing discussion for now, but feel free to re-open if relates to code errors.

sarahooker changed discussion status to closed

Sign up or log in to comment