Separate the weights from the code
Before loading a model, ask two questions. What format stores the numerical weights? What software will the loading process run? The answers are separate.
Some PyTorch checkpoints use pickle to reconstruct Python objects. Loading an unrestricted pickle from an untrusted source can run code in your process. The .pt and .bin extensions alone do not tell you how a file was made. Current PyTorch defaults to a restricted weights_only loader for normal torch.load calls that do not supply a custom pickle module. This limits which objects can be rebuilt; it is still not a reason to open an unknown checkpoint. If a file fails to load, do not disable that protection just to make it open. See PyTorch serialization notes.
What safetensors stores
The file contains a length prefix, a JSON header that lists the tensor shapes, types and byte offsets, and the tensor bytes. There is no pickle instruction stream in that format. Offsets also let compatible tools inspect the header or read selected tensor data without loading everything at once. The exact performance depends on your hardware and loader. See the safetensors format and library.
A loading example with two explicit choices
This example uses an architecture supported by Transformers. It downloads model weights, so read the code first if you only want to inspect the repository.
from transformers import AutoModel
model = AutoModel.from_pretrained(
"openai/whisper-tiny",
revision="169d4a4341b33bc18d8881c4b69c2e104e1cc0af",
use_safetensors=True,
trust_remote_code=False,
)use_safetensors=True asks Transformers to use safetensors rather than falling back to a different weights format. A load can still fail for many other reasons. Read the error before assuming that the format is missing.
trust_remote_code=False keeps the Hub repository’s custom model code out of this load. Enabling the flag lets Transformers run custom Python from the repository. Safetensors does not protect that separate route. A pinned revision makes the choice reproducible; it does not tell you that the pinned code is safe. If you cannot establish that you trust the code, choose a supported alternative. The Transformers loading guide explains the distinction.
What a scan can and cannot tell you
The Hub reports scan results on files. The Hub’s description of pickle scanning calls out limits of import inspection. A clear scan, a popular organisation and a familiar file extension do not replace knowing what you are loading. Reading the imports is a start when reviewing code; it is not a complete review.
Try it in the browser
Open the Whisper Tiny repository at the pinned revision above. Find the safetensors weights and config.json. Write down the file format, the architecture and the revision. Now imagine the usage snippet asked you to enable custom code. Which of those three facts would change, and what new trust decision would you have to make? You can answer without installing anything or running a model.
Check your understanding
A team standardises on use_safetensors=True for every model they load, and also loads a new vision-language architecture with trust_remote_code=True. What risk remains?
Pick the one you would defend. Your answer stays private.
Your place and first choices stay on this browser. Classroom credit is recorded separately.
Every lesson here is open. Your progress is recorded once you pass the Image Generation, in Practice exam.
Stuck on something?Ask Arjun, your AI tutor