Load torch checkpoints as NumPy arrays without torch at runtime.
Project description
ptloader
Load zip-based PyTorch checkpoints as NumPy arrays, without installing torch at runtime.
ptloader is designed to feel familiar if you already use torch.load, while staying minimal and safe.
Quickstart
Install:
uv add ptloader
Use:
from ptloader import load
state = load("model.pt")
print(type(state["layer.weight"])) # numpy.ndarray
load(...) preserves nested Python structures (dict, list, tuple, OrderedDict) and converts tensors to numpy.ndarray.
API (torch-like usage)
from ptloader import load
obj = load(
f, # path or binary file object
weights_only=True, # default behavior
)
Supported parameters:
f:str | pathlib.Path | BinaryIOweights_only:NoneorTruesupported (FalseraisesCheckpointError)
Unsupported torch.load parameters currently raise CheckpointError:
map_locationpickle_modulemmap- custom pickle load args
Notes
- Runtime dependency:
numpy - Tests use
torchto generate realistic checkpoint fixtures - Only zip-based checkpoints are supported (PyTorch default format)
Development
uv sync
uv run pytest -q
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 ptloader-0.1.5.tar.gz.
File metadata
- Download URL: ptloader-0.1.5.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76ecf1b8edbd282a532a858cbeee0f621b0987c19220982e4f5d203e69f6e9c7
|
|
| MD5 |
e9f876b4469d8a1527ef4a18eb4cb144
|
|
| BLAKE2b-256 |
229cd56c4e79709647af738a9759498c0d9b8f6d7b0afb89341cbd6a70e43f4b
|
File details
Details for the file ptloader-0.1.5-py3-none-any.whl.
File metadata
- Download URL: ptloader-0.1.5-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20c529cf497bb4ebc4864d1c8ec766f4102d3888b3914018281d3b338d31860f
|
|
| MD5 |
91d01e74ac93ebb23decf2882e131a64
|
|
| BLAKE2b-256 |
ee0b0a3d8e34a0b0b77662c8a7b45ffb720ae5b8e6089d9e6bc3af2cf55d087a
|