Module 22.4 ended with media vendors (Udio). Module 22.5 is where engineers find, run, and host models. Hugging Face is the default open-ML platform: Model Hub, transformers, datasets, Spaces, and Inference APIs/Endpoints. Vol. 11.5 open-source models taught families; this page teaches the distribution and inference surface you actually type into a terminal.
Peers: Replicate (Cog predictions), Together / Groq / Cerebras (fast LLM hosts), OpenRouter (gateway). SDK wrap remains Vol. 18 OpenAI SDK / FastAPI—HF Inference is often OpenAI-compatible now, but the Hub is not “an SDK.” Speech models on the Hub still follow Vol. 16 Whisper / TTS eval.
Learning Objectives
By the end of this lesson, students should be able to:
- Name the five HF surfaces: Hub, Transformers, Datasets, Spaces, Inference (serverless + dedicated endpoints).
- Load a Hub model with
transformerslocally vs call Inference API remotely. - Contrast HF vs Replicate vs Together vs self-host on qualitative price, control, and ops.
- Read model cards, licenses, and gated-repo rules before shipping weights.
- Sketch wrapping HF Inference behind FastAPI like any Vol. 18 vendor.
- Know when Spaces is a demo, not a multi-tenant product.
Hugging Face is an open machine-learning platform and company. The Model Hub hosts weights, configs, and model cards. Transformers is the Python library that loads many of those checkpoints. Datasets loads and streams training/eval corpora. Spaces hosts Gradio/Streamlit (and Docker) demos. Inference is HF’s hosted runtimes: serverless Inference API and dedicated Inference Endpoints (plus related Inference Providers). Hugging Face is not a single model and not a replacement for your product API.
Five Surfaces, One Account
Students collapse “Hugging Face” into “that chatbot.” In production you pick a surface: download weights (Hub + Transformers + your GPU), call a metered endpoint (Inference), or show a prototype (Spaces). Mixing them without intent causes surprise bills and surprise licenses.
Hub + Transformers
- You operate GPU/RAM
- Full control, license still binds
- Vol. 18.3/18.4 hardware tiers
Inference API / Endpoints
- HF or partner GPUs
- HTTP / OpenAI-compatible clients
- Scale-to-zero vs dedicated
Datasets + Spaces
- Datasets: train/eval corpora
- Spaces: public demos
- Not your SLA production API
Pricing / Strengths / Weaknesses (Qualitative)
| Dimension | Hugging Face | Replicate | Together / Groq / Cerebras | Self-host (vLLM etc.) |
|---|---|---|---|---|
| Pricing posture | Free Hub/Transformers (you pay compute); Spaces CPU/GPU tiers; Inference billed per request or dedicated instance—confirm live meters | Pay-per-prediction / GPU-second | Token-based LLM inference (hardware specialists) | Your cloud/GPU bill + eng time |
| Strengths | Largest open catalog; library + cards + community; multimodal (LLM, vision, speech); endpoints + Spaces; ecosystem gravity | Turnkey Cog models, especially image/video | High-throughput LLM serving | Data residency, custom kernels, no per-token vendor margin |
| Weaknesses | Serverless cold starts; license/gated-model footguns; Spaces ≠ prod; you still own eval; not the fastest LLM chip | Less “research Hub”; you depend on someone’s Cog | Narrower non-LLM catalog | Ops burden (Vol. 18.4) |
Python: Transformers Local vs Inference Remote
Local pipeline is for labs and Vol. 18.4 boxes. Production often uses InferenceClient or an OpenAI-compatible base URL. Pin revision hashes for reproducibility. Honor gated models’ user access tokens and licenses.
Do
- Read the model card + license before deploy
- Pin revision; log model id in traces
- Treat Spaces as prototypes
- Wrap Inference behind FastAPI + auth
Don’t
- Assume Hub weights are Apache-2.0
- Ship a public Space as the only backend
- Ignore gated-repo terms
- Confuse HF Chat UI with your SLA
Related Lectures
| Lecture | Role |
|---|---|
| Open-source models / Llama family | What weights mean |
| OpenAI SDK / FastAPI / Tier 1 API-only | How you ship calls |
| Whisper / TTS | Speech checkpoints on the Hub |
| Replicate · Together · OpenRouter | Alternative runtimes / gateways |
| Copyright | Weight + dataset licenses |
“Hugging Face is one API like OpenAI.” Hub, library, Spaces, and Inference are different SLAs. Second: downloading Llama from the Hub ignores the license/gate. Third: a viral Space is production. Fourth: Inference serverless has no cold start. Fifth: Datasets streaming means you own the corpus copyright. Sixth: Vol. 19 perplexity (metric) is the Perplexity company (last lecture in this module).
Knowledge Check
- Short Answer: Name three Hugging Face surfaces. Answer: Hub, Transformers, Datasets, Spaces, Inference (any three).
- True/False: Spaces is the recommended multi-tenant production API. Answer: False.
- Multiple Choice: Before shipping Hub weights you should: (a) read card + license + gate rules, (b) assume MIT, (c) only check likes. Answer: (a).
- Short Answer: What is the difference between Transformers local and Inference remote? Answer: Local runs on your GPU/CPU; Inference is hosted HTTP/metered runtime.
- True/False: You should invent HF Inference dollar rates from memory. Answer: False.
- Multiple Choice: Pin production checkpoints by: (a) git revision/SHA, (b) “latest,” (c) Space likes. Answer: (a).
- Short Answer: Which Vol. 18 lecture wraps vendor HTTP into your product? Answer: FastAPI (or OpenAI SDK / API lecture).
- True/False: Replicate is the same product as the Model Hub. Answer: False.
- Multiple Choice: Speech models on the Hub still need: (a) Vol. 16 WER/MOS eval, (b) no eval, (c) only Suno credits. Answer: (a).
- Short Answer: Which Vol. 11.5 lecture catalogs open weights conceptually? Answer: Open-source models (or a family lecture such as Llama).
Key Takeaways
- HF = Hub + Transformers + Datasets + Spaces + Inference—pick the surface on purpose.
- Licenses, gates, and revisions are part of the vendor decision.
- Serverless Inference ≠ dedicated Endpoint ≠ self-host.
- Wrap calls with Vol. 18; eval speech/vision with Vol. 16/19.
- Next: Replicate—Cog predictions as a productized runtime.
Lab: Students pick one Hub text model (small) and (1) run pipeline locally or on CPU, (2) sketch the same call via InferenceClient with HF_TOKEN from env, (3) paste the model card license clause. Grade: revision noted, no committed token, explicit statement whether Spaces would be allowed in prod (answer: no).
Recap: Hugging Face is the open-ML platform of record. Use the Hub to choose weights; use Inference or your GPU to run them. Next runtime: Replicate.