Load local ModularPipeline snapshots when modular_model_index.json still names Hub ids - #14645
Open
22elix3r wants to merge 1 commit into
Open
Load local ModularPipeline snapshots when modular_model_index.json still names Hub ids#1464522elix3r wants to merge 1 commit into
22elix3r wants to merge 1 commit into
Conversation
…ndex.json When ModularPipeline is initialized from a local directory, component specs copied from modular_model_index.json still pointed at Hub repo ids. load_components() then re-downloaded (or failed offline) even if the snapshot already contained the subfolders. Bind those specs to the local directory when the subfolder exists, and leave Hub ids in place for pointer repos and pruned snapshots.
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 #14640.
Motivation
ModularPipeline.from_pretrained(local_dir)/blocks.init_pipeline(local_dir)followed byload_components()still resolved components against the Hub id stored inmodular_model_index.json. A complete local snapshot of MiniMax-H3 therefore re-downloaded ~134 GB (or left components asNoneoffline), even though the files were already on disk.This is the
model_index.jsonvsmodular_model_index.jsonasymmetry: the standard-repo fallback already bindsrepoto the local path; the modular index is taken verbatim, including published Hub ids.Root cause
ModularPipeline.__init__copies each from_pretrained spec frommodular_model_index.jsonas-is. Published checkpoints such as MiniMax-H3 write"pretrained_model_name_or_path": "MiniMaxAI/MiniMax-H3"into every entry. When the caller passed a local directory, those Hub ids still won, soComponentSpec.load()contacted the Hub.The
model_index.jsonfallback already does the right thing:The invariant that was missing: if the pipeline path is a local directory and
<local_dir>/<subfolder>exists, load that component from the directory; otherwise keep the Hub id.That second clause is required. Modular repos are allowed to be pointer repos (index only, weights elsewhere). Blindly rewriting every spec to the local directory would break those.
Solution
After specs are applied from either index, if
pretrained_model_name_or_pathis a local directory, rewrite a from_pretrained spec onto that directory only when:subfolder<local_dir>/<subfolder>exists on diskMissing subfolders keep their Hub id (pointer repos / pruned snapshots). Hub
from_pretrained("org/model")is unchanged becauseos.path.isdir("org/model")is false.Not done: wrapping
pin_memory/from_pretrainedin try/except, MiniMax-specific branches, or changing how published indexes are written.save_pretrained(..., overwrite_modular_index=True)remains the way to persist local references.Testing
Synthetic snapshot (no MiniMax weights, no GPU):
Without the
__init__change the three remapping tests fail; the two "leave Hub id / leave existing local path" tests already passed on main.New coverage:
init_pipeline(local_dir)with Hub ids in the index and a presentscheduler/subfolder loads offlinePerformance
No extra copies and no extra Hub traffic on the common path. The new branch is an
os.path.isdirscan of already-loaded specs, only when the pipeline path is a local directory. Hub loads are unchanged. Local snapshots avoid a second download.Self-review
docs/source/en/modular_diffusers/modular_pipeline.md); the zh page was not updated. Specs remapped at init also flow intoregister_components/ saved config — same as passingpretrained_model_name_or_pathintoload_components()today.overwrite_modular_index=Trueis still the way to retarget a save.Related issue
Fixes #14640
Coordination: #14640 (open, unassigned, no linked PR at the time of this change). Investigation comment: #14640 (comment)
Before submitting
self-reviewskill on the diff?Who can review?
cc @yiyixuxu @apolinario