Skip to content

Add dict input support to from_single_file for reusing loaded weights - #14898

Open
xalteropsx wants to merge 1 commit into
huggingface:mainfrom
xalteropsx:feat/single-file-dict-input
Open

xalteropsx wants to merge 1 commit into
huggingface:mainfrom
xalteropsx:feat/single-file-dict-input

Conversation

@xalteropsx

@xalteropsx xalteropsx commented Sep 28, 2026 •

Copy link
Copy Markdown

What does this PR do?

Extends FromSingleFileMixin.from_single_file() so that
pretrained_model_link_or_path_or_dict accepts a state dict in
addition to a path/URL. This lets users load multiple pipelines
(e.g. txt2img + img2img) from a single checkpoint without
re-reading and re-parsing the file from disk.

Fixes #14903

Before

def from_single_file(cls, pretrained_model_link_or_path, **kwargs): ...

user had to load the file twice:

txt2img = StableDiffusionPipeline.from_single_file(path)
img2img = StableDiffusionImg2ImgPipeline.from_single_file(path) # re-reads disk

After

def from_single_file(cls, pretrained_model_link_or_path_or_dict, **kwargs): ...

state_dict = load_file("sd_xl_base_1.0.safetensors")
txt2img = StableDiffusionPipeline.from_single_file(state_dict)
img2img = StableDiffusionImg2ImgPipeline.from_single_file(state_dict) # no re-read

How

  • Accept dict in the first argument; when a dict is passed, skip
    download/file I/O and use the provided tensors directly.
  • Existing str / os.PathLike behavior is unchanged (backward compatible).
  • Updated docstring + type hints.

Who can review?

Anyone in the community is free to review
@sayakpaul @DN6 @yiyixuxu

@github-actions github-actions Bot added single-file size/S PR with diff < 50 LOC labels Sep 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hi @xalteropsx, thanks for the PR! It does not appear to link an issue it fixes. If this PR addresses an existing issue, please add a closing keyword (e.g. Fixes #1234) to the PR description so the issue is linked. See the contribution guide for more details. If this PR intentionally does not fix a tracked issue, a maintainer can add the no-issue-needed label to silence this reminder.

Please note that PRs without a linked issue are likely to be automatically closed 10 days after this notice.

Once the PR links an issue (or gets the no-issue-needed label), you can ignore this message — it stays here as a comment, but it no longer applies.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

single-file size/S PR with diff < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Required weight pass on a singlefile

1 participant