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

Fix faulty rstrip in module loading #31108

Merged
merged 1 commit into from
May 29, 2024
Merged

Conversation

Rocketknight1
Copy link
Member

Our module loading code uses .rstrip(".py") to remove the python file suffix if present, but this is incorrect, because it actually removes any number of characters in the list [".", "p", "y"] from the end of the filename, resulting in an error if the filename ends in p or y:

>>> "lamp.py".rstrip(".py")
'lam'

Python has a proper method for doing what we want here, which is .removesuffix(), but it was only added in 3.9, and we still need to support 3.8. Instead, I just do it by hand.

Fixes #31061

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

@ydshieh
Copy link
Collaborator

ydshieh commented May 29, 2024

Thanks @Rocketknight1 Sorry about the previous merge.

@Rocketknight1 Rocketknight1 force-pushed the fix_dynamic_module_loading branch from 56c83c3 to 4f7193b Compare May 29, 2024 12:21
@Rocketknight1
Copy link
Member Author

@ydshieh No problems, I don't think I would have spotted it either until I saw the error in the logs!

@Rocketknight1 Rocketknight1 merged commit 0bef4a2 into main May 29, 2024
21 checks passed
@Rocketknight1 Rocketknight1 deleted the fix_dynamic_module_loading branch May 29, 2024 12:33
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.

Python suffix stripping in transformers.dynamic_model_utils.get_class_in_module strips additional characters
4 participants