Skip to content

Integration of from_pretrained and from_single_file #10208

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
wants to merge 52 commits into
base: main
Choose a base branch
from

Conversation

suzukimain
Copy link
Contributor

@suzukimain suzukimain commented Dec 13, 2024

What does this PR do?

This PR integrates the from_single_file function into from_pretrained

pip install -q git+https://github.com/suzukimain/diffusers.git@loading_method_integration

from diffusers import StableDiffusionPipeline

# Load a single file checkpoint
pipe = StableDiffusionPipeline.from_pretrained("https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5/blob/main/v1-5-pruned-emaonly.safetensors")

# Load a multi-folder Diffusers format checkpoint
pipe = StableDiffusionPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5")

Additionally, since AutoPipeline doesn't have a method to load single file checkpoints, I've adapted a part of the model_search functionality to enable this capability.

from diffusers import AutoPipelineForText2Image

# Load a single file checkpoint
pipe = AutoPipelineForText2Image.from_pretrained("https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5/blob/main/v1-5-pruned-emaonly.safetensors")

# Load a multi-folder Diffusers format checkpoint
pipe = AutoPipelineForText2Image.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5")

Edit:
Reflected changes

Before submitting

Who can review?

@yiyixuxu ,@asomoza

@suzukimain
Copy link
Contributor Author

This PR allows these issues to be corrected.
#6986 #7496 #7979

@suzukimain
Copy link
Contributor Author

Updated dictionary used when loading the single file checkpoint in AutoPipeline

@suzukimain
Copy link
Contributor Author

Can anyone please review this PR?

@suzukimain
Copy link
Contributor Author

suzukimain commented Dec 23, 2024

Hi, Could you please review this PR if possible?
I hope to not have caused any inconvenience. Thank you for your cooperation.
cc: @hlky @DN6

@bghira
Copy link
Contributor

bghira commented Jan 3, 2025

cc @yiyixuxu @a-r-r-o-w

local_files_only=local_files_only,
revision=revision,
)
pipeline_class = _get_pipeline_class(cls, class_name=cls.__name__, config=None)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't pass the class_name when loading a single file checkpoint in DiffusionPipeline, it will result in a TypeError.

Comment on lines +752 to +771
# Load the pipeline from a single file
elif load_method_name == "from_single_file":
# The arguments for the __init__ method of `DiffusionPipeline` are keyword arguments, so they cannot be loaded from `from_single_file`
if cls.__name__ == "DiffusionPipeline":
# import it here to avoid circular import
from .stable_diffusion.convert_from_ckpt import download_from_original_stable_diffusion_ckpt

checkpoint = load_single_file_checkpoint(
pretrained_model_name_or_path,
force_download=force_download,
proxies=proxies,
token=token,
cache_dir=cache_dir,
local_files_only=local_files_only,
revision=revision,
)

return download_from_original_stable_diffusion_ckpt(checkpoint, **kwargs)
else:
return cls.from_single_file(pretrained_model_name_or_path, **kwargs)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm separating the process because executing DiffusionPipeline.from_single_file results in the following error:

ValueError: Pipeline <class 'diffusers.pipelines.pipeline_utils.DiffusionPipeline'> expected {'kwargs', 'args'}, but only set() were passed.

@suzukimain
Copy link
Contributor Author

Hello, I have made corrections based on your advice.
cc @DN6 @yiyixuxu

Copy link
Contributor

github-actions bot commented Feb 3, 2025

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

@github-actions github-actions bot added the stale Issues that haven't received updates label Feb 3, 2025
@suzukimain
Copy link
Contributor Author

Hello, Could you please review this PR?
@yiyixuxu @DN6

@github-actions github-actions bot removed the stale Issues that haven't received updates label Mar 1, 2025
@yiyixuxu
Copy link
Collaborator

yiyixuxu commented Mar 4, 2025

hi @suzukimain

thanks for the PR, like @DN6 mentioned here #10208 (comment) but we are not 100% about if we are going to unify these two methods yet. We will not be able to merge PR at the moment.

sorry if we wasted your time. In the future, would you be abe to open an issue and start a discussion first?

@suzukimain
Copy link
Contributor Author

I understand. I appreciate your kind response during your busy time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants