How to Use Hugging Face Models: Download, Run, Deploy
How to use Hugging Face models in practice: download with the hf CLI, run with transformers, handle gated licences, size for your hardware and serve in production.
By AI Model Hub Desk · 29 November 2026
To use a Hugging Face model, install huggingface_hub and transformers, download the weights with hf download (or let transformers fetch them), and run them with pipeline(). For production, serve the same weights behind an OpenAI-compatible API with vLLM or llama.cpp, or skip the GPUs and call the model through Hugging Face Inference Providers.
Key takeaways
- The CLI is now
hf:hf auth login,hf download,hf cache ls. Older guides that usehuggingface-cliare out of date. pipeline()in transformers is the fastest way to try a model in Python.- Check the licence and gating on the model card before you download, not after you ship.
- Memory needed is roughly parameters × bytes per parameter, plus room for context.
- Text Generation Inference (TGI) is in maintenance mode. Hugging Face itself recommends vLLM, SGLang, llama.cpp or MLX for new deployments.
Versions checked on 1 December 2026: transformers 5.24.1, huggingface_hub 2.5.0, vllm 0.34.0 (all from PyPI) and llama.cpp v1.1.0.
What libraries do I need to use Hugging Face models?
| Library | What it does | Install |
|---|---|---|
| huggingface_hub | hf CLI, downloads, login, Inference Providers client | pip install -U "huggingface_hub" |
| transformers | Loads and runs models in Python (needs Python 3.11+) | pip install -U transformers |
| PyTorch | The compute backend transformers runs on | Pick the build for your GPU at pytorch.org |
| accelerate | device_map="auto" placement across GPUs and CPU | pip install -U accelerate |
| vLLM | High-throughput GPU server | uv pip install vllm --torch-backend=auto |
| llama.cpp | CPU, Apple silicon and GPU inference for GGUF files | Installer from llama.app or the releases page |
You only need the first two to get started. Hugging Face also ships a standalone hf installer (curl -LsSf https://hf.co/cli/install.sh | bash) if you want the CLI without Python.
How do I download a model from Hugging Face?
Log in once, then download. Login is required for gated models.
hf auth login # paste a token from hf.co/settings/tokens
hf download Qwen/Qwen3-0.6B # whole repo into the local cache
hf download Qwen/Qwen3-0.6B config.json # one file
hf download Qwen/Qwen3-0.6B --include "*.safetensors" --local-dir ./qwen3
hf download Qwen/Qwen3-0.6B --dry-run # list files and sizes first
hf cache ls # see what is cached
Each command prints the local path on its last line. By default files go into the shared cache under HF_HOME, so transformers and vLLM find them without a second download.
In Python, the same thing looks like this:
from huggingface_hub import hf_hub_download, snapshot_download
config_path = hf_hub_download(repo_id="Qwen/Qwen3-0.6B", filename="config.json")
repo_path = snapshot_download(repo_id="Qwen/Qwen3-0.6B", allow_patterns=["*.json", "*.safetensors"])
print(config_path, repo_path)
Pin a revision (a tag, branch or full commit hash) in production so an upstream update cannot change your model under you.
How do I run a Hugging Face model in Python?
pipeline() handles the tokenizer, the chat template and device placement. This is the chat example from the transformers docs:
from transformers import pipeline
chat = [
{"role": "system", "content": "You are a helpful science assistant."},
{"role": "user", "content": "Hey, can you explain gravity to me?"},
]
pipe = pipeline(task="text-generation", model="HuggingFaceTB/SmolLM2-1.7B-Instruct", dtype="auto", device_map="auto")
response = pipe(chat, max_new_tokens=512)
print(response[0]["generated_text"][-1]["content"])
dtype="auto" matters. The docs note that transformers loads models in full float32 by default, which for an 8B model needs about 32 GB. With "auto" it uses the precision the model was trained in, usually bfloat16. To continue the chat, append the reply and a new user message to response[0]["generated_text"] and call the pipeline again.
The same pipeline() call works for other tasks: automatic-speech-recognition, image-classification, image-text-to-text and more.
What about licences and gated models?
Every model card shows a licence tag. They vary a lot: Qwen/Qwen3-0.6B is Apache-2.0, while meta-llama/Llama-3.2-1B-Instruct uses the Llama 3.2 licence and is gated.
For a gated model you:
- Open the model page while logged in and accept the terms. This shares your username and email with the authors unless they opted out.
- Wait for approval. Some repos approve automatically, others review by hand.
- Authenticate your script with
hf auth login, anHF_TOKENenvironment variable, or atoken=argument.
Authors can revoke access at any time, so mirror approved weights you depend on in production, if the licence allows it.
How do I choose a model size for my hardware?
Weights alone take about parameters × bytes per parameter. Leave headroom on top for the KV cache, which grows with context length and concurrent users.
| Model size | bf16 (2 bytes) | 8-bit (1 byte) | 4-bit (~0.5 byte) | Typical fit |
|---|---|---|---|---|
| 1B | ~2 GB | ~1 GB | ~0.5 GB | Laptop CPU, phone |
| 8B | ~16 GB | ~8 GB | ~4 GB | One consumer GPU, Apple silicon |
| 32B | ~64 GB | ~32 GB | ~16 GB | Workstation GPU or a big-memory Mac |
| 70B | ~140 GB | ~70 GB | ~35 GB | Multi-GPU server |
These are weight sizes only, not measured runs. Mixture-of-experts models still need memory for all their weights, even though only some are active per token. Quantised GGUF files for llama.cpp are often the easiest way to fit a model onto smaller machines.
How can I deploy a Hugging Face model in production?
Pick by where you want the GPUs to live.
-
vLLM on your own GPUs. One command starts an OpenAI-compatible server on port 8000 that pulls the model from the Hub:
vllm serve Qwen/Qwen2.5-1.5B-Instruct curl http://localhost:8000/v1/completions -H "Content-Type: application/json" \ -d '{"model": "Qwen/Qwen2.5-1.5B-Instruct", "prompt": "San Francisco is a", "max_tokens": 7}' -
llama.cpp for CPUs, Macs and small GPUs. Its commands are now
llama cliandllama serve. The server's default port is 9931, so set one explicitly:llama serve -hf ggml-org/Qwen3.5-0.8B-GGUF --port 8080 -
Inference Providers when you want no servers at all. One Hugging Face token reaches models hosted by partner providers through an OpenAI-compatible router, billed at the provider's price. Hugging Face says routing is powered by OpenRouter. Add
:fastestor:cheapestto the model id to choose the routing policy:import os from openai import OpenAI client = OpenAI(base_url="https://router.huggingface.co/v1", api_key=os.environ["HF_TOKEN"]) completion = client.chat.completions.create( model="deepseek-ai/DeepSeek-V4.1-Flash:fastest", messages=[{"role": "user", "content": "How many 'G's in 'huggingface'?"}], ) print(completion.choices[0].message.content) -
Inference Endpoints when you want dedicated hardware that Hugging Face manages for you.
What about TGI? Its documentation now says it is in maintenance mode, taking only minor fixes, and points new users to vLLM, SGLang, llama.cpp or MLX. Existing TGI deployments keep working, but do not start new ones on it.
Production checklist
- Pin the model
revisionand the server version. - Read the licence and record it next to the deployment.
- Load test with your real context lengths, not short prompts.
- Keep
HF_TOKENin a secret store, never in the image. - Run your own eval set before and after every model swap.
Sources
About the author
AI Model Hub Desk, Editors
The editors of AI Model Hub. We cover new models for the people who build with them.
Connecting services
4 Open models GuideDeepSeek API pricing: Flash vs V4 Pro, peak vs off-peak
DeepSeek API pricing for December 2026: what deepseek-flash and deepseek-v4-pro cost, how cache hits and off-peak hours cut the bill, and how it compares to OpenAI.
1 News NewsNew AI models: every major release of November 2026
New AI models from November 2026 for builders: GPT-6.2, Claude Fable 5.2, Gemini 4 Hydrogen and Neon, Qwen4-Max, Muse Ember, plus open weights from Kimi and Inkling.
5 Guides GuideOpenAI API pricing explained, with a worked example
OpenAI API pricing in plain numbers: what each model costs per million tokens, how caching, Batch and Fast change the bill, and how to watch spend live.
3 Comparisons StoryAI model pricing comparison: GPT, Claude, Gemini, DeepSeek
An AI model pricing comparison built on one real job: what 10,000 requests cost on OpenAI, Anthropic Claude, Google Gemini and DeepSeek, from official price lists.