diffusers icon indicating copy to clipboard operation
diffusers copied to clipboard

[From pretrained] Allow returning local path

Open patrickvonplaten opened this issue 3 years ago • 1 comments

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:

patrickvonplaten avatar Nov 28 '22 12:11 patrickvonplaten

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

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.

keturn avatar Dec 02 '22 00:12 keturn

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 avatar Dec 02 '22 11:12 patrickvonplaten