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

prefetch: use a separate temporary cache for prefetching #730

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

Conversation

skshetry
Copy link
Member

@skshetry skshetry commented Dec 23, 2024

This PR will use a separate temporary cache for prefetching that resides in .datachain/tmp/prefetch-<random> directory when prefetch= is set but cache is not.
The temporary directory will be automatically deleted after the prefetching is done.

For cache=True, the cache will be reused and won't be deleted.

Please note that auto-cleanup does not work for PyTorch datasets because there is no way to invoke cleanup from the Dataset side. The DataLoader may still have cached data or rows even after the Dataset instance has finished iterating. As a result, values associated with a catalog/cache instance can outlive the Dataset instance.

One potential solution is to implement a custom dataloader or provide a user-facing API.
In this PR, I have implemented the latter. The PytorchDataset now includes a close() method, which can be used to clean up the temporary prefetch cache.

Eg:

dataset = dc.to_pytorch(...)
with closing(dataset):
    pass

Copy link

cloudflare-workers-and-pages bot commented Dec 23, 2024

Deploying datachain-documentation with  Cloudflare Pages  Cloudflare Pages

Latest commit: acd168e
Status: ✅  Deploy successful!
Preview URL: https://1557c442.datachain-documentation.pages.dev
Branch Preview URL: https://prefetch-cache.datachain-documentation.pages.dev

View logs

Copy link

Deploying datachain-documentation with  Cloudflare Pages  Cloudflare Pages

Latest commit: afae789
Status: ✅  Deploy successful!
Preview URL: https://d7bd07c5.datachain-documentation.pages.dev
Branch Preview URL: https://prefetch-cache.datachain-documentation.pages.dev

View logs

Copy link

codecov bot commented Dec 24, 2024

Codecov Report

Attention: Patch coverage is 89.02439% with 18 lines in your changes missing coverage. Please review.

Project coverage is 87.48%. Comparing base (60256d6) to head (acd168e).

Files with missing lines Patch % Lines
src/datachain/lib/pytorch.py 68.18% 4 Missing and 3 partials ⚠️
src/datachain/lib/file.py 69.23% 2 Missing and 2 partials ⚠️
src/datachain/lib/prefetcher.py 88.88% 3 Missing and 1 partial ⚠️
src/datachain/cache.py 81.25% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #730   +/-   ##
=======================================
  Coverage   87.47%   87.48%           
=======================================
  Files         114      115    +1     
  Lines       10941    11033   +92     
  Branches     1504     1509    +5     
=======================================
+ Hits         9571     9652   +81     
- Misses        992      999    +7     
- Partials      378      382    +4     
Flag Coverage Δ
datachain 87.41% <89.02%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Also did:

* minor refactor,
* removes `nrows` _hack_ and,
* disables prefetching when `nrows` is set, so that we don't download
    the whole dataset.
`dvc_objects.fs.utils.remove()` works for readonly files too.
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.

1 participant