Loading tutorials
__reduce__. You should know that a pickle is a list of opcodes that a small virtual machine runs, and that GLOBAL-style opcodes plus REDUCE can call functions. Here you will learn t4 min read__init__. It also assumes you know that a model file stores trained weights. You have seen that pickle is a stack-based instruction stream. Here you will see how that design lets a file you load run code you5 min read__reduce__ lets a pickle run code on load. It also assumes you have used PyTorch or scikit-learn to save a model. Here you will learn where pickle appears in everyday machine learning (ML) work, which uses cross a5 min readGLOBAL, REDUCE and pickletools.dis. You should also be comfortable with nn.Module, state_dict() and torch.save. Here you will open a .pt or .pth file and see where pickle sits inside it. That t5 min read__reduce__ can run code on load. Here you will learn how to limit what an unpickler is allowed to import, why that works, and where it stops working.5 min readtorch.save and torch.load are used, what a state_dict is, and why unpickling untrusted data can run code (the __reduce__ mechanism from earlier chapters). Here you will see what weights_only=True allows, what it rejects, how it fails, and where it stops pr5 min read__reduce__, so you know why loading a pickle can run code. Here we look at the format that removes that risk by5 min read__reduce__ attack from earlier chapters has no equivalent in the format. This chapter as4 min read__reduce__, and that you have used model.save() or tf.saved_model at least once. The central point is that thes5 min read__reduce__ allows code execution. It also assumes you have seen torch.load(..., weights_only=True) and the safetensors layout from earlier chapters. Here you compare the formats and pick one for a given job.5 min readstate_dict, know that torch.load unpickles files, and have read the earlier chapters on weights_only=True and the safetensors layout. Here you will turn a .pt or .pth checkpoint into a .safetensors file, check that the result is faithful, and h4 min read__reduce__ leads to code execution, what torch.load(weights_only=True) restricts, and how safetensors differs from pickle-based checkpoints. It combines those pieces into one workflow. No single control makes an untrusted model safe, so you stack severa5 min read