Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix: correctly encode/decode config in ModelHubMixin if custom coders #2337

Merged
merged 4 commits into from
Jun 14, 2024

Conversation

Wauplin
Copy link
Contributor

@Wauplin Wauplin commented Jun 14, 2024

Fix #2334.

Thanks to @not-lain's investigation (see #2334 (comment)), I have been able to reproduce the error with a simple example. The problem was that custom encoders/decoders were not used for the special attribute config. This PR fixes it. I also added a regression test inspired by the reproducible example.

Once merged, I'll make a hot-fix release with this fix.

(failing tests are unrelated)

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

tests/test_hub_mixin_pytorch.py Outdated Show resolved Hide resolved
tests/test_hub_mixin_pytorch.py Show resolved Hide resolved
provided_config = passed_values.get("config")
if isinstance(provided_config, dict):
init_config.update(provided_config)
if isinstance(passed_config, dict):
Copy link
Contributor

Choose a reason for hiding this comment

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

we should change this one, a counter-example would be

class Model(nn.Module,PyTorchModelHubMixin):
  def __init__(self,config):
    super().__init__()
    # other stuff here maybe load config file number 2
    self.layer = nn.Linear(config,config)

model = Model(2)
model._hub_mixin_config
>>> None

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I'd prefer not to update the lib' for this corner case. This PR is meant to fix real-world issue (reported by @NielsRogge for https://github.com/hamadichihaoui/BIRD/) but having a int config seems pretty unusual.

Co-authored-by: Hafedh <70411813+not-lain@users.noreply.github.com>
Copy link
Contributor

@not-lain not-lain left a comment

Choose a reason for hiding this comment

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

LGTM, nice work

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.

Thanks for that @Wauplin!

@Wauplin
Copy link
Contributor Author

Wauplin commented Jun 14, 2024

Thanks both for the quick review! 🤗

@Wauplin Wauplin merged commit c013756 into main Jun 14, 2024
17 checks passed
@Wauplin Wauplin deleted the 2334-correctly-encode-and-decode-config branch June 14, 2024 14:04
Wauplin added a commit that referenced this pull request Jun 14, 2024
…#2337)

* Fix: correctly encode/decode config in ModelHubMixin if custom coders

* make style

* make quality

* Update tests/test_hub_mixin_pytorch.py

Co-authored-by: Hafedh <70411813+not-lain@users.noreply.github.com>

---------

Co-authored-by: Hafedh <70411813+not-lain@users.noreply.github.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[PyTorchModelHubMixin] argparse.Namespace config does not seem to be pushed
4 participants