Hugging Face, End to EndLesson 6 of 75

Module 1 · The Hub, read properly

Loading a model can run someone else’s code

In this lesson

  • 9 min read
  • 4 reading sections
  • Knowledge check
  • Lesson 6 of 9 in this chapter

This chapter’s goalFind a model using filters or the Python API, inspect the files at a known revision, identify the architecture, weights and any custom loading code, and explain what the download counter can and cannot tell you.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmNot availableWatch3:05
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 6Free · no account needed
Lesson steps

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.

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

How to cite: Addaly (2026) ‘Loading a model can run someone else’s code’, in Hugging Face, End to End. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/hugging-face/safetensors-and-pickle (Accessed: 29 November 2026).