Skip to main content

Redirect Ultralytics disk cache files into a local temporary cache root.

Project description

ultralytics-disk-cache-hook

Redirect ultralytics cache="disk" image caches away from the dataset directory and into a local cache root on the training node.

中文说明

Quick Start

from ultralytics_disk_cache_hook import enable
from ultralytics import YOLO

enable()

model = YOLO("yolov8n.pt")
model.train(data="coco128.yaml", cache="disk")

What It Does

When ultralytics runs with cache="disk", it writes *.npy cache files next to the original images by default.

This plugin monkey patches the internal dataset implementation and redirects those cache files into a local temporary cache root instead.

  • Only affects cache="disk"
  • Does not affect cache="ram" or disabled cache
  • Rewrites self.npy_files for detection, segmentation, pose, and other tasks built on BaseDataset
  • Rewrites *.npy paths inside ClassificationDataset.samples for classification tasks
  • 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

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.x still uses the old ultralytics/yolo/data/... layout
  • v8.1.x through v8.3.x do not match the internal hook points used by this patch
  • Starting from v8.4.0, the disk cache structure in BaseDataset and ClassificationDataset matches 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

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

ultralytics_disk_cache_hook-0.1.2.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ultralytics_disk_cache_hook-0.1.2-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file ultralytics_disk_cache_hook-0.1.2.tar.gz.

File metadata

File hashes

Hashes for ultralytics_disk_cache_hook-0.1.2.tar.gz
Algorithm Hash digest
SHA256 87391907c2d3fedaf82cd8cedbabca208332dcfb597060a9bfb88bded91b3918
MD5 929405704a8cb7bfb509d9cf918e5108
BLAKE2b-256 e6e5460f0f83093e1a88986d71c2e130bd87db536be5e955e9d3df9e51a9767e

See more details on using hashes here.

Provenance

The following attestation bundles were made for ultralytics_disk_cache_hook-0.1.2.tar.gz:

Publisher: publish.yml on xx025/ultralytics-disk-cache-hook

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ultralytics_disk_cache_hook-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for ultralytics_disk_cache_hook-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ea0dd300aabcb49550c529bf88b28a67bb0f9f2b62a2e22acfa577fa19ea0bf8
MD5 d209f323c24ed1e4c18db8af8b8d3543
BLAKE2b-256 aa1f824d840195e9c4b086f91b3bba927d428eb233a7065d332947c7b5f43a1d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ultralytics_disk_cache_hook-0.1.2-py3-none-any.whl:

Publisher: publish.yml on xx025/ultralytics-disk-cache-hook

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page