[From pretrained] Allow returning local path
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:
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_folderproperty on the returned instance somewhere, or perhaps in its.config. - add a new method
from_pretrained_and_stuffthat returns a dataclass or namedtuple withmodelandcached_folderattributes. - have some separate function
find_path_of_pretrained(pretrained_model_or_path, revision, subfolder)that only returns the Path.
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_pretrainedbeing a method that takes a whole mob of arguments, sometimes bundled up as**componentsor 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_folderproperty on the returned instance somewhere, or perhaps in its.config.- add a new method
from_pretrained_and_stuffthat returns a dataclass or namedtuple withmodelandcached_folderattributes.- 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.