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

feat(models): add output_dir option to model_download #178

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

KeijiBranshi
Copy link
Member

BUG=b/377340841 (for googlers)

Adds support for an output_dir argument, similar to HuggingFace Hub's local_dir.

This change is primarily motivated by this torchtune RFC: pytorch/torchtune#1852 (comment)

While we could use a stopgap solution and copy files within torchtune, this behavior is general enough that direct kagglehub users could benefit from it.

"""Download model files.

Args:
handle: (string) the model handle.
path: (string) Optional path to a file within the model bundle.
force_download: (bool) Optional flag to force download a model, even if it's cached.

output_dir: (str) Optional path to copy model files to after successful download.
Copy link
Member

Choose a reason for hiding this comment

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

we should integrate the default path here instead.

Copy link
Member

Choose a reason for hiding this comment

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

@rosbo - The parameters for this fn is starting to grow. Any thoughts on managing this? Should we use wrap this in a settings/configuration object instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

just my nitpick opinion: I don't think the explicit default path here is necessary since it circumvents the general cache behavior, which is encapsulated in the http resolver.

Copy link
Contributor

Choose a reason for hiding this comment

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

We want this method to be easy to use and I feel like adding a settings object would complicate it more than anything. Users will use keyword argument for these and likely set no parameters or at most 1-2.
If we compare to huggingface_hub.snapshot_download(...), we don't have many arguments... https://github.com/huggingface/huggingface_hub/blob/4011b5a2836d7bb036d8da54ed656f88bc0d2f7f/src/huggingface_hub/_snapshot_download.py#L21-L45

Copy link
Member

Choose a reason for hiding this comment

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

sg.

src/kagglehub/models.py Outdated Show resolved Hide resolved
"""Download model files.

Args:
handle: (string) the model handle.
path: (string) Optional path to a file within the model bundle.
force_download: (bool) Optional flag to force download a model, even if it's cached.

output_dir: (string) Optional path to copy model files to after successful download.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the user's expectation would be that files are downloaded directly to this output_dir and the cache folder is skipped entirely.

Copy link
Member

@neshdev neshdev left a comment

Choose a reason for hiding this comment

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

LGTM

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.

3 participants