cheat-sheets

Hugging Face CLI and Model Formats

Download, cache and upload models with the hf CLI, and understand the file formats (GGUF, safetensors) and quantisation levels you will meet.

Project: Hugging Face Hub Documentation: hf CLI guide · GGUF

Verification: hf commands and options were checked against hf --help and subcommand help (huggingface_hub 2.2.0). Format and quantisation notes are general guidance from the docs; size estimates are rough and marked (approximate).

Install #

COMMANDDESCRIPTION
uv tool install huggingface_hubInstall the hf command (unverified: package extras may be needed)
hf updateUpdate the CLI
hf version / hf envVersion and environment info

Authenticate #

Gated models need an account token from your Hub settings.

COMMANDDESCRIPTION
hf auth loginLog in with a token or the browser
hf auth whoamiShow the current account
hf auth list / hf auth switchManage several tokens
hf auth logoutRemove a token
HF_TOKENEnvironment variable alternative; keep it out of git

Download #

COMMANDDESCRIPTION
hf download REPO_IDDownload a whole repo into the cache
hf download REPO_ID FILENAMEOne file
hf download REPO_ID --include "*Q4_K_M*.gguf"Only matching files
hf download REPO_ID --exclude "*.bin"Skip matching files
hf download REPO_ID --local-dir DIRPut files in a normal folder instead of the cache
hf download REPO_ID --revision BRANCH_OR_SHAPin a revision
hf download REPO_ID --dry-runShow what would download
hf download REPO_ID --type datasetDatasets (model, dataset, space, kernel)
bash
hf download TheOrg/Some-Model-GGUF --include "*Q4_K_M.gguf" --local-dir ./models

Cache #

Default location is ~/.cache/huggingface. Override with HF_HOME.

COMMANDDESCRIPTION
hf cache lsList cached repos
hf cache ls --sort size:descLargest first
hf cache rm model/OWNER/NAMEDelete a cached repo (frees disk, cannot be undone)
hf cache pruneRemove detached revisions and incomplete downloads
hf cache verify REPO_IDCheck checksums

Browse and Upload #

COMMANDDESCRIPTION
hf models lsList models on the Hub (see --help for filters)
hf models info REPO_IDModel details
hf models card REPO_IDShow the model card
hf repos create REPO_IDCreate a repo
hf upload REPO_ID LOCAL_PATH [PATH_IN_REPO]Upload a file or folder (re-run to resume)
hf upload REPO_ID . . --privateUpload the current folder, creating a private repo
hf repos delete REPO_IDDelete a repo (destructive)

Formats #

FORMATNOTES
safetensorsSafe tensor storage (no code execution); the standard for original Hugging Face weights, used with Transformers, vLLM
GGUFSingle-file format for llama.cpp, Ollama and LM Studio; carries metadata and quantised weights
PyTorch .bin / .ptPickle-based; can run code on load, so avoid untrusted files
ONNX, MLXOther runtimes (ONNX Runtime, Apple MLX)

Quantisation #

Quantisation stores weights in fewer bits to cut memory and disk at some quality cost. In GGUF the names encode the bits per weight.

NAMEMEANING
F16 / BF16Unquantised half precision; about 2 bytes per parameter
Q8_08-bit; near-lossless, about 1 byte per parameter
Q6_K, Q5_K_MHigher quality mid-size options
Q4_K_MCommon default balance of size and quality; about 0.5 to 0.6 bytes per parameter (approximate)
Q3_K, Q2_KSmall but noticeably worse
IQ variantsImportance-matrix quants, better quality at low bits

Rough memory: parameters (in billions) × bytes per parameter, plus several GB for context (KV cache) and overhead (approximate). A 7B model at Q4_K_M is around 4 to 5 GB. If it does not fit in VRAM, layers spill to CPU and speed drops sharply. See llama.cpp for -ngl and llama-quantize.

See Also #

Search all sheets

Tip: / or Ctrl/Cmd+K to open, Esc to close.