After humming like a small jet engine all night, your GPU fans finally quiet down. A glorious line appears in your terminal: Training Finished.
Now comes the moment of truth: saving the model you just spent days babysitting.
For many developers, this once felt like a routine step. If you were working in PyTorch, you saved a .pt or .pth file. If you were using TensorFlow, you exported a SavedModel directory and called it a day.
Then the destinations multiplied. Models needed to move from training clusters to production servers, developer MacBooks, smartphones, and embedded devices. Saving a model became part of deciding how to distribute and run it.
Today, the landscape includes .pt, .safetensors, .onnx, .tflite, and .gguf. They may look like different answers to the same question, but they serve different purposes:
- Preserving training state so an interrupted run can resume.
- Distributing tensors without pickle-style code execution.
- Representing a computational graph for compatible inference runtimes.
- Packaging models for mobile and embedded deployment.
- Bundling LLM weights and metadata for convenient local inference.
You do not need to memorize every file extension. Start with one question:
Where does this model need to go next?
1. Resuming Training: PyTorch Checkpoints (.pt, .pth)
If you work in PyTorch, this probably looks familiar:
torch.save(model.state_dict(), "model.pt")
This saves the model’s parameters and persistent buffers. But saving weights is not the same as saving enough state to resume training.
For a long training run, you will usually want a broader checkpoint:
torch.save({
"model": model.state_dict(),
"optimizer": optimizer.state_dict(),
"scheduler": scheduler.state_dict(),
"epoch": epoch,
"scaler": scaler.state_dict(),
}, "checkpoint.pt")
Alongside the model, this captures optimizer state, the learning rate schedule, training progress, and the gradient scaler if your training setup uses one. Depending on the pipeline, reproducible resumption may also require random number generator and data sampling state.
The checkpoint’s job is to preserve the information your training loop needs to continue.
Flexibility and Pickle
The extensions .pt and .pth are naming conventions commonly used for files saved with torch.save().
PyTorch serialization uses Python’s pickle machinery for objects and metadata, with tensor storage handled separately. This makes checkpoints flexible, but unrestricted pickle loading carries a security risk: a malicious file can execute code with the permissions of the loading process.
Since PyTorch 2.6, torch.load() defaults to weights_only=True when no custom pickle module is supplied, restricting deserialization and reducing that risk. For large checkpoints, mmap=True allows tensor data to load on demand rather than reading all tensor storage into RAM upfront.
For comparison, in the JAX ecosystem, Orbax addresses a similar need, including saving and restoring distributed training state across accelerators.
Use PyTorch checkpoints when you need to preserve and resume a PyTorch training run.
2. Distributing Weights: Safetensors (.safetensors)
Once training is complete, optimizer buffers and learning rate schedules are usually unnecessary for inference. You can distribute the trained tensors separately from the training checkpoint.
Safetensors, originally developed by Hugging Face, is designed for this purpose. It stores tensors without relying on executable Python object reconstruction.
Simple Storage, Efficient Access
A Safetensors file contains a JSON header describing each tensor’s name, data type, shape, and location, followed by the raw tensor data.
This layout avoids pickle-style code execution and supports memory-mapped access. A loader can access the tensors or slices it needs without first reading the entire file into RAM, which can reduce loading overhead for large models.
From Model Hubs to GPU Serving
Safetensors is not limited to model distribution on Hugging Face. It has also become a common weight format in GPU-based LLM serving stacks.
Serving engines such as vLLM can load Safetensors weights directly and prefer them when available, while Hugging Face TGI uses Safetensors for efficient weight loading and multi-GPU tensor parallelism. TensorRT-LLM also supports Hugging Face Safetensors checkpoints as an input format for optimized GPU inference.
In other words, the same Safetensors files used to distribute a model can often become the starting point for large-scale GPU serving.
What Comes Alongside the Weights
Safetensors stores tensors and optional metadata, but it does not define how a model computes its outputs. Architecture, tokenizer, and generation settings are typically provided separately.
A model repository might include:
model.safetensors: trained weight tensors.config.json: model architecture and configuration.tokenizer.json: tokenizer vocabulary and rules.tokenizer_config.json: tokenizer settings and special-token configuration.generation_config.json: default generation settings.
The exact files vary by model and tooling. The loader still needs a compatible implementation of the model architecture to use the weights.
Think of Safetensors as a container for the building materials. The model implementation provides the instructions for assembling them.
Use Safetensors when you want to distribute trained weights efficiently or load them into modern GPU inference stacks without pickle-style deserialization.
3. Moving Computational Graphs: ONNX (.onnx)
Safetensors stores tensors. ONNX, short for Open Neural Network Exchange, also describes the operations that use them.
Consider a vision block that applies a convolution, batch normalization, and then a ReLU activation. A weight file stores the relevant tensors. An ONNX model represents the operations, their connections, and their parameters.
It can include weights in the model file or reference external data files for large tensors.
The result is a framework-independent representation of a model’s computational graph and weights.
Why the Graph Matters
An exported graph allows a compatible runtime to execute the model without the original Python model implementation.
Runtimes such as ONNX Runtime can analyze that graph, simplify operations, fuse supported patterns, and use hardware-specific execution backends. The available optimizations depend on the model and the runtime.
Exporting is not always effortless. Custom operations, dynamic behavior, and operator-version differences can require additional work. The destination runtime must support the operations in the exported model.
Use ONNX when you need a portable graph representation for deployment through compatible inference runtimes.
4. Deploying to the Edge: LiteRT (.tflite)
Now move from the server to a smartphone, an automotive system, or an embedded device.
The constraints change. Memory competes with other applications. Power consumption affects battery life and heat. Available accelerators differ from device to device.
LiteRT, formerly TensorFlow Lite, is Google’s framework for on-device inference, while .tflite is the compact model representation commonly consumed by its runtime. It packages a computational graph and weights for deployment on mobile and embedded devices.
Built for On-Device Inference
The .tflite format is designed for efficient loading. The LiteRT runtime handles execution, reuses memory where possible, and can run supported operations on a device's GPU or NPU.
Quantization can further reduce model size and, on compatible hardware, improve inference efficiency. Actual performance depends on the model, its operations, and the available hardware.
Supported models trained in PyTorch, JAX, or TensorFlow can be converted to .tflite for deployment with LiteRT.
This illustrates a broader principle: the framework you train in does not have to be the runtime you deploy to.
Use
.tflitewhen targeting mobile or embedded devices through the LiteRT ecosystem.
5. Running LLMs Locally: GGUF (.gguf)
For local LLM inference on PCs and Macs, GGUF is a common format. You will often encounter it in tools such as llama.cpp, Ollama, and LM Studio.
Its appeal combines convenient packaging with extensive support for quantized weights in the surrounding ecosystem.
Convenient Packaging
A typical text-model GGUF file can bundle:
- Model weights.
- Architecture metadata, such as layer counts and hidden dimensions.
- Tokenizer vocabulary and related information.
- A chat template, when provided.
- Information needed to interpret quantized tensors.
For supported models, this often lets you download one file and load it in a compatible application. Some models require additional files, and large models may be split across several files, but the packaging still makes local distribution convenient.
The runtime must understand the model’s architecture. Metadata describes the model; the runtime implements its computation.
Smaller Models Through Quantization
Quantization reduces model size by storing weights at lower precision.
For example, an 8-billion-parameter model needs roughly 16 GB for its FP16 weights. A 4-bit quantized version can shrink those weights to around 5 GB. Inference still requires additional memory for the KV cache and runtime buffers.
Labels such as Q8_0, Q5_K_M, and Q4_K_M describe different quantization options. Lower bit widths generally mean smaller files and lower memory requirements, with a possible loss in quality. GGUF can also store floating-point weights; quantization is common, not mandatory.
The goal is to choose a version that fits your hardware while preserving enough quality for your use case.
For a deeper look at quantization formats and labels, see my guide: Untangling the LLM Quantization Alphabet Soup: Q4_K_M, W4A16, GPTQ, AWQ, and Beyond.
Use GGUF when distributing supported models for local inference through tools such as
llama.cpp.
6. The Lifecycle of a Model
Before looking at how these formats fit into a model’s lifecycle, here is the simplest way to remember them:
- .pt preserves training state.
- Safetensors moves tensors.
- ONNX moves computational graphs.
- .tflite takes models to the edge.
- GGUF packages LLMs for local inference.
These are not competing answers to the same problem. They solve different problems at different stages of a model’s journey.
During training, checkpoints preserve the state needed to continue your work. Once the model is ready, its destination determines the next step:
- For sharing weights, publish Safetensors files with the accompanying configuration and tokenizer files.
- For deployment through ONNX-compatible runtimes, export the restored model to ONNX.
- For mobile or edge deployment, convert a supported model to
.tflite, optionally applying quantization to reduce size and improve efficiency on compatible hardware. - For local LLM inference, package a supported model as GGUF, often quantizing the weights to fit the memory available on personal hardware.
These are possible paths, not a mandatory sequence. A model can move from a restored training checkpoint to a deployment format without first being saved as Safetensors. Some serving systems can also load distributed weights directly into their own model implementations.
Conversion involves more than changing a file extension. Graph formats require the model’s computation as well as its weights. GGUF conversion requires a supported architecture and the appropriate inference metadata, typically including model configuration and tokenizer information.
The path depends on the model, the conversion tools, and where you want to run it.
7. Formats vs. Runtimes
One more thing to keep in mind: don’t confuse a file format with an execution runtime.
- ONNX represents a computational graph and weights; ONNX Runtime optimizes and executes supported graphs through its execution backends.
.tflitestores a model representation; LiteRT manages its execution and supported hardware acceleration.- GGUF stores tensors and metadata;
llama.cppimplements supported architectures and manages execution, including CPU/GPU placement and KV cache allocation.
A file extension alone does not guarantee faster inference. Performance depends on how well the runtime and hardware support the model’s operations and numerical formats.
The format determines how the model is represented. The runtime manages how it executes. The hardware performs the computation.
Keeping these roles clear makes tool selection and performance debugging much easier.
8. Looking Beyond File Extensions
Saving a model can look like the final line of a training script. In practice, it is often the beginning of the model’s next journey.
A checkpoint helps training continue. A tensor container helps distribute weights and feed modern GPU serving stacks. A graph format enables deployment through compatible runtimes. An edge format brings models to mobile and embedded hardware. A local inference package makes LLMs easier to run on personal hardware.
Each serves a purpose, and one model may use several during its lifetime.
The useful question is:
Where does this model need to go next?
Once you know the destination, the choice becomes much clearer.