Skip to content

Allow modifications of attributes in modular#41450

Closed
molbap wants to merge 2 commits intomainfrom
rename_modular_attrs
Closed

Allow modifications of attributes in modular#41450
molbap wants to merge 2 commits intomainfrom
rename_modular_attrs

Conversation

@molbap
Copy link
Contributor

@molbap molbap commented Oct 8, 2025

What does this PR do?

Often, attributes are not derived from model names. Modular files based on a given model are then bloated because there is a tiny change in an attribute, needing the entire thing to be rewritten. See https://github.com/huggingface/transformers/pull/41224/files here for instance.

This introduces an attribute renamer, from an arbitrary attribute name to another.

  class DINOv3ViTForImageClassification(Dinov2ForImageClassification):
      _attribute_renames = {"dinov2": "dinov3"}

On the attached PR, this expands the modeling file correctly.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@molbap
Copy link
Contributor Author

molbap commented Oct 8, 2025

After internal discussion: this would harm the overall modular philosophy, adding a mutable inside classes like this. For the moment, we accept rewriting modular files which differ just by an attribute naming. (cc @yonigozlan )

Instead, a util to convert on load with 0 cost would be preferrable, and is in the works. cc @Cyrilvallez @ArthurZucker

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