Fix custom-module copies inheriting read-only permissions#45686
Merged
Rocketknight1 merged 1 commit intohuggingface:mainfrom Apr 29, 2026
Merged
Conversation
Contributor
Author
|
AI was used to author some of this code but I reviewed & hand-edited the contribution myself. |
a6a6423 to
30f65e4
Compare
30f65e4 to
a9728da
Compare
Member
|
Looks good, but we can skip the test I think! The custom saving code doesn't get updated too often, so we should be fine without a regression test. Can you revert the test file and ping me to merge the fix? |
…e#45684) `shutil.copy` is `copyfile` + `copymode`, so when source files are read-only (common with version-control systems like Perforce that check out files as `r--r--r--`), the destination inherits those permissions. This breaks post-save tooling and leaves users with read-only files in their saved-model directories. Switch to `shutil.copyfile` at all five call sites in `dynamic_module_utils.py`. New files then get standard umask-based permissions, matching what callers of `save_pretrained` expect.
a9728da to
d19b012
Compare
Contributor
Author
|
Thanks @Rocketknight1! I removed the test case in the latest commit version. The change should be ready to merge. |
Rocketknight1
approved these changes
Apr 29, 2026
Member
Rocketknight1
left a comment
There was a problem hiding this comment.
Yep, LGTM now. Thank you!
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #45684.
shutil.copyiscopyfile+copymode, so when source files are read-only (common with version-control systems like Perforce that check files out asr--r--r--until edit), the destination inherits those permissions. This breaks post-save tooling that wants to rewrite the saved module file, and leaves users with read-only files in their saved-model directories.The fix swaps
shutil.copyforshutil.copyfileat all five call sites indynamic_module_utils.py(one incustom_object_save, four inget_cached_module_file).copyfilecopies file contents only; the destination, when newly created, gets standard umask-based permissions, which is what callers ofsave_pretrainedexpect.A regression test is added to
tests/utils/test_dynamic_module_utils.py: it makes a source module read-only, callscustom_object_save, and asserts the destination is writable. The test fails onmainand passes with this fix.Code Agent Policy
Before submitting
make stylebut it changes many files I did not touch and exits with errors)(withregister_for_auto_class`) propagates read-only permissions from custom-model source files #45684Who can review?
@Cyrilvallez (model loading)