AI and ML Bootcamp · Lecture 23 · lecture notes
Hugging Face End-to-End
In short — What is Hugging Face and what does it offer? It is the GitHub of AI: a hub of models, datasets and spaces, plus the libraries and deployment options to use them. The lecture also covers loop engineering (slash loop and slash goal) and a basic way to eval an agent.
What Hugging Face is
Hugging Face is the GitHub of AI. Everything AI related lives there: models, datasets, and ways to deploy or serve apps.
- The Hub - Models, Datasets, Spaces (plus trending sections like GitHub)
- Libraries - transformers, peft, trl, datasets, diffusers, smolagents, Trackio
- Deployments - serverless inference providers, Spaces
Companies post under their own org (e.g. Z.ai), like an org on GitHub. A model is a repository.
Models on the Hub
Almost 3 million models, filterable by task (text generation, image-to-text, text-to-image...), size, library, local apps and inference provider.
- Files and versions - license, readme, chat template, config
- Safetensors files -> the model weights (many shards, several GB each)
- Posting a model means pushing all these files
- Running locally means downloading all weights, then serving with vLLM or similar
- Closed-source labs do not publish weights; open ones (e.g. GPT-OSS, GLM, Qwen) do
- Model page shows downloads, likes, parameter count, tensor types (BF16 etc.)
- Model tree - base model, finetunes, adapters, quantizations of it
- Community tab - best practices and tips
- Inference widget - chat with the model in the browser
Small models (e.g. Qwen3 0.6B, Z-Image text-to-image) run locally or fast. A small image model made a picture in about 2.8 seconds, though with artifacts like two headlights.
Ways to use a model
| Way | How |
|---|---|
| transformers library | pipeline (simple) or AutoTokenizer + AutoModel (lower level) |
| Inference provider | Pay a host (Groq, Together, Fireworks, Cerebras, SambaNova...) via HF router |
| Local runtime | Download weights, serve with vLLM, SGLang, Ollama etc. |
| diffusers | Image and video generation models |
| transformers.js | Tiny models directly in the browser |
- Inference router is OpenAI compatible -> swap the base URL and token in the OpenAI SDK, use any HF model
- pipeline - give task/model and messages, done
- AutoTokenizer + AutoModel - control tokenization, device (CPU, GPU, MPS), number of outputs
- Thinking models (Qwen3) emit think tags before the final answer
from transformers import pipeline
clf = pipeline('sentiment-analysis')
print(clf('Hugging Face makes this easy'))!
No GPU? Use small models, free Colab/Kaggle GPUs, or HF Pro (~$7/month, limited GPU hours).
Datasets
- Data for training or evaluating, across modalities (text, audio, images, 3D, robotics sensor data)
- Sizes from 1,000 rows to over 1 trillion rows
- Formats - JSON, CSV, Parquet, Arrow, images, audio, text
- Load with the datasets library: install, give the dataset name, it downloads
- Example: WikiText - scraped Wikipedia, usable to train a small model
- Model interaction logs can be used to distill style into a small model, but only partly
- You can publish your own models and datasets, public or private, with team access
Spaces
- Spaces -> web apps hosted on Hugging Face, built on models/datasets
- Used for demos; labs put a Space up when they launch a model
- Create: New Space -> name, license, SDK (Docker or Gradio) -> hardware -> add app.py
- app.py handles input and passes it to the model
- Gradio - build ML app front ends from Python, no JavaScript or CSS (Blocks, ChatInterface)
- ZeroGPU use has quotas; beyond it you pay
- Image generation demo: diffusion starts from noise and refines over steps (e.g. 28)
import gradio as gr
def chat(message, history):
return 'reply from model'
gr.ChatInterface(chat).launch()Other Hugging Face tools
- smolagents - open-source agent library, tool calling, Hub integration
- Trackio - lightweight experiment tracking, open source, a free alternative to Weights & Biases
- Tracking shows training loss, logs and artifacts so you can spot problems like exploding normalization
- peft and trl for post-training; sentence-transformers for embeddings; diffusers for image models
- LeRobot - open-source robotics
- Blogs from HF maintainers and community are worth reading
Loop engineering
- Loop - agent repeats a task with a defined goal and a done condition
- /loop - runs a prompt on an interval (e.g. ping a site every minute) via a cron job during the session
- /schedule - dedicated tasks that persist beyond the session
- /goal - keeps iterating until a condition is met (e.g. all tests pass, zero lint errors)
- Example use: after building a v0 agent, loop mini-batch experiments across models, escalate promising ones to bigger batches, log decisions
- Reusable workflows can be written in files and pointed to from /loop
Evaluating an agent
Process
- Decide which existing agents to evaluate against (Pi, Claude Code, Codex, Amp...)
- Specialised agent -> eval mainly on its domain, plus common tasks
- Build a dedicated task list (~50 tasks) or use benchmarks like Terminal-Bench, SWE-bench Verified
- Run all tasks, record pass or fail and why
- Fix failures, rerun, climb the benchmark
- Simple code is enough; skills can automate eval
How startups ship and agent harness choices
- Product flow: small engineering test -> check fit with product -> v0 -> benchmark, benchmark, climb
- Hot areas: harness design, agent orchestration, long-running sessions and memory freshness
- Portfolio idea: a system handling long-horizon memory well, or a minimal, customizable harness (like Pi)
- Model-agnostic harnesses -> Pi, OpenCode, Factory, Amp; model-tied -> Claude Code, Codex
- Pi is an agent library; a Clawbot-style agent is a persistent agent living on a machine or server
- Post-training gains come mostly from data, model size and RL environments, and many RL environment startups exist
Glossary
- Hub
- Hugging Face platform hosting models, datasets and spaces.
- Space
- A web app hosted on Hugging Face, often a model demo.
- Safetensors
- File format storing model weights.
- Inference provider
- Company that hosts a model and serves it through an API.
- pipeline
- High-level transformers function that runs a task in a few lines.
- Gradio
- Python library for building ML app front ends without JavaScript.
- Trackio
- Hugging Face's lightweight experiment tracking library.
- smolagents
- Hugging Face's open-source agent library.
- /goal
- Coding agent command that iterates until a stated condition is met.
- /loop
- Coding agent command that repeats a prompt on an interval.