| name | huggingface-hub |
| description | HuggingFace Hub — download models/datasets, upload artifacts, search, and manage tokens via CLI and Python API. |
| version | 1.0.0 |
| author | hermes-CCC (ported from Hermes Agent by NousResearch) |
| license | MIT |
| metadata | {"hermes":{"tags":["MLOps","HuggingFace","Models","Datasets","Hub","Download","Upload"],"related_skills":["grpo-rl-training"]}} |
HuggingFace Hub
Download models and datasets, upload artifacts, and manage your Hub presence via CLI and Python API.
Setup
pip install huggingface_hub datasets transformers
huggingface-cli login
Or set env var:
export HF_TOKEN=hf_...
Download Models
huggingface-cli download meta-llama/Llama-3.1-8B-Instruct
huggingface-cli download Qwen/Qwen2.5-7B-Instruct --local-dir ./models/qwen
huggingface-cli download microsoft/phi-4 config.json
huggingface-cli download bartowski/Llama-3.1-8B-Instruct-GGUF \
Llama-3.1-8B-Instruct-Q4_K_M.gguf --local-dir ./models/
Python API:
from huggingface_hub import snapshot_download, hf_hub_download
snapshot_download("meta-llama/Llama-3.1-8B-Instruct", local_dir="./models/llama")
hf_hub_download("meta-llama/Llama-3.1-8B-Instruct", "config.json", local_dir="./")
Download Datasets
huggingface-cli download --repo-type dataset HuggingFaceH4/ultrachat_200k
from datasets import load_dataset
dataset = load_dataset("HuggingFaceH4/ultrachat_200k")
dataset["train_sft"].to_json("./data/train.jsonl")
Upload Models
huggingface-cli upload your-username/my-model ./local-model-dir
huggingface-cli upload your-username/my-model ./model.safetensors
huggingface-cli repo create my-new-model --type model
Python API:
from huggingface_hub import HfApi
api = HfApi()
api.upload_folder(
folder_path="./fine-tuned-model",
repo_id="your-username/my-fine-tuned-model",
repo_type="model",
)
Search Models
huggingface-cli search models --filter task=text-generation --filter language=ko
from huggingface_hub import list_models
models = list_models(
task="text-generation",
language="ko",
sort="downloads",
limit=10,
)
for m in models:
print(m.id, m.downloads)
Cache Management
huggingface-cli cache info
huggingface-cli cache scan
huggingface-cli cache evict --model meta-llama/Llama-3.1-8B-Instruct
echo ~/.cache/huggingface/hub/
Custom cache dir:
export HF_HOME=/path/to/custom/cache
Model Cards
python -c "from huggingface_hub import ModelCard; print(ModelCard.load('Qwen/Qwen2.5-7B-Instruct'))"
Spaces
huggingface-cli upload your-username/my-space ./app --repo-type space
huggingface-cli space info your-username/my-space
Token Management
huggingface-cli whoami
huggingface-cli token list
huggingface-cli token revoke TOKEN_NAME
Gated Models (Llama, Gemma, etc.)
- Go to hf.co/model-card and accept terms
- Use a token with read access:
huggingface-cli login
- Download normally — gate is checked server-side
from huggingface_hub import model_info
info = model_info("meta-llama/Llama-3.1-8B-Instruct")
print(info.gated)