Huggingface

From ericrisco/rsc-harness · View interactive version

Huggingface is an AI agent skill from the GitHub repository ericrisco/rsc-harness. Use when running open models or working on the Hugging Face platform — the Inference Providers router or InferenceClient, Hub repos via the hf CLI, a dedicated Inference Endpoint with scale-to-zero, a Gradio Space with ZeroGPU, picking an open model by task/license/size, or loading one locally with

How to use this skill

Skill file

Hugging Face: Hub, routed/hosted inference, and transformers

Hugging Face is three surfaces, and you should always know which one you are on:

  1. The Hub — versioned git repos for models, datasets, and Spaces. You search it, you

hf download / hf upload, you read and write model cards.

  1. Inference — three ways to actually run a model: the Inference Providers router

(serverless, you own nothing), a dedicated Inference Endpoint (you own a deployment

that autoscales), or local transformers (you own the machine).

  1. The catalog — 1M+ open models you choose from by task, license, and size.

The whole skill is choosing the right surface for the job and proving it works: a 200 router

response, a live endpoint URL, a pushed repo commit. If the model is open and the workflow

lives on huggingface.co, you are in the right place. Operating the GPU box yourself is

CODE0 (your machine) or CODE1

(a rented box); training weights is CODE0.

Decision: how should I run this model?

Pick the row before you write a line of code. The cheapest mistake is standing up infra you

did not need.

| Situation | Use | Why |

|---|---|---|

| Try a model now, low/dev volume, own no infra | Inference Providers router (InferenceClient) | Fastest path; pay-as-you-go (PRO includes monthly credits, Free has none). |

| CPU task: embeddings, text-ranking, text-classification, small BERT/GPT-2 | provider="hf-inference" | That is exactly its remaining niche as of July 2025. |

| Big LLM (8B, 70B, 405B) through HF | router with a partner provider (Together/Fireworks/Cerebras/DeepInfra…) | hf-inference does not serve big LLMs — it will 404 or stall. |

| Steady prod traffic, need fixed latency/SLA | dedicated Inference Endpoint + scale-to-zero | Predictable, autoscaling, billed per minute. |

| Interactive demo or shareable GPU app | Space (Gradio + ZeroGPU) | Free-ish, public URL, GPU only while a call runs. |

| One-off GPU job (eval, batch convert) | hf jobs run | No standing infra; PRO feature. |

| Offline, data-private, or already on a GPU box | local transformers pipeline() | No network, no per-call cost. |

Auth & install

pip install huggingface_hub               # 2.4.0; needs Python >=3.10
pip install transformers                    # 5.x line, PyTorch-first, optional/local
hf auth login                               # stores a token; or export HF_TOKEN=...

hf upload, hf repos create, hf jobs run). huggingface_hub 2.0 removed the

huggingface-cli entry point and the singular hf repo group — scripts that call them fail.

from the environment instead:

import os
from huggingface_hub import InferenceClient
client = InferenceClient(api_key=os.environ["HF_TOKEN"])   # never api_key="hf_xxx"

fine-grained to scope to specific repos/orgs — why: a leaked read token cannot overwrite

your models.

Inference Providers — the default path

One router reaches 200+ models across partner providers plus hf-inference; HF passes provider

cost through with no markup. Two equivalent entry points:

# Native client — task methods, NOT the removed .post()
from huggingface_hub import InferenceClient
client = InferenceClient(api_key=os.environ["HF_TOKEN"])
out = client.chat.completions.create(
    model="meta-llama/Llama-3.1-8B-Instruct",
    messages=[{"role": "user", "content": "One sentence on diffusion models."}],
    provider="together",          # name a partner; or omit for auto-routing
)
print(out.choices[0].message.content)
# OpenAI-compatible — same router, drop-in for existing OpenAI code
from openai import OpenAI
client = OpenAI(
    base_url="https://router.huggingface.co/v1",   # this exact host, nothing else
    api_key=os.environ["HF_TOKEN"],
)

chat.completions.create(), text_generation(), feature_extraction() (embeddings),

text_to_image(), automatic_speech_recognition().

Team/Enterprise $2.00 per seat (shared). Past that you are pay-as-you-go and must buy credits. Budget accordingly — why: a

chat loop on a 70B model burns the free tier in minutes.

not apply). For org billing, pass bill_to="org-name" (header X-HF-Bill-To).

in references/inference-providers.md.

Hub ops

hf download meta-llama/Llama-3.1-8B-Instruct --include "*.safetensors"
hf repos create my-org/my-model --repo-type model
hf upload my-org/my-model ./out --commit-message "v1 weights"
from huggingface_hub import snapshot_download
path = snapshot_download("BAAI/bge-small-en-v1.5")   # full repo, cached, resumable

then a token with read access — otherwise the download 403s.

base_model). Ship one on every upload — why: an uncarded repo is unsearchable and unusable by

anyone but you. Command map and hf jobs run details in references/hub-and-cli.md.

Choosing a model

Filter the Hub by task + license + size + recent downloads, then read the card before you

commit. Match the model to your constraint; do not grab whatever is trending.

are gated; "non-commercial"/"research-only" cards mean you cannot ship them.

the usable one.

Dedicated Inference Endpoints — when to graduate

Move off the router when you need fixed latency/SLA, or the router's PAYG cost stops being

predictable. An Endpoint is your own autoscaling deployment.

billed per minute even though shown hourly.

next request. A bursty 100–1000 req/day workload typically lands at $20–60/mo.

cost worksheet are in references/endpoints-and-spaces.md.

Spaces + ZeroGPU

A Space hosts a demo app with a public URL. ZeroGPU grabs half an NVIDIA RTX Pro 6000 Blackwell (48GB; size="xlarge" for the full 96GB at 2x quota) only

while a decorated function runs, then releases it.

import spaces
@spaces.GPU                       # GPU acquired for this call only
def generate(prompt: str) -> str:
    ...

gives 8x daily quota, queue priority, and up to 10 owned ZeroGPU Spaces. Details in

references/endpoints-and-spaces.md.

Local transformers

from transformers import pipeline
pipe = pipeline("text-generation", model="meta-llama/Llama-3.1-8B-Instruct",
                device_map="auto", dtype="auto")
print(pipe("Hello", max_new_tokens=64)[0]["generated_text"])

you need control over generation/quantization. Set device_map/dtype explicitly (torch_dtype is deprecated).

router is far less ops than babysitting CUDA and weights.

Anti-patterns

| Anti-pattern | Why it bites | Do instead |

|---|---|---|

| InferenceClient.post(...) | Removed in hub v0.31.0; raises | Task methods: chat.completions.create(), feature_extraction() |

| provider="hf-inference" for a 70B/405B LLM | CPU niche; 404s or stalls | Route to a partner provider (Together/Fireworks/Cerebras) |

| api_key="hf_abc123..." in code | Token leaks in git history | Read os.environ["HF_TOKEN"] |

| Spin up a dedicated Endpoint just to try a model | Burns money idle | Use the router first; graduate only on real traffic |

| Assuming router calls are free/unlimited | Free accounts get no monthly credits; PRO $2/mo | Budget credits; expect PAYG |

| ZeroGPU under Streamlit/Docker SDK | Unsupported, silently no GPU | Use the Gradio SDK |

| huggingface-cli ... / hf repo ... in scripts | Removed in huggingface_hub 2.0; the command fails | Use hf ... / hf repos ... |

| OpenAI base URL other than https://router.huggingface.co/v1 | Won't reach the HF router | Use that exact host |

verify.sh

scripts/verify.sh [TARGET] is a static, read-only linter (no network, no token). It flags the

hard violations above — .post(, hardcoded hf_ tokens, big-LLM-to-hf-inference, wrong router

host, the removed huggingface-cli. It exits 0 on a clean or empty target.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.