| name | huggingface |
| description | Browse, download, and deploy models, datasets, and spaces on HuggingFace Hub |
| version | 1.0.0 |
| author | kai-agent |
| metadata | {"kai":{"tags":["kai","compute","huggingface","models","datasets","inference","ml"]}} |
HuggingFace Hub
Skill for browsing, downloading, uploading, and running inference on models, datasets,
and spaces from HuggingFace.
Authentication
This skill uses the HF_TOKEN environment variable. If it is not set, ask your admin
to add it in Agent Settings. You can generate a token at https://huggingface.co/settings/tokens.
Some operations (public model browsing, public dataset loading) work without a token,
but gated models, private repos, and uploads always require one.
Install the Hub library
pip install huggingface-hub transformers datasets
Browsing and searching models
Search by task
from huggingface_hub import HfApi
api = HfApi()
models = api.list_models(
task="text-generation",
sort="downloads",
direction=-1,
limit=10,
)
for m in models:
print(f"{m.id} downloads={m.downloads}")
Search by name or keyword
models = api.list_models(search="llama", sort="downloads", direction=-1, limit=5)
Filter by library (vLLM, TGI, ONNX, etc.)
models = api.list_models(
task="text-generation",
library="vllm",
sort="downloads",
direction=-1,
limit=10,
)
This is particularly useful for inference optimization: filter by vllm or text-generation-inference
to find models already packaged for fast serving.
Reading model cards
from huggingface_hub import ModelCard
card = ModelCard.load("meta-llama/Llama-3.1-8B-Instruct")
print(card.text)
print(card.data.tags)
print(card.data.license)
Downloading models
Download a single file
from huggingface_hub import hf_hub_download
path = hf_hub_download(
repo_id="meta-llama/Llama-3.1-8B-Instruct",
filename="config.json",
)
print(path)
Download an entire model snapshot
from huggingface_hub import snapshot_download
local_dir = snapshot_download(
repo_id="meta-llama/Llama-3.1-8B-Instruct",
local_dir="./llama-3.1-8b",
ignore_patterns=["*.md", "*.txt"],
)
Download quantized / optimized variants
For inference optimization, look for GGUF, AWQ, or GPTQ variants:
models = api.list_models(search="Llama-3.1-8B AWQ", sort="downloads", direction=-1, limit=5)
Uploading models
api.upload_folder(
folder_path="./my-fine-tuned-model",
repo_id="your-org/my-model",
repo_type="model",
commit_message="Upload fine-tuned checkpoint",
)
Datasets
Search datasets
datasets = api.list_datasets(search="code", sort="downloads", direction=-1, limit=10)
Load a dataset
from datasets import load_dataset
ds = load_dataset("openai/gsm8k", split="train")
print(ds[0])
Stream large datasets without downloading
ds = load_dataset("allenai/c4", split="train", streaming=True)
for example in ds:
print(example["text"][:200])
break
Inference API
Serverless inference (no GPU required)
from huggingface_hub import InferenceClient
client = InferenceClient(model="meta-llama/Llama-3.1-8B-Instruct")
response = client.text_generation(
"Explain quantization in 3 sentences:",
max_new_tokens=200,
temperature=0.7,
)
print(response)
Chat-style inference
response = client.chat_completion(
messages=[{"role": "user", "content": "What is KV-cache quantization?"}],
max_tokens=500,
)
print(response.choices[0].message.content)
Embeddings
embeddings = client.feature_extraction("Inference optimization for LLMs")
print(len(embeddings[0]))
Spaces
Create a Space
api.create_repo(
repo_id="your-org/my-demo",
repo_type="space",
space_sdk="gradio",
)
Upload files to a Space
api.upload_folder(
folder_path="./my-space-app",
repo_id="your-org/my-demo",
repo_type="space",
)
Duplicate an existing Space
api.duplicate_space("stabilityai/stable-diffusion", to_id="your-org/sd-copy")
Inference optimization tips
- Check quantized variants first: Search for AWQ/GPTQ/GGUF versions before downloading full-precision weights.
- Use
library filter: Filter by vllm or text-generation-inference for deployment-ready models.
- Check model size vs. your GPU memory: Read the model card for memory requirements.
- Use streaming for large datasets: Avoid downloading multi-TB datasets to disk.
- Cache management: Models are cached in
~/.cache/huggingface/. Use huggingface-cli scan-cache to inspect and huggingface-cli delete-cache to free space.
Rules
- ALWAYS check if a gated model requires access before attempting download (e.g., Llama models require accepting a license)
- Prefer quantized models when the use case is inference, not training
- Use
ignore_patterns to skip downloading unnecessary files (READMEs, training configs)
- Set
HF_HOME if you want to customize the cache directory
- Never commit tokens to code: rely on
HF_TOKEN environment variable