Skip to content
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

[From pretrained] Allow returning local path #1450

Merged
merged 2 commits into from Dec 2, 2022

Conversation

patrickvonplaten
Copy link
Contributor

@patrickvonplaten patrickvonplaten commented Nov 28, 2022

It is a common use case to want to know exactly where the pipeline was downloaded. This PR adds a simply kwarg return_cached_folder to see this. It could help with issues such as:

@@ -585,6 +560,33 @@ def load_module(name, value):
f"Keyword arguments {unused_kwargs} are not expected by {pipeline_class.__name__} and will be ignored."
)

if low_cpu_mem_usage and not is_accelerate_available():
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is not used for downloading the model, but just for loading the classes

@patrickvonplaten patrickvonplaten changed the title Allow returning local path [From pretrained] Allow returning local path Nov 28, 2022
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Nov 28, 2022

The documentation is not available anymore as the PR was closed or merged.

Copy link
Member

@anton-l anton-l left a comment

Choose a reason for hiding this comment

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

LGTM! This should probably be in the flax pipeline as well, to keep them in sync

@keturn
Copy link
Contributor

keturn commented Dec 2, 2022

This gets the job done with minimal disruption to the existing API. But methods that don't have a consistent return type are real hard to type-check and use consistently. from_pretrained being a method that takes a whole mob of arguments, sometimes bundled up as **components or something, makes things a bit riskier as you might be passing that through without paying too much attention to whether one of them is going to change the return type on you.

Alternatives could be:

  • stick the cached_folder property on the returned instance somewhere, or perhaps in its .config.
  • add a new method from_pretrained_and_stuff that returns a dataclass or namedtuple with model and cached_folder attributes.
  • have some separate function find_path_of_pretrained(pretrained_model_or_path, revision, subfolder) that only returns the Path.

@patrickvonplaten
Copy link
Contributor Author

This gets the job done with minimal disruption to the existing API. But methods that don't have a consistent return type are real hard to type-check and use consistently. from_pretrained being a method that takes a whole mob of arguments, sometimes bundled up as **components or something, makes things a bit riskier as you might be passing that through without paying too much attention to whether one of them is going to change the return type on you.

Alternatives could be:

  • stick the cached_folder property on the returned instance somewhere, or perhaps in its .config.
  • add a new method from_pretrained_and_stuff that returns a dataclass or namedtuple with model and cached_folder attributes.
  • have some separate function find_path_of_pretrained(pretrained_model_or_path, revision, subfolder) that only returns the Path.

Think in the future we could have from_pretrained(...) better modularized, but for now this should work. Using return_cached_folder will stay an edge case and it's turned off by default - think someone wouldn't just turned it on by accident.

@patrickvonplaten patrickvonplaten merged commit 22b9cb0 into main Dec 2, 2022
@patrickvonplaten patrickvonplaten deleted the allow_returning_local_path branch December 2, 2022 11:26
tcapelle pushed a commit to tcapelle/diffusers that referenced this pull request Dec 12, 2022
sliard pushed a commit to sliard/diffusers that referenced this pull request Dec 21, 2022
yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
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.

None yet

4 participants