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

simplify get_class_in_module and fix for paths containing a dot #29262

Merged
merged 1 commit into from
Feb 28, 2024

Conversation

cebtenzzre
Copy link
Contributor

@cebtenzzre cebtenzzre commented Feb 23, 2024

What does this PR do?

A simpler implementation of get_class_in_module that also works when the path starts with e.g. ./ or otherwise contains dot characters outside of the repo ID.

Fixes #29251

I should write a test. The test in #29175 didn't fail before the PR (with code from commit 89c6481), so it does not seem valid.

This does change the API of get_class_in_module to expect the path to an actual file, with the extension - but since the previous PR changed the API already, this seems fine.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

Copy link
Member

@Rocketknight1 Rocketknight1 left a comment

Choose a reason for hiding this comment

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

Strong approval!

For @ArthurZucker: This PR is fixing the same problem as my PR #29175. However, it has two advantages. Firstly, it's cleaner, rather than a messy try-except, and secondly it's more universal and doesn't fail in other cases when . is present in the repo path.

The only thing I'm confused about is that @cebtenzzre said that the test I added in #29175 was still passing even before that PR. That's strange to me - my test explicitly called model = AutoModel.from_pretrained("hf-internal-testing/test_dynamic_model_v1.0", trust_remote_code=True), which should definitely have failed before my PR because the repo name contains .

I'm not sure what's going on there - I'd appreciate any clarification from @cebtenzzre about what he thinks the cause is! Ideally we'd make sure that test is working correctly before we merge this.

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

@Rocketknight1
Copy link
Member

Update: @not-lain explained the issue with the test. The repo being tested has now been updated, so that the test actually tests what we wanted to test in the first place, and that resolves my question!

@cebtenzzre I don't have any other objections, so we just need core maintainer review to merge this!

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

A lot cleaner !

@ArthurZucker ArthurZucker merged commit bd5b986 into huggingface:main Feb 28, 2024
19 of 21 checks passed
"""
Import a module on the cache directory for modules and extract a class from it.

Args:
repo_id (`str`): The repo containing the module. Used for path manipulation.
class_name (`str`): The name of the class to import.
module_path (`str` or `os.PathLike`): The path to the module to import.

Choose a reason for hiding this comment

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

module_path now expects the file extension too now. Maybe that should be reflected here too? @cebtenzzre

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.

AutoModel.from_pretrained('.') raises ModuleNotFoundError with trust_remote_code=True
6 participants