Containers · .pt
PyTorch torch.save checkpoint (.pt / .pth / .bin / .ckpt)
torch.save writes an uncompressed ZIP (PyTorch's own writer, "inline_container") with one top-level folder holding a pickle of the user's object (data.pkl) and one record per storage (data/<key>), each 64-byte aligned in the file. Tensors in the pickle are reduce-calls to torch._utils._rebuild_tensor_v2/v3 whose storage argument is a persistent id resolved to a data/ record. Because the container is pickle, loading can run arbitrary code unless restricted to an allowlist (weights_only=True, default since torch 2.6). HF "pytorch_model.bin" is this format; sharding uses pytorch_model.bin.index.json (same schema as the safetensors index).
.pt .pth .bin .ckpt
- What it is
- many tensors
- Byte order
- file declared
- Dimension order
- row major
- Compression
- none
- Metadata
- pickle
- Loading
- executes code The usual loader executes code unless that is turned off.
How to read it
Uncompressed ZIP. Record order: data.pkl, .format_version, .storage_alignment, byteorder, data/0..data/n, version, .data/serialization_id, then the central directory.
- <archive>/data.pkl
- pickle protocol 2. the saved object
- <archive>/.format_version
- ascii
- <archive>/.storage_alignment
- ascii
- <archive>/byteorder
- ascii. 'little' or 'big'
- <archive>/data/<key>
- bytes. raw storage bytes, key = persistent id key ('0','1',...)
- <archive>/version
- ascii. '3\n' for current writers
- <archive>/.data/serialization_id
- ascii. random id string
One tensor
- name
- path of the tensor in the unpickled object (state_dict key)
- dtype
- storage_type (v2) or explicit dtype (v3)
- shape
- size tuple
- strides
- stride tuple (elements)
- data_offset
- zip data offset of data/<key> + storage_offset * itemsize
- nbytes
- contiguous: prod(size)*itemsize; otherwise gather using strides
Example
The specs test vector. torch.save (torch 2.14.1+cu130) wrote an uncompressed ZIP. This viewer reads the archive records and does not unpickle data.pkl. The specs record that a weights_only round trip matched w_f32, b_f16, e_bf16, i_i32, and s_f32.
small.pt3,587 bytes
- byteorder
- little
- .format_version
- 1
- .storage_alignment
- 64
- version
- 3
- members
- small/data.pkl 477 bytes small/.format_version 1 bytes small/.storage_alignment 2 bytes small/byteorder 6 bytes small/data/0 1024 bytes small/data/1 16 bytes small/data/2 12 bytes small/data/3 24 bytes small/data/4 4 bytes small/version 2 bytes small/.data/serialization_id 40 bytes
- serialization_id
- 0055190185320359078712506378669613723131
Number formats
The name in the file, and the canonical dtype it maps to.
| In the file | Canonical | Bits |
|---|---|---|
| float32 | float32 | 32 |
| float64 | float64 | 64 |
| float16 | float16 | 16 |
| bfloat16 | bfloat16 | 16 |
| int64 | int64 | 64 |
| int32 | int32 | 32 |
| int16 | int16 | 16 |
| int8 | int8 | 8 |
| uint8 | uint8 | 8 |
| bool | bool | 8 |
| complex64 | complex64 | 64 |
| complex128 | complex128 | 128 |
| float8_e4m3fn | float8_e4m3fn | 8 |
| float8_e5m2 | float8_e5m2 | 8 |
| float8_e4m3fnuz | float8_e4m3fnuz | 8 |
| float8_e5m2fnuz | float8_e5m2fnuz | 8 |
| float8_e8m0fnu | float8_e8m0fnu | 8 |
| float4_e2m1fn_x2 | float4_e2m1fn | 4 |
| uint16 | uint16 | 16 |
| uint32 | uint32 | 32 |
| uint64 | uint64 | 64 |
| quantized | none | — |