Short answer
You search the Hub, download a model repo, and run it with Transformers. Create a Hugging Face account when the docs require a login for private repos, gated repos, uploads, or pull requests. Public file examples in the download guide are shown without that login step.
Last verified against the sources listed below.
Key takeaways
- Install huggingface_hub for the hf command, then install Transformers when you want to run a model.
- PyPI listed transformers 5.25.1 and required Python 3.11 or newer, checked in December 2026.
- Create an account and run hf auth login for private repos, gated repos, uploads, or pull requests.
- Search with hf models ls --search, then download with hf download.
- Transformers loads a named model through pipeline or from_pretrained.
- Use hf download --dry-run when you want the file list before a large pull.
How to use Hugging Face starts on the Hub, where people publish models, datasets, and demos. The huggingface_hub package includes an hf command for search and download. This guide follows that CLI, the download guide, and the Transformers quickstart for the step that runs a model.
How to use Hugging Face models is a short loop: find a repo id, copy the files you need, then load that id in Python. The sections below keep each action separate. Nothing here guesses a model’s parameter count. If a card prints a size, read it on the model page.
What you need
You need Python 3.11 or newer, pip, and two Hugging Face packages. PyPI listed transformers 5.25.1 with a Python requirement of >=3.11.0 when this was checked in December 2026. The same page says the torch extra needs torch >=2.6.
Work inside a virtual environment so this install does not change other projects. The Python tutorial creates one with python -m venv and installs packages with python -m pip. The machine learning ideas stay the same. The new part is the Hub client.
If the language itself is new, read what Python is before you install the packages.
python -m venv .venv
source .venv/bin/activate
python -m pip install -U huggingface_hub
python -m pip install -U "transformers[torch]"
The Hub quickstart installs huggingface_hub with pip install --upgrade huggingface_hub and notes that the package ships the hf CLI. The Transformers quickstart then installs Transformers. Use the transformers repo and the PyPI page if you want the project home and the current pin.
Create an account only when you need one
Create an account when the docs say a login is required, not before every public download. The CLI guide says you must be logged in for many Hub actions, including private repos, uploads, and pull requests. It also says a token is required for private or gated repositories.
The Transformers quickstart recommends an account so you can host and access versioned models, datasets, and Spaces. That is a recommendation for the library workflow, not a line in every download example.
- Open the Hugging Face site and register if you do not already have an account.
- Create a read token in settings for downloads. Use a write token only if you will create or edit a repo.
- Run
hf auth loginand approve the browser prompt, or paste the token. - Run
hf auth whoamito see which account is active.
The Hub quickstart says the saved token lives under your HF_HOME directory, which defaults to ~/.cache/huggingface/token. You can also set the HF_TOKEN environment variable. Do not paste a token into a notebook you will share.
Search for a model
Search with hf models ls and a short query, then copy the repo id you want. The CLI guide shows hf models ls --search plus filters for author, pipeline tag, and sort order.
hf models ls --search "bert" --limit 2
hf models ls --author google --limit 5
A repo id looks like gpt2 or distilbert/distilbert-base-uncased. Those ids appear in the download guide and the Transformers quickstart. Read the model card before you load anything large. hf models card prints that card, and hf models info prints details for one id.
Pick a small public repo while you learn the commands. The download guide uses gpt2 for single-file examples. Switch to another id only after that command works on your machine.
Download the files
Download with hf download, which caches the files and prints a local path. The download guide says the command uses the same helpers as hf_hub_download and snapshot_download.
- Download one file:
hf download gpt2 config.json. - Download several named files by listing them after the repo id.
- Download a whole repo by passing only the repo id.
- Add
--dry-runwhen you want the file list and sizes before the transfer.
Do not edit files inside the cache path. The guide says that path points at the cache, and changing it can corrupt the cache. If you want a normal project folder, pass a local directory argument as the download guide describes. A later run can skip files that are already up to date.
In Python, the same one-file download looks like this:
from huggingface_hub import hf_hub_download
path = hf_hub_download(repo_id="gpt2", filename="config.json")
print(path)
The quickstart uses google/pegasus-xsum and config.json as its example. Either id is fine. The point is the pair of arguments: repo id and file name.
Load the model and run it
Load the repo with Transformers once the id is one your machine can hold. The quickstart calls pipeline the most convenient way to run inference, and it uses from_pretrained when you want the model and tokenizer objects.
The pipeline call in the quickstart takes a task name and a model id. This version uses gpt2, the public id from the download guide:
from transformers import pipeline
pipe = pipeline("text-generation", model="gpt2")
print(pipe("Hello from the Hub", max_length=20))
For the lower-level path, the quickstart imports AutoModelForCausalLM and AutoTokenizer, then calls from_pretrained with the same repo id for both. It also shows device_map="auto" and dtype="auto" so weights land on a suitable device in the stored data type. Use those arguments when you follow that section, not on every tiny test.
Pipeline downloads and caches a model for the task if you omit model. Pass model when you want the repo you just searched. If the repo is gated, log in first. The CLI guide is explicit that a token is required there.
Fix the usual failures
Match the error to the check in the docs before you change the model id. Most first runs fail on the account, the Python version, or the size of the repo.
| Symptom | What to check |
|---|---|
hf is not found |
Install huggingface_hub. The quickstart says the package ships the CLI. |
| Private or gated repo | Run hf auth login. The CLI guide requires a token for those repos. |
| Install error about Python | PyPI required Python >=3.11.0 for transformers 5.25.1. |
| Download looks huge | Run hf download REPO --dry-run and read the printed sizes. |
| Cache file changed by hand | Download again. The guide says not to edit cache files. |
If a model card says you must accept terms on the website, do that in the browser, then retry the command. That gate is separate from installing the library. Keep the repo id copied from hf models ls or from the model page so a typo does not look like a missing login.
When you only wanted the words of a card or a README, stop after hf models card. Running a full text-generation pipeline is the later step, after you know the id and the license on that card.
Frequently asked questions
Do I need a Hugging Face account to download a public model?
The download guide shows public commands, such as hf download gpt2 config.json, without a login step. The CLI guide says you must be logged in for private repos, uploads, and pull requests, and that a token is required for private or gated repositories. Create an account when you hit one of those cases. A read token is enough for downloads. Use a write token only when you create or edit a repo.
What is the difference between hf download and Transformers?
hf download copies files from a Hub repo into a local cache and prints the path. It does not run the model. Transformers is the library that defines model code and loads weights for inference or training. The quickstart shows pipeline for a task and from_pretrained when you want the model object and a tokenizer. You can download files first, or let pipeline fetch them when you pass a model id.
Where do downloaded Hugging Face files go?
The download guide says hf_hub_download caches the file and returns a path inside the Hugging Face cache, not a folder you should edit. Changing that file can corrupt the cache. If you want a normal folder layout, pass a local directory. A .cache/huggingface folder then stores metadata so later runs can skip files that are already current. You can delete that metadata folder later, but the next run may take longer.
Can I load one file instead of the whole repository?
Yes. Pass the repo id and the file name to hf download, or call hf_hub_download with repo_id and filename. The download guide uses gpt2 and config.json as the short example. Add more file names on the same command when you only need a subset. snapshot_download, or hf download with only the repo id, pulls the repository. allow_patterns and ignore_patterns can limit that pull.
Which Python version does Transformers require?
The PyPI page for transformers, checked in December 2026, listed version 5.25.1 and required Python >=3.11.0. The same page lists a torch extra that requires torch >=2.6. Install inside a virtual environment so this pin does not clash with other projects. The Python tutorial shows python -m venv for that environment, then python -m pip install for packages. Check your version with python --version before you install.
Sources
- Command Line Interface (CLI) · Hugging Face, 2026
- Hugging Face Hub quickstart · Hugging Face, 2026
- Download files from the Hub · Hugging Face, 2026
- Transformers quickstart · Hugging Face, 2026
- transformers on PyPI · Python Package Index, 2026
- Virtual Environments and Packages · Python Software Foundation, 2026
- huggingface/transformers · GitHub, 2026