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

ModelHubMixin: Fix attributes lost in inheritance #2305

Merged
merged 5 commits into from
Jun 5, 2024

Conversation

Wauplin
Copy link
Contributor

@Wauplin Wauplin commented May 31, 2024

Fix #2300.

Instead of recreating the MixinInfo object, we should complete its information as mentioned by @qubvel. Thanks for reporting this!

EDIT: made some minor edits to ModelCardData as well but mostly setting alphabetical order + adding license_name/license_link officially.

EDIT 2: deprecated languages in favor of language to be consistent with ModelCardData.

@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.

@qubvel
Copy link
Member

qubvel commented May 31, 2024

@Wauplin thanks for a quick response and fix!

@Wauplin Wauplin changed the title ModelHubMixn: Fix attributes lost in inheritance ModelHubMixin: Fix attributes lost in inheritance May 31, 2024
Copy link
Member

@qubvel qubvel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great fix, just nit comments

src/huggingface_hub/hub_mixin.py Outdated Show resolved Hide resolved
Comment on lines +244 to +247
if info.model_card_data.tags is not None:
info.model_card_data.tags.extend(tags)
else:
info.model_card_data.tags = tags
Copy link
Member

@qubvel qubvel May 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we extend tags instead of overriding them? In that case, it would be impossible to drop base model tags and set new ones. Probably there is no the best solution, but I would expect them to be replaced rather than extended 🙂 WDYT?

Suggested change
if info.model_card_data.tags is not None:
info.model_card_data.tags.extend(tags)
else:
info.model_card_data.tags = tags
info.model_card_data.tags = tags

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to extend them actually, specifically so that we don't loose tags defined by base models. Worst case, users can overwrite the internal attribute 😕
TBH I don't think this will ever be a problem, multiple inheritance when using ModelHubMixin is already not common so cases where nested classes define tags and where these tags should not be inherited might just never happen.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense, thank you!

Co-authored-by: Pavel Iakubovskii <qubvel@gmail.com>
Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Why are we switching from languages to language if we expect it to still be a list?

EDIT: Ah, to be consistent with ModelCardData

@Wauplin
Copy link
Contributor Author

Wauplin commented Jun 5, 2024

EDIT: Ah, to be consistent with ModelCardData

Yes, and moreover to be consistent with the existing repos on the Hub (and typically to filter by language).

Thanks for the review :)

@Wauplin Wauplin merged commit d630f31 into main Jun 5, 2024
16 checks passed
@Wauplin Wauplin deleted the 2300-fix-model-hub-mixin-inheritance branch June 5, 2024 12:51
Wauplin added a commit that referenced this pull request Jun 14, 2024
* ModelHubMixn: Fix attributes lost in inhericance

* make style

* deprecate

* style

* Update src/huggingface_hub/hub_mixin.py

Co-authored-by: Pavel Iakubovskii <qubvel@gmail.com>

---------

Co-authored-by: Pavel Iakubovskii <qubvel@gmail.com>
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.

Metadata is missed in child classes for models with HubMixinModel
4 participants