Skip to content

feat(hub): adding downloadFileToCacheDir #1034

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

Merged

Conversation

axel7083
Copy link
Contributor

@axel7083 axel7083 commented Nov 15, 2024

Description

Following #1031 which added a pathsInfo method which can return the etag/commitHash for a given file. Allowing to be compliant with the _hf_hub_download_to_cache_dir1 method from the python library.

Potential issue

The JS implementation do not handle the .lock files as the python library does.. This could be a problem if using the JS and PY function.. ?

The JS could make a basic implementation of the lock file that the PY lib is doing if this is a hard requirement.

Testing

I wrote tests for the existing downloadFile function (no change to the implementation) and the new one added downloadFileToCacheDir.

  • unit tests has been added

Footnotes

  1. huggingface_hub/file_download.py#L882

@axel7083 axel7083 requested a review from coyotte508 as a code owner November 15, 2024 13:42
@axel7083 axel7083 changed the title feat: adding downloadFileToCacheDir feat(hub): adding downloadFileToCacheDir Nov 15, 2024
@axel7083 axel7083 requested a review from coyotte508 November 15, 2024 15:30
@axel7083 axel7083 requested a review from coyotte508 November 16, 2024 14:27
@coyotte508
Copy link
Member

coyotte508 commented Nov 16, 2024

Thanks a lot, probably a browser: { "./download-file-to-cache-dir.ts": false} to add in package.json

@axel7083
Copy link
Contributor Author

Thanks a lot, probably a browser: { "./download-file-to-cache-dir.ts": false} to add in package.json

Should be good now :) !

@coyotte508
Copy link
Member

Can you find a way to skip the test in browser environment? (I can look into it otherwise)

@axel7083
Copy link
Contributor Author

Can you find a way to skip the test in browser environment? (I can look into it otherwise)

Yes, I excluded it from packages/hub/vitest-browser.config.mts.

@coyotte508
Copy link
Member

Thanks!!

@coyotte508 coyotte508 merged commit 2e0c2c6 into huggingface:main Nov 18, 2024
4 checks passed
coyotte508 added a commit that referenced this pull request Nov 19, 2024
## Description

We can now create a `snapshotDownload` method similator to the
`snapshot_download` of the PY lib[^1], clone to the cache (only cache
supported for now) a repository (either model, space or dataset)

[^1]:
https://huggingface.co/docs/huggingface_hub/en/guides/download#download-an-entire-repository

## Related issues/PR

With the amazing help of @coyotte508 we were able to merge the following
changes

- #1034
- #1031
- #999

Which allow this PR to provide a python compliant clone of a hugging
face repository to the cache directory.

## Testing

- [x] unit tests are covering the new feature

**Manually**

```ts
await snapshotDownload({
	repo: {
		name: 'OuteAI/OuteTTS-0.1-350M',
		type: 'model',
	},
});
```

assert using the `huggingface-cli` tool (python)
```
$: huggingface-cli scan-cache
REPO ID                             REPO TYPE SIZE ON DISK NB FILES LAST_ACCESSED     LAST_MODIFIED     REFS LOCAL PATH                                                                         
----------------------------------- --------- ------------ -------- ----------------- ----------------- ---- ---------------------------------------------------------------------------------- 
OuteAI/OuteTTS-0.1-350M             model           731.6M       14 5 minutes ago     5 minutes ago     main /home/axel7083/.cache/huggingface/hub/models--OuteAI--OuteTTS-0.1-350M
```

---------

Co-authored-by: Eliott C. <[email protected]>
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.

2 participants