.ckpt has no single format. A PyTorch Lightning checkpoint is one file
written by torch.save, so its bytes are those of a
PyTorch archive; what matters is the dictionary
inside. A TensorFlow checkpoint is a set of files sharing a prefix such as
model.ckpt. This page follows Lightning’s
checkpoint_connector.py
(dump_checkpoint) and TensorFlow’s
tensor_bundle.h,
tensor_bundle.cc and tensor_bundle.proto, all read
2026-11-12.
PyTorch Lightning
The pickled object is a dictionary. Lightning always writes the first five keys;
the next ones are left out when the checkpoint is saved with
weights_only.
| Key | Value |
|---|---|
epoch | The training epoch. The code notes it is kept for compatibility and not used for restoring. |
global_step | The global training step, likewise. |
pytorch-lightning_version | The Lightning version that wrote the file. |
state_dict | The model’s state_dict: parameter names mapped to tensors. |
loops | State of fit_loop, validate_loop, test_loop and predict_loop. |
callbacks | Each callback’s state (not with weights_only). |
optimizer_states | A list with each optimiser’s state_dict (not with weights_only). |
lr_schedulers | A list with each learning-rate scheduler’s state_dict (not with weights_only). |
| The precision plugin’s class name | Its state, when it has any (not with weights_only). |
hyper_parameters | The model’s and data module’s saved hyperparameters, as a dictionary (or an OmegaConf container). |
hparams_name, hparams_type | The name the hyperparameters were saved under, and the container type when OmegaConf is used. |
| The data module’s class name | Its state_dict, when it returns one. |
| Anything else | The model’s on_save_checkpoint hook may add its own keys. |
TensorFlow checkpoint bundle
A tensor bundle is a set of immutable files with a common prefix:
ckpt.index
ckpt.data-00000-of-00020
ckpt.data-00001-of-00020
…
ckpt.data-00019-of-00020
- The
.indexfile is a string-to-string immutable table (TensorFlow’stable::Table). Each key is a tensor name and each value a serialisedBundleEntryProto. - The key that is the empty string, always the first in the table, holds a
BundleHeaderProto. - The
.data-NNNNN-of-NNNNNshards hold the raw tensor bytes. The writer can pad each tensor to a set data alignment.
| Message | Field | Meaning |
|---|---|---|
BundleHeaderProto | 1 num_shards | Number of data files. |
2 endianness | 0 little (the default), 1 big. It affects only the tensor bytes, not the protobufs, and a bundle can only be read on a platform of the same byte order. | |
3 version | A VersionDef; the writer sets producer 1 and minimum consumer 0. | |
BundleEntryProto | 1 dtype, 2 shape | The tensor’s data type and shape. |
3 shard_id | Which data file holds the bytes. | |
4 offset | Start of the bytes in that file. | |
5 size | Number of bytes. | |
6 crc32c | CRC-32C of the tensor bytes. | |
7 slices | Present only for a partitioned tensor: then fields 1 and 2 describe the full tensor, fields 3 to 6 are ignored, and each slice has its own entry, keyed by the slice name. |
Further details of the bundle, from tensor_bundle.cc and
tensor_bundle.proto (TensorFlow master, read 2026-11-13): the
crc32c in an entry is the masked CRC-32C (the same mask as the table
blocks below); tensor data in a shard is padded with zero bytes up to the writer's
data_alignment option; a partitioned tensor's slice entries are stored under a
key made by EncodeTensorNameSlice, which writes with TensorFlow's
OrderedCode the number 0, the tensor name, the number of dimensions and then for
each dimension the signed start and length (a full-extent dimension is −1 and −1); the byte
form of OrderedCode numbers was not read, so decoding a slice key is not possible from this
page. Entries are in the table's sorted key order and the empty header key sorts first.
String and variant tensors
- Other types: a tensor of any numeric or bool dtype is its raw in-memory bytes (
size= elements times element size), in the bundle's endianness. DT_STRING: the varint64 lengths of all elements, then a 4-byte masked CRC-32C of the lengths, then the string bytes back to back. The entry's CRC-32C covers the lengths (each as a uint32, or as a uint64 when over 4 GiB, not as varints), the length checksum and all string bytes.DT_VARIANT: per element a varint64 length, the serialised variant bytes and a 4-byte checksum; the entry's CRC covers the lengths, bytes and checksums (the source comments, same on read and write).
The .index table (sstable)
The .index file is a LevelDB-format sorted table. Sources: LevelDB's
doc/table_format.md (main branch) and TensorFlow's copy in the
xla/tsl/lib/io folder of the OpenXLA repository (format.h,
format.cc, block_builder.cc, table_builder.cc,
table_options.h), read 2026-11-13.
- File layout: data blocks; meta blocks; the metaindex block; the index block; a fixed footer at the end.
- BlockHandle: two varint64 values, the block's file offset and its size (not counting the trailer). At most 10 bytes each.
- Footer (48 bytes): the metaindex handle, the index handle, zero padding to 40 bytes (2 × 20), then the magic number as 8 bytes, written as two little-endian 32-bit words, low word first:
0xdb4775248b80fb57(the leading 64 bits of the SHA-1 of the texthttp://code.google.com/p/leveldb/, per the header comment). A reader checks the magic first. - Block trailer (5 bytes after each block): 1 byte compression type (0 none, 1 Snappy; anything else is an error) and a little-endian 32-bit masked CRC-32C of the block contents plus the type byte. The reader verifies it and fails on a mismatch. The writer defaults here are a block size of 262,144 bytes of uncompressed data, a restart interval of 16 and Snappy compression, falling back to none when Snappy is unavailable or saves under 12.5%.
- Block contents: entries
shared_bytesvarint32,unshared_bytesvarint32,value_lengthvarint32, the key bytes after the shared prefix, the value; thenrestartsuint32[n] (offsets of entries stored withshared_bytes= 0) andnas uint32. Keys are strictly increasing; within a restart interval each key shares a prefix with the previous one, and a restart stores the whole key. Values are stored as given. The index block uses restart interval 1. - Index block: one entry per data block: key a string at least the last key of the block and less than the first key of the next, value the data block's BlockHandle.
- Metaindex block: entries named for meta blocks; LevelDB defines a
filter.Nblock (a filter policy's output, one filter per 2 KB range of block offsets, with a 4-byte array of offsets, a 4-byte offset of that array and 1 byte for lg(base)) and an unfilledstatsblock. Whether TensorFlow's writer emits any meta block was not read.
The protobuf messages
From types.proto, tensor_shape.proto, tensor_slice.proto,
versions.proto, saver.proto and meta_graph.proto (TensorFlow
master, read 2026-11-13).
| Message | Fields |
|---|---|
DataType | 0 DT_INVALID, 1 DT_FLOAT, 2 DT_DOUBLE, 3 DT_INT32, 4 DT_UINT8, 5 DT_INT16, 6 DT_INT8, 7 DT_STRING, 8 DT_COMPLEX64, 9 DT_INT64, 10 DT_BOOL, 11 DT_QINT8, 12 DT_QUINT8, 13 DT_QINT32, 14 DT_BFLOAT16, 15 DT_QINT16, 16 DT_QUINT16, 17 DT_UINT16, 18 DT_COMPLEX128, 19 DT_HALF, 20 DT_RESOURCE, 21 DT_VARIANT, 22 DT_UINT32, 23 DT_UINT64, 24 DT_FLOAT8_E5M2, 25 DT_FLOAT8_E4M3FN, 26 DT_FLOAT8_E4M3FNUZ, 27 DT_FLOAT8_E4M3B11FNUZ, 28 DT_FLOAT8_E5M2FNUZ, 29 DT_INT4, 30 DT_UINT4, 31 DT_INT2, 32 DT_UINT2, 33 DT_FLOAT4_E2M1FN, 34 DT_FLOAT8_E8M0FNU. Values 101 to 134 are the same types as obsolete reference variables (the type number plus 100: DT_FLOAT_REF = 101 … DT_FLOAT8_E8M0FNU_REF = 134); the file says not to use them. |
TensorShapeProto | dim = 2 (repeated Dim: size = 1 int64, at least −1, −1 meaning unknown; name = 2), unknown_rank = 3 (if true, no dim). The first dim is the outermost (row-major) dimension. |
TensorSliceProto | extent = 1 (repeated Extent: start = 1 int64, length = 2 int64 in a oneof, missing or −1 meaning to the end of the dimension), one per dimension of the tensor. |
VersionDef | producer = 1, min_consumer = 2 (int32), bad_consumers = 3 [int32]. A consumer may read the data if producer ≥ its min_producer, its version ≥ min_consumer and it is not among bad_consumers. |
SaverDef | filename_tensor_name = 1, save_tensor_name = 2, restore_op_name = 3 (strings), max_to_keep = 4 (int32; 0 keeps all), sharded = 5, keep_checkpoint_every_n_hours = 6 (float), version = 7 (CheckpointFormatVersion: 0 LEGACY, 1 V1 (deprecated, table::Table based), 2 V2 (current)). |
The .meta file (MetaGraphDef)
TensorFlow 1 style checkpoints add model.ckpt.meta, a serialised
MetaGraphDef: tf.train.export_meta_graph writes it as binary
protobuf unless as_text is set (python/framework/meta_graph.py).
| Message | Fields |
|---|---|
MetaGraphDef | meta_info_def = 1, graph_def = 2 (GraphDef), saver_def = 3, collection_def = 4 (map string to CollectionDef), signature_def = 5 (map string to SignatureDef), asset_file_def = 6 [AssetFileDef], object_graph_def = 7 (SavedObjectGraph). |
MetaInfoDef | meta_graph_version = 1, stripped_op_list = 2 (OpList: the OpDefs used, with descriptions and unused ops removed), any_info = 3 (Any), tags = 4 [string] (for example train, serve, gpu, tpu), tensorflow_version = 5, tensorflow_git_version = 6 (filled in by the framework), stripped_default_attrs = 7 (bool), function_aliases = 8 (map string to string). |
CollectionDef | oneof kind: node_list = 1 (value [string] node names), bytes_list = 2 (value [bytes]: strings and serialised protobufs), int64_list = 3 (packed int64), float_list = 4 (packed float), any_list = 5 ([Any]). |
SignatureDef | inputs = 1 and outputs = 2 (maps string to TensorInfo), method_name = 3 (deprecated), defaults = 4 (map string to TensorProto). |
TensorInfo | oneof encoding: name = 1 (dense tensor name), coo_sparse = 4 (CooSparse: values_tensor_name = 1, indices_tensor_name = 2 (int64 [?, ?]), dense_shape_tensor_name = 3 (int64 [?])), composite_tensor = 5 (CompositeTensor: type_spec = 1 (TypeSpecProto), components = 2 [TensorInfo]); then dtype = 2, tensor_shape = 3. |
AssetFileDef | tensor_info = 1, filename = 2 (file name without directories). |
The contents of GraphDef, OpList, SavedObjectGraph,
TypeSpecProto, TensorProto and Any are defined in other proto
files that were not read here.
Stable Diffusion checkpoints
A Stable Diffusion .ckpt is a Lightning checkpoint (see above) of the
LatentDiffusion model, so its state_dict holds the keys of that
model's parts. Sources: CompVis ldm/models/diffusion/ddpm.py (the module
attribute names) and Hugging Face diffusers
pipelines/stable_diffusion/convert_from_ckpt.py (which prefixes a converter
looks for), read 2026-11-13.
model.diffusion_model.…: the U-Net (DiffusionWrapper.diffusion_model; a ControlNet checkpoint usescontrol_model.instead). A key such asmodel.diffusion_model.input_blocks.2.1.transformer_blocks.0.attn2.to_k.weightappears in the converter, which uses it to tell version 2.1 from other models.first_stage_model.…: the VAE (some files omit the prefix, which the converter allows).cond_stage_model.transformer.…: the text encoder of version 1 models (a Hugging Face CLIP text transformer);cond_stage_model.model.…withtransformer.resblocks.nandtext_projection: the OpenCLIP text encoder of version 2 models. Other prefixes the converter reads:cond_stage_model.final_lnandcond_stage_model.mapper, andconditioner.embedders.0.transformer(its list of prefixes to strip besidecond_stage_model.transformer).model_ema.…: exponential-moving-average copies of the U-Net weights, with the dots of the original names removed (the converter forms the key asmodel_ema.plus the name's remaining parts joined with no dots). The converter treats a file as holding EMA weights when more than 100 keys start withmodel_ema.- Buffers registered by
DDPM:betas,alphas_cumprod,alphas_cumprod_prev,sqrt_alphas_cumprod,sqrt_one_minus_alphas_cumprod,log_one_minus_alphas_cumprod,sqrt_recip_alphas_cumprod,sqrt_recipm1_alphas_cumprod,posterior_variance,posterior_log_variance_clipped,posterior_mean_coef1,posterior_mean_coef2, andscale_factorin the latent model;logvaris a parameter when learned (otherwise a plain tensor, which astate_dictdoes not hold). - Some files nest
state_dictinsidestate_dict; the converter unwraps while the key is present.