# Problems using AutoModel.from\_pretrained on custom model

**URL:** <https://discuss.huggingface.co/t/problems-using-automodel-from-pretrained-on-custom-model/65286>\
**Category:** Beginners\
**Created:** [December 11, 2023, 2:17am UTC](https://discuss.huggingface.co/t/problems-using-automodel-from-pretrained-on-custom-model/65286 "2023-12-11T02:17:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fal7acy](https://avatars.discourse-cdn.com/v4/letter/f/35a633/32.png) [@Fal7acy](https://discuss.huggingface.co/u/Fal7acy)\
**Post date:** [December 11, 2023, 2:17am UTC](https://discuss.huggingface.co/t/problems-using-automodel-from-pretrained-on-custom-model/65286/1 "2023-12-11T02:17:54Z")

</div>

Hi,

I’m working on a custom casual language model that doesn’t extend any huggingface models.

```auto
class BigBrainConfig(PretrainedConfig):
    model_type = 'big-brain-lm'
...

```

```auto
class BigBrainLanguageModel(PreTrainedModel):
    config_class = BigBrainConfig
    base_model_prefix = 'big-brain-lm'
...

```

I used the following code to upload the model and register it for AutoModel.

```auto
login(token=args.token)

BigBrainConfig.register_for_auto_class()
BigBrainLanguageModel.register_for_auto_class('AutoModel')

model = BigBrainLanguageModel(BigBrainConfig())
model.push_to_hub('big-brain-lm')

logout()

```

When using the following code in my training script, I get the following error.

```auto
model = AutoModel.from_pretrained('Fal7acy/big-brain-lm', trust_remote_code=True)

```

```auto
Traceback (most recent call last):
  File "C:\Users\parof\PycharmProjects\BigBrainAI\src\model\training.py", line 88, in <module>
    model = AutoModel.from_pretrained('Fal7acy/big-brain-lm', trust_remote_code=True)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\parof\PycharmProjects\Environments\BigBrainAI\Lib\site-packages\transformers\models\auto\auto_factory.py", line 487, in from_pretrained
    cls.register(config. __class__ , model_class, exist_ok=True)
  File "C:\Users\parof\PycharmProjects\Environments\BigBrainAI\Lib\site-packages\transformers\models\auto\auto_factory.py", line 513, in register
    raise ValueError(
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 'config.BigBrainConfig'> and you passed <class 'transformers_modules.Fal7acy.big-brain-lm.fc99f449c2d4cdb74e902662267cec031eeeea5f.config.BigBrainConfig'>. Fix one of those so they match!

```

I am probably doing something wrong, but I feel that I have followed the [share a custom model](https://huggingface.co/docs/transformers/custom_models) guide.

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![panigrah](https://avatars.discourse-cdn.com/v4/letter/p/bb73d2/32.png) [@panigrah](https://discuss.huggingface.co/u/panigrah)\
**Post date:** [December 11, 2023, 7:51am UTC](https://discuss.huggingface.co/t/problems-using-automodel-from-pretrained-on-custom-model/65286/2 "2023-12-11T07:51:51Z")

</div>

I have not used this yet - but does the very last section in the tutorial apply in your case?

> **[Sharing custom models](https://huggingface.co/docs/transformers/custom_models#registering-a-model-with-custom-code-to-the-auto-classes)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

That is registering models without using the `_for_auto_class()` suffix.

---

<div class="post-metadata">

**Author:** ![Fal7acy](https://avatars.discourse-cdn.com/v4/letter/f/35a633/32.png) [@Fal7acy](https://discuss.huggingface.co/u/Fal7acy)\
**Post date:** [December 11, 2023, 9:06am UTC](https://discuss.huggingface.co/t/problems-using-automodel-from-pretrained-on-custom-model/65286/3 "2023-12-11T09:06:18Z")

</div>

That is for when the code is in a different repo, my code is in the same repo the model is saved in. The config file for my model has the right section in it.

```auto
"auto_map": {
    "AutoConfig": "config.BigBrainConfig",
    "AutoModel": "language.BigBrainLanguageModel"
  }

```

I think the problem might be that the config class gets saved somewhere on the backend so the class path is not the same when loading it.

```auto
(model has <class 'config.BigBrainConfig'> and you passed <class 'transformers_modules.Fal7acy.big-brain-lm.fc99f449c2d4cdb74e902662267cec031eeeea5f.config.BigBrainConfig'>

```

---

<div class="post-metadata">

**Author:** ![panigrah](https://avatars.discourse-cdn.com/v4/letter/p/bb73d2/32.png) [@panigrah](https://discuss.huggingface.co/u/panigrah)\
**Post date:** [December 12, 2023, 7:04am UTC](https://discuss.huggingface.co/t/problems-using-automodel-from-pretrained-on-custom-model/65286/4 "2023-12-12T07:04:28Z")

</div>

Perhaps its a bug?

To keep going, try overriding the config class by adding it in to the `from_pretrained call`, that should force the config to be what you pass it instead of it trying to read it from the model file.

```auto
config = BigBrainConfig()
model = AutoModel.from_pretrained('Fal7acy/big-brain-lm', trust_remote_code=True, config=config)

```

The `AutoConfig` does read the setting in the config file, but based on the code, it looks like the actual cache is loaded from the code which will end up pointing to the cached or remote class.
