01Chapter 1: What is inside a model fileA trained model is more than a file of numbers. It is a model artifact: a saved package that lets another program rebuild or use a model. The artifact may contain learned weights, the model architecture, training settings, metadata, and sometimes the state of the training process.2 min read
02Chapter 2: Serialization: turning objects into bytes and backAssume you know basic Python, classes, and tensors. You should also know that a trained model has learned weights, such as matrices and vectors, that must be stored between program runs.2 min read
03Chapter 3: How pickle works: a small virtual machineAssume you know basic Python classes, special methods, byte streams, and the difference between a model and its weights. You should also understand that serialization turns an in-memory object into bytes, while deserialization reconstructs the object from those bytes.2 min read
04Chapter 4: Reading a pickle with pickletoolsThis chapter assumes basic Python, classes, special methods, and familiarity with trained model weights. You should also know that loading a pickle can execute code. The goal here is to inspect a pickle without loading it.2 min read
05Chapter 5: Why loading a pickle can run codeAssume you know basic Python classes, special methods, model weights, and byte streams. You should also understand that loading a file supplied by someone else is a security boundary.2 min read
06Chapter 6: Where pickle shows up in ML workflowsAssume you know basic Python classes and special methods, understand model weights, and have used a deep learning framework such as PyTorch. This chapter focuses on recognizing pickle in common machine learning workflows and deciding when loading it is unsafe.2 min read
07Chapter 7: Inside a PyTorch checkpointAssume you know basic Python, classes, tensors, and PyTorch. You should also know that a model's weights are numerical tensor values, while the model code defines how those values are used.2 min read
08Chapter 8: Restricting what an unpickler may importAssume you know basic Python classes, special methods, and PyTorch checkpoints. You should also know that a pickle file is a byte stream that can describe Python objects. This chapter focuses on one defense: allowing an unpickler to resolve only explicitly approved classes and functions.2 min read
09Chapter 9: Loading PyTorch files with weights_only=TrueAssume you know basic Python classes, PyTorch tensors, and the difference between a model and its learned weights. This chapter focuses on loading a PyTorch checkpoint safely. It does not make an untrusted file automatically safe.2 min read
10Chapter 10: safetensors: a data-only tensor formatThis chapter assumes basic Python, familiarity with model weights, and basic PyTorch use. The goal is to load tensor data without asking Python to reconstruct arbitrary objects.2 min read
11Chapter 11: GGUF for local inference and quantized modelsAssume you know what model weights are, have basic Python and PyTorch experience, and understand that a byte stream is a sequence of stored bytes. This chapter focuses on GGUF, a model format commonly used for running language models locally.2 min read
12Chapter 12: ONNX: a graph format built on protobufThis chapter assumes basic Python, familiarity with trained model weights, and basic PyTorch or another deep learning framework. You should also know that a byte stream is a sequence of bytes used to store or transmit data.2 min read
13Chapter 13: TensorFlow and Keras formats and their risksAssume you know basic Python, have used a deep-learning framework such as PyTorch or TensorFlow, and understand that model weights are learned numbers. The important distinction here is between storing tensor data and storing instructions for rebuilding a model.2 min read
14Chapter 14: Choosing a format: safety, portability and speedAssume you know Python classes, trained model weights, and basic PyTorch use. This chapter focuses on choosing a storage format after training. The format affects security, interoperability, loading speed, and whether the file can be used for training or only inference.2 min read
15Chapter 15: Converting existing checkpoints to safetensorsThis chapter assumes you know basic Python, PyTorch, model weights, and byte-based file formats. It also assumes that the checkpoint already exists and that you can identify the model architecture needed to use its weights.2 min read
16Chapter 16: A layered approach to loading third-party modelsAssume you know basic Python, model weights, PyTorch, and file formats. This chapter focuses on reducing risk when a model came from someone else. No single loading option can make every artifact safe.2 min read