HuggingFace CLI
Execute Hugging Face Hub operations using the hf CLI for downloading models/datasets, uploading files, managing repositories, cache, and cloud compute.
Prerequisites
- •HuggingFace CLI installed:
pip install huggingface_hub - •HF account and token for authenticated operations
- •
hf auth logincompleted
Instructions
- •
Authentication
bashhf auth login # Interactive login hf auth login --token $HF_TOKEN # Non-interactive hf auth whoami # Check current user
- •
Download models and datasets
bashhf download <repo_id> # Full repo to cache hf download <repo_id> --local-dir ./models # To local directory hf download <repo_id> --include "*.safetensors" # Filter by pattern hf download <repo_id> --repo-type dataset # Dataset
- •
Upload files
bashhf upload <repo_id> . . # Current dir to root hf upload <repo_id> ./models /weights # Folder to path hf upload <repo_id> . . --repo-type dataset # Dataset hf upload <repo_id> . . --create-pr # Create PR
- •
Repository management
bashhf repo create <name> # Create model repo hf repo create <name> --repo-type dataset # Create dataset hf repo create <name> --private # Private repo hf repo delete <repo_id> # Delete repo hf repo tag create <repo_id> v1.0 # Create tag
- •
Cache management
bashhf cache ls # List cached repos hf cache rm model/gpt2 # Remove cached repo hf cache prune # Remove detached revisions
- •
Browse Hub
bashhf models ls # List trending models hf models ls --search "llama" --limit 20 # Search models hf datasets ls # List datasets hf spaces ls # List spaces
- •
Cloud compute (Jobs)
bashhf jobs run python:3.12 python script.py # Run on CPU hf jobs run --flavor a10g-small <image> <cmd> # Run on GPU hf jobs ps # List jobs hf jobs logs <job_id> # View logs
Error Handling
- •If authentication fails, run
hf auth loginagain - •For permission errors, check token scope
- •For large uploads, use
hf upload-large-folder
Notes
- •Key options:
--repo-type(model/dataset/space),--revision,--quiet - •GPU flavors: cpu-basic, t4-small, a10g-small, a100-large, h100
- •Use
--quietfor scripts to get only paths/URLs
Source: huggingface/skills