Safety, Security & Responsible AI·Question 21 of 70Intermediate

Explain the model supply-chain risks: pickle vs safetensors, weights provenance, dependencies.

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

Loading a model is running someone's code and trusting someone's artifact. Three risk areas (OWASP LLM04:2026 Supply Chain, LLM03 in 2025):

Serialization / pickle. PyTorch's classic .bin/.pt checkpoints are Python pickle files, and unpickling executes arbitrary code via __reduce__. A malicious checkpoint on a hub can pop a shell the moment you torch.load it - this has been demonstrated with real poisoned models. safetensors (Hugging Face) is a data-only format: just tensors and metadata, no code path, so loading is safe by construction and also faster (zero-copy, lazy). Since PyTorch 2.6, torch.load defaults to weights_only=True, which blunts the pickle path, but that restricted unpickler has itself had a code-execution bypass (CVE-2025-32434, fixed in 2.6), so the durable rule is: prefer safetensors; never load pickle checkpoints from untrusted sources.

Full worked answer with diagram

Loading a model is running someone's code and trusting someone's artifact. Three risk areas (OWASP LLM04:2026 Supply Chain, LLM03 in 2025):

Serialization / pickle. PyTorch's classic .bin/.pt checkpoints are Python pickle files, and unpickling executes arbitrary code via __reduce__. A malicious checkpoint on a hub can pop a shell the moment you torch.load it - this has been demonstrated with real poisoned models. safetensors (Hugging Face) is a data-only format: just tensors and metadata, no code path, so loading is safe by construction and also faster (zero-copy, lazy). Since PyTorch 2.6, torch.load defaults to weights_only=True, which blunts the pickle path, but that restricted unpickler has itself had a code-execution bypass (CVE-2025-32434, fixed in 2.6), so the durable rule is: prefer safetensors; never load pickle checkpoints from untrusted sources.

Weights provenance. Where did the weights come from? A model could be backdoored - trained or fine-tuned to behave normally except on a trigger phrase, which flips it to a chosen behaviour (poisoning, LLM05:2026). You can't easily detect this by inspection. Mitigations: download from official/verified sources, pin the exact revision/commit and verify the hash, prefer models with documented training provenance, and be wary of random fine-tunes and LoRA adapters from unknown authors.

Dependencies. The Python/ML stack is a huge dependency tree (transformers, tokenizers, CUDA libs, custom kernels), each a supply-chain vector - typosquatting, malicious versions, trust_remote_code=True executing arbitrary repo code on model load. Mitigations: lockfiles and pinned versions, SBOMs, vulnerability scanning, avoid trust_remote_code unless the source is trusted, and vendor/mirror critical artifacts.

The theme is that AI supply chain is classic supply-chain security plus two new artifact types (weights, datasets) that can carry payloads inspection won't reveal.

Worth sketching. One boundary with four things crossing it makes clear which risks a format change fixes and which it does not touch at all.

flowchart LR
    A["Checkpoint file"] -->|"pickle: code runs on load"| R["Your runtime"]
    A -->|"safetensors: tensors and metadata only"| R
    B["Repo code via trust_remote_code"] --> R
    C["Pinned deps and lockfile"] --> R
    D["Unknown training provenance"] --> W["Backdoor no benchmark will trip"]
    R --> W

What a good answer covers

  • Loading a model is running someone's code and trusting someone's artifact
  • PyTorch's classic .bin/.pt checkpoints are Python pickle files, and unpickling executes arbitrary code…
  • A malicious checkpoint on a hub can pop a shell the moment you torch.load it - this has been…
  • Since PyTorch 2.6, torch.load defaults to weights_only=True, which blunts the pickle path, but that…
  • A model could be backdoored - trained or fine-tuned to behave normally except on a trigger phrase, which…

Key terms: Serialization / pickle · pickle · safetensors · Weights provenance · backdoored · Dependencies

Interviewer follow-ups to expect

  1. Why exactly is unpickling dangerous, and what does safetensors change?

  2. What is a model backdoor and why can't you just inspect the weights to find it?

  3. What does trust_remote_code=True do and when is it acceptable?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep