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

Correct model_type in PretrainedConfig's to_dict #28507

Closed
wants to merge 2 commits into from

Conversation

fxmarty
Copy link
Contributor

@fxmarty fxmarty commented Jan 15, 2024

As per title, now

from transformers import AutoConfig, PretrainedConfig

cfg = AutoConfig.from_pretrained("bert-base-uncased")
config = PretrainedConfig.from_dict(cfg.to_dict())
config.model_type = "my-model"

print(config.to_dict()["model_type"])

rightfully yields my-model, while it use to give "" (the class attribute value of PretrainedConfig).

I think instance attributes (if any) should take precedence over class attributes.

Related to huggingface/optimum#1645

@amyeroberts
Copy link
Collaborator

Thanks for opening this PR @fxmarty!

The reason this happens at the moment is that model_type is intended to be a class attribute, not an instance attribute i.e. to be consistent and shared for all instances of the config object and not modified instance to instance. What's the motivation for modifying it like this?

@fxmarty
Copy link
Contributor Author

fxmarty commented Jan 16, 2024

Understood!

@fxmarty fxmarty closed this Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants