Skip to main content

cattensors

Faster safetensors loading for JuiceFS.

Note: This library was developed and benchmarked against JuiceFS, but in theory should work with any network backed distributed filesystem.

cattensors monkey-patches safetensors to pre-warm the OS page cache before tensor reads. On network backed filesystems, the first read of a large model file is slow. cattensors reads the file into page cache using parallel threads so subsequent mmap based access hits RAM instead of the network.

Compatibility

  • POSIX platforms (Linux/macOS)
  • Not supported on Windows (fcntl.flock is used for cross-process coordination)

Installation

pip install git+https://github.com/badayvedat/cattensors

Usage

Installing or importing cattensors does not patch anything. Call patch() explicitly in each process that loads models:

import cattensors

cattensors.patch()

from safetensors.torch import load_file

Call it before importing libraries such as diffusers or transformers that may cache references to safetensors functions. Importing torch first is fine; existing from safetensors import safe_open or from safetensors.torch import load_file references cannot be updated by patching later. Calling patch() before any torch/safetensors-related imports is the simplest safe convention.

Flashpack patching is separate and opt-in:

from cattensors.flashpack_patch import patch as patch_flashpack

patch_flashpack()

Call this before importing code that caches flashpack reader functions.

No startup .pth file is installed, and CATTENSORS_AUTO_PATCH is no longer supported. When upgrading an older installation, ensure its cattensors.pth has been removed from site-packages (a normal package upgrade should remove it).

Configuration

Environment variables:

Variable Default Description
CATTENSORS_WARM_THREADS 8 Parallel reader threads per file
CATTENSORS_PARALLEL_SHARDS false Pre-warm sibling shards in background when loading sharded models
HF_ENABLE_PARALLEL_LOADING false If true, cattensors skips sibling-shard parallel warming to avoid overlapping I/O
CATTENSORS_DEBUG false Enable debug logs to stderr

Flags are read when used, so changes affect subsequent load calls.

Metadata

Release files for cattensors 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cattensors 0.2.0
File Size Uploaded Provenance
cattensors-0.2.0.tar.gz 157.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for cattensors 0.2.0
File Interpreter ABI Platform
cattensors-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 166.5 kB

Release files / cattensors-0.2.0.tar.gz

Download URL cattensors-0.2.0.tar.gz
Size 157.1 kB
Tags Source
SHA-256 checksum
How to use checksums
ca156bf57d4ef6713a39c4bc867e26df1cd3bb77a9dbeeece23cb107d4079670
BLAKE2b-256 checksum
How to use checksums
2dc89c93b89242714a0062e033a104ea88acb0abedf12dfb3a9bcffc35a88e6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / cattensors-0.2.0-py3-none-any.whl

Download URL cattensors-0.2.0-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a574f56da17dfc91a3df3ec1211c8a8acd21f36144d2b5e60104c164ba6f0046
BLAKE2b-256 checksum
How to use checksums
3b8c2fb2b697f912ea53142b20323ec251ee0d2a8034260967b47b831721819d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for cattensors 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page