ModularPipeline.save_pretrained: change the default overwrite_modular_index to be True - #14659
ModularPipeline.save_pretrained: change the default overwrite_modular_index to be True#14659yiyixuxu wants to merge 9 commits into
overwrite_modular_index to be True#14659Conversation
|
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. |
|
@yiyixuxu Sounds good to me. Did you also want to overwrite for cases where pipe = ModularPipeline.from_pretrained(repo_id, local_dir=<path to dir>)
pipe.load_components() |
|
@DN6
|
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HCdbvRpL9fv3h3WwSUPpfS
…ular-local-copies
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
| pipe.save_pretrained("local/path", repo_id="my-username/flux2-custom-transformer", push_to_hub=True) | ||
| ``` | ||
|
|
||
| Pass `overwrite_modular_index=False` to preserve the recorded specs of saved components that already have a load ID. Components without a recorded source, such as models added with `update_components`, are still rewritten to point to the destination. |
There was a problem hiding this comment.
Components without a recorded source, such as models added with
update_components, are still rewritten to point to the destination.
If we don't call push_to_hub=True and just save locally, what is the expected behaviour here? As per the changes in this PR, the modular index then records the local path?
If so, is there a possibility where users would just upload that and the modular index still points to a local destination? So, maybe we could further clarify a bit:
For a local save, the destination recorded in
modular_model_index.jsonissave_directory. Don't upload that directory separately because the index continues to point to the local path. To publish the saved components, passpush_to_hub=Trueandrepo_idto [~ModularPipeline.save_pretrained]; the index then points to the Hub repository instead.
| component_spec_dict["pretrained_model_name_or_path"] = repo_id if push_to_hub else save_directory | ||
| component_spec_dict["subfolder"] = component_name | ||
| component_spec_dict["variant"] = variant if save_method_accept_variant else None | ||
| component_spec_dict["revision"] = None |
There was a problem hiding this comment.
But is there any reason to include revision here?
There was a problem hiding this comment.
just in case the original entry on modular_model_index has a revision and we overwrite, we need to set it to None since it would not apply for the "local compnent"
| with open(os.path.join(save_dir, "modular_model_index.json")) as f: | ||
| index = json.load(f) | ||
|
|
||
| _library, _cls, unet_spec = index["unet"] | ||
| assert unet_spec["pretrained_model_name_or_path"] == save_dir | ||
| assert unet_spec["subfolder"] == "unet" | ||
|
|
||
| _library, _cls, vae_spec = index["vae"] | ||
| expected_vae = save_dir if overwrite_modular_index else "hf-internal-testing/tiny-stable-diffusion-xl-pipe" | ||
| assert vae_spec["pretrained_model_name_or_path"] == expected_vae |
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HCdbvRpL9fv3h3WwSUPpfS
cc @DN6
Just a proposal, but I think since
save_pretrainednow saves the loaded components by default, it makes sense foroverwrite_modular_indexto default toTrueas well — otherwise the result is not very intuitive: e.g. when you runthe components are all saved into
local_dir, but itsmodular_model_index.jsonstill points atrepo_id— so reloading from the local_dir still fetch everything from hub even though weights are in the local folderIt's especially confusing if you intended to save a self-contained local copy with some custom components
See related issues: #14251, #14640