-
Notifications
You must be signed in to change notification settings - Fork 7.1k
align snapshot_download to respect hfh latest version #14118
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
Open
sayakpaul
wants to merge
7
commits into
main
Choose a base branch
from
hfh-snapshot-download-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+104
−21
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7313492
align snapshot_download to respect hfh latest version
sayakpaul d148470
fix
sayakpaul 5231b26
Merge branch 'main' into hfh-snapshot-download-fix
sayakpaul 3e14a06
Merge branch 'main' into hfh-snapshot-download-fix
sayakpaul fd5a5bb
Merge branch 'main' into hfh-snapshot-download-fix
sayakpaul c2f9647
compute the same snapshot_download patterns offline as online
sayakpaul e92e259
match missing-shard test on the shard filename
sayakpaul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requesting to download a single file to then use
Path(...).parentis IMO a hacky way of getting the snapshot_folder. (hence why it needs 7 lines of explanation in comments)to avoid that I've opened huggingface/huggingface_hub#4500 to expose the
snapshot_folderin the error in case ofIncompleteSnapshotError. I think this is the most explicit way to do things. In diffusers the code will look like this:making it explicit for anyone reading the code that the folder is incomplete and that we knowingly ignored it
(even though, once again, I do think the best way to tackle this is to provide the correct allow_pattern/ignore_pattern filters in the first place. I still don't understand why it's not the solution we are trying to have in this PR. If there is a rational behind not trying to fix the root cause I genuinely believe it should at the very least be mentioned/documented somewhere)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for offering further thoughts. Post-mortem:
The reason we can't write the patterns down without any file listing: they're data-dependent. allow_patterns are largely concrete filenames chosen by
variant_compatible_siblings(variant / sharded / safetensors-vs-bin resolution), and_get_ignore_patternspicks formats based on what actually exists in the repo.For the online path, that listing comes from
model_info().siblings. For the offline path, the only faithful source is the cached snapshot itself, which holds exactly what the same computation downloaded when online — so both modes compute the same patterns. We also test it here:diffusers/tests/pipelines/test_pipelines.py
Line 508 in e92e259
More precisely, the offline path falls through into the same pattern-computation code as online, fed with a filenames' set that came from the cache instead of
model_info().siblings. Before this PR, the offline path skipped all of this (patterns stayed None).Regarding
hf_hub_download(config_file), the online branch makes the identical call becausemodel_index.json's content dictates the computation (component folders,_ignore_files, custom pipeline):diffusers/src/diffusers/pipelines/pipeline_utils.py
Lines 1655 to 1664 in e92e259
(All of that is used for computing the patterns)
For the offline path, we are also reusing its parent as the snapshot dir, matching the pre-existing
snapshot_folder = Path(config_file).parentonmain.huggingface/huggingface_hub#4500 is cool, thanks!
snapshot_pathon the error does locate the folder correctly. But the error only fires fromsnapshot_download.We need the folder before callingsnapshot_download(its listing is the input to the pattern computation). Using it would mean a deliberate no-patterns call that fails on every offline diffusers load just to catch the error.Maybe there's a way to refactor this but that's for another PR.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detailed response! That makes sense then. So if I understand correctly what's missing before-hand is the list of files in the repo when in offline mode, right? Luckily we now have this information in cache -hence why we are able to tell if a folder is incomplete-. We could definitely add a method to retrieve that cached list to that you can:
repo.siblingsrepo.siblingsfrom the cache (requires a method fromhuggingface_hub)Would that be interesting for you?
Yes that's what I had in mind. I feel that it's less hacky than a deliberate
hf_hub_downloadcall on the index file, just to do aPath(index file).parentafterwards.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opened huggingface/huggingface_hub#4513 to add a
get_cached_repo_treemethod useful whenrepo.siblingsorlist_repo_treefails (in offline mode). A priori, this is the cleanest way to determine the patterns down the line (with variants, etc.) without raising an error and without skipping the "incomplete folder check". Should be shipped today or tomorrow with the rest.