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

Option to use ~/.cache/huggingface/hub for downloaded models #102

Open
DePasqualeOrg opened this issue Jul 4, 2024 · 3 comments
Open

Option to use ~/.cache/huggingface/hub for downloaded models #102

DePasqualeOrg opened this issue Jul 4, 2024 · 3 comments

Comments

@DePasqualeOrg
Copy link
Contributor

The Python transformers library downloads models to ~/.cache/huggingface/hub. This allows reuse of previously downloaded models by multiple apps. Currently, calling HubApi.shapshot in swift-transformers downloads the models to a specified directory, with a different directory structure than the one used by Python transformers. As more apps get built with these libraries, it would be great if swift-transformers and Python transformers could share models in the user's home directory on macOS. (If I understand correctly, this isn't possible on iOS, although apps within the same app group can save models to the app group's shared directory.)

@DePasqualeOrg DePasqualeOrg changed the title Option to use ~/.cache/huggingface/hub to download models Option to use ~/.cache/huggingface/hub for downloaded models Jul 4, 2024
@DePasqualeOrg
Copy link
Contributor Author

Users of my app, which uses MLX and swift-transformers, are requesting to be able to reuse models downloaded from other apps, and the Hugging Face cache directory seems like a natural choice.

https://x.com/Andreadful_/status/1813156367324057611

https://x.com/vincentbosch/status/1813131165437448646

@pcuenca, any idea how this could be approached, given that swift-transformers and the Python transformers library use a different directory structure for storing the models?

@terribilissimo
Copy link

Andreadful_ here. Of course the solution you laid out above would be the neatest, but I could live with just being able to set a directory of choice for swift-transformers' models (that is, I wouldn't mind too much if swift-transformers requires its own directory structure and downloads duplicates of the same models put into the HF cache by python-transformers).
With HF python transformers it's quite easy, you just have to set the HF_HOME env var.
Question: where does swift-transformers download the models by default?? Asking for Mac OS, not iOS.

@DePasqualeOrg
Copy link
Contributor Author

@terribilissimo, you can find it here. It is already possible to define a download directory:
https://github.com/huggingface/swift-transformers/blob/main/Sources/Hub/HubApi.swift

Ideally swift-transformers should be able to share models with the Python transformers library. I can imagine people will be building macOS apps with the Python and Swift implementations, and currently they use different conventions for saving the model files and so cannot share models.

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

No branches or pull requests

2 participants