Redirect Ultralytics disk cache files into a local temporary cache root.
Project description
ultralytics-disk-cache-hook
Redirect ultralytics cache files away from the dataset directory and into a local cache root on the training node.
Quick Start
pip install ultralytics-disk-cache-hook
from ultralytics import YOLO
model = YOLO("yolov8n.pt")
model.train(data="coco128.yaml", cache="disk")
After installation, the package auto-enables itself for new Python processes via the
ultralytics_disk_cache_hook_auto_enable_startup.pth file in site-packages.
Configuration
You can control the startup defaults with environment variables:
export ULTRALYTICS_IMAGE_DISK_CACHE=1
export ULTRALYTICS_DATASET_META_CACHE=0
Supported false values are 0, false, no, and off.
If you disable or bypass the startup defaults and want to control the hooks explicitly in code:
from ultralytics_disk_cache_hook import enable
enable(image_disk_cache=True, dataset_meta_cache=False)
enable(image_disk_cache=False, dataset_meta_cache=True)
What It Does
When ultralytics runs with cache="disk", it writes *.npy cache files next to the original images by default.
It also writes dataset metadata *.cache files such as labels/train.cache, annotations.cache, or dataset_root.cache next to the dataset source paths.
This plugin monkey patches the internal dataset implementation and redirects those cache files into a local temporary cache root instead.
- By default affects
cache="disk"image caches - By default affects dataset metadata
*.cachefiles - Lets you disable either hook independently via environment variables or
enable(...) - Does not affect
cache="ram"or disabled cache - Rewrites
self.npy_filesfor detection, segmentation, pose, and other tasks built onBaseDataset - Rewrites
*.npypaths insideClassificationDataset.samplesfor classification tasks - Can redirect dataset metadata cache helpers shared by detection, grounding, and classification datasets
- Writes cache files into hash buckets instead of mirroring the original dataset directory tree
Cache Root
The cache root is derived from ULTRALYTICS_DISK_CACHE_TMPDIR when set, otherwise from tempfile.gettempdir(), with ultralytics-disk-cache appended to it.
Override it with an environment variable:
export ULTRALYTICS_DISK_CACHE_TMPDIR=/local_nvme/tmp
Example cache path:
/mnt/shared-storage/datasets/coco/images/train2017/000000000001.jpg
-> <cache-root>/d1/3f/d13f474cca61f46ba06ecba11c1b3046.npy
Dataset metadata cache example:
/mnt/shared-storage/datasets/coco/labels/train.cache
-> <cache-root>/7a/9c/7a9c5f8af885b2f5c6c2f67066342c0a.cache
Version Support
This plugin monkey patches non-public ultralytics internals, so it only claims support for versions whose source layout has been checked.
The current code enforces the following validated range:
- Minimum supported version:
8.4.0 - Maximum validated version:
8.4.38 - Allowed range:
8.4.0 <= ultralytics <= 8.4.38
If the installed version is outside that range, enable() raises UnsupportedUltralyticsVersionError.
Why:
v8.0.xstill uses the oldultralytics/yolo/data/...layoutv8.1.xthroughv8.3.xdo not match the internal hook points used by this patch- Starting from
v8.4.0, thedisk cachestructure inBaseDatasetandClassificationDatasetmatches this plugin
This range is based on checked GitHub source files and release/tag history. As of 2026-04-17, the latest verified release I checked is v8.4.38.
Check the installed version with:
python -c "import ultralytics; print(ultralytics.__version__)"
Disk Space
This plugin does not currently validate whether the cache disk has enough free space.
When cache="disk" is enabled, the plugin prints a warning with the cache root and asks the user to manage disk space manually.
If the local cache disk fills up, the error will occur when *.npy files are actually being written.
References
- Ultralytics releases: https://github.com/ultralytics/ultralytics/releases
- Ultralytics tags: https://github.com/ultralytics/ultralytics/tags
v8.4.38release: https://github.com/ultralytics/ultralytics/releases/tag/v8.4.38
Copyright
Copyright (c) xx025. All rights reserved.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ultralytics_disk_cache_hook-0.2.0.tar.gz.
File metadata
- Download URL: ultralytics_disk_cache_hook-0.2.0.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ef9cb45906c65963579a6dd53194a949c1f2a7b4825bbf8b8bad40eb4553006
|
|
| MD5 |
986752c35dae7ec1b6f5384fd802128f
|
|
| BLAKE2b-256 |
458bdf9f8dc32c3440a2a65dfb8ac10ce349e5e5b4d99832b249f664353edfb1
|
Provenance
The following attestation bundles were made for ultralytics_disk_cache_hook-0.2.0.tar.gz:
Publisher:
publish.yml on xx025/ultralytics-disk-cache-hook
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ultralytics_disk_cache_hook-0.2.0.tar.gz -
Subject digest:
2ef9cb45906c65963579a6dd53194a949c1f2a7b4825bbf8b8bad40eb4553006 - Sigstore transparency entry: 1339326130
- Sigstore integration time:
-
Permalink:
xx025/ultralytics-disk-cache-hook@78881b1c57e8a8af1a81bceb3fe464631322ffc0 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/xx025
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@78881b1c57e8a8af1a81bceb3fe464631322ffc0 -
Trigger Event:
release
-
Statement type:
File details
Details for the file ultralytics_disk_cache_hook-0.2.0-py3-none-any.whl.
File metadata
- Download URL: ultralytics_disk_cache_hook-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c028aab1f35d1e33dcd25589b425eceaa5f955e12e0a38bf7543d296222a780f
|
|
| MD5 |
696302bfcdf30a86f3f6847a2010495f
|
|
| BLAKE2b-256 |
1abc4b1a84f1eba08a8830a5d9d726900243230fbf5e2347f6f59b33d34b8c18
|
Provenance
The following attestation bundles were made for ultralytics_disk_cache_hook-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on xx025/ultralytics-disk-cache-hook
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ultralytics_disk_cache_hook-0.2.0-py3-none-any.whl -
Subject digest:
c028aab1f35d1e33dcd25589b425eceaa5f955e12e0a38bf7543d296222a780f - Sigstore transparency entry: 1339326138
- Sigstore integration time:
-
Permalink:
xx025/ultralytics-disk-cache-hook@78881b1c57e8a8af1a81bceb3fe464631322ffc0 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/xx025
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@78881b1c57e8a8af1a81bceb3fe464631322ffc0 -
Trigger Event:
release
-
Statement type: