Skip to content
mentoor

Topic 1 of 5 · 4 min read

Finding and downloading models from the Hub

Goal: Find a model by task, size and licence on the Hub and download a pinned revision with the CLI.

On the Hub, choose a model by task, size and licence first, then download one pinned revision, never "whatever main is today".

Check yourself · 1 of 3

Why should a deployed service load a Hub model by commit hash instead of by repo name alone?

Choose one answer

Why it matters

A Hub model is a git repository. The owner can push new weights, edit the chat template or delete files on main at any time. A service that loaded org/model on Monday may load different files on Friday, and your evals no longer describe what runs.

How to do it

  1. Filter before you read names. On the models page filter by task (for example text generation), library, parameter size, language and licence. Sort by downloads for safe defaults and by trending for new releases. Repo names carry hints: -Instruct or -Chat is tuned for conversation, while a base model only continues text. Tags such as gguf or safetensors tell you the file format.
  2. Check the size against your hardware before you download. A repo can hold tens of gigabytes of shards.
  3. Handle gated models. Some owners require you to accept terms on the model page while signed in. After that, authenticate the CLI with hf auth login or set the HF_TOKEN environment variable. Without both, the download fails with a 401 or 403.
  4. Download with the CLI and pin a commit. Every repo has a commit hash on its history page.
  5. Know the cache. Downloads land in a content-addressed cache under HF_HOME and are reused across projects. HF_HUB_OFFLINE=1 makes code use only what is already cached.

Before and after

# Before: floats with whatever main points to today
model = AutoModelForCausalLM.from_pretrained("acme-labs/Orbit-8B-Instruct")
# After: pinned, only the files you need, in a folder you control
hf download acme-labs/Orbit-8B-Instruct \
  --revision 3f9c2a1e8b7d4c5a96e0b1d2c3f4a5b6c7d8e9f0 \
  --include "*.safetensors" "*.json" "tokenizer*" \
  --local-dir ./models/orbit-8b
model = AutoModelForCausalLM.from_pretrained("./models/orbit-8b")

Record the repo, commit hash and licence next to your eval results so a result can be tied to exact files.

What goes wrong

  • Unpinned loads. The model changes under a stable name, and a regression has no cause you can find.
  • Downloading everything. Without --include you may fetch several copies of the weights in different formats.
  • Mistaking base for instruct. A base model given a chat prompt rambles and looks "broken".
  • Ignoring the licence filter. Some licences limit commercial use or add conditions; find out before you build on it.

Examples

Ticket: pick a model for a 24 GB GPU

Filters: task text generation, library transformers, size under 14B, licence permissive for commercial use. Sort by downloads, open the top three cards. Choose the -Instruct variant of the one whose card lists your language, note its commit hash, then run hf download with --revision and --include "*.safetensors".

A 403 on a model that exists

hf download meta-org/Large-Chat returns 403 even though the page opens in your browser. The model is gated: accept the terms on the page while signed in, run hf auth login with a read token, and retry. A new token alone does not help if the terms were never accepted.

Key points

  • A Hub model is a git repository whose main branch can change, so pin a commit hash for anything you evaluate or ship.
  • Filter by task, size, language and licence before you compare names or download counts.
  • Gated models need both accepted terms on the model page and an authenticated token on your machine.
  • Use hf download with --revision and --include to fetch only the pinned files you need into a folder you control.
  • Record repo, commit hash and licence beside every eval result so it can be reproduced.

Common mistakes

  • Loading by repo name in production code, so the weights change without a deploy.
  • Downloading a whole repository when one file format is enough.
  • Choosing by download count alone and skipping the licence and size filters.
  • Putting an access token in a script or a repository instead of an environment variable.

Check yourself · 2 of 3

A download of a gated model returns 403 although you can open its page in the browser. What is the most likely fix?

Choose one answer

Check yourself · 3 of 3

You see two repos from the same lab: Orbit-8B and Orbit-8B-Instruct. You want a chat assistant. Which do you start with?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic