The Hub

The Hugging Face Hub hosts models, datasets, and Spaces. Transformers from_pretrained / push_to_hub talk to it by default. There are 1M+ checkpoints.


Search models

Open huggingface.co/models and filter by task, framework (PyTorch), library (transformers), and language. Check downloads, likes, and whether the repo is gated.

Useful starting queries for this course:

QueryUse
distilbertSmall classification / generation
Qwen2.5-0.5B-InstructChinese / English instruct
DeepSeekCN-friendly open weights (watch size)
whisper-tinyASR experiments

Open the repo and read the model card before you copy the ID.


What to read on a model card

The card is the repo-root README.md. It usually covers:

  • License (Apache-2.0, MIT, custom, non-commercial)
  • Training data and limits (bias, languages)
  • Usage (Pipeline snippet, whether trust_remote_code is required)
  • VRAM / hardware
  • Gating: Llama-style models need a web click-through plus hf auth login

This tutorial stays on ungated IDs. If you must use Llama, finish the license flow first—do not assume every reader already accepted it.


Datasets and Spaces

  • Datasets share the load_dataset("rotten_tomatoes") namespace; pages include a preview and citation.
  • Spaces host Gradio / Streamlit / Docker demos—e.g. a public sentiment widget. Wrap pipeline in app.py. This course only teases Spaces; a full front end is out of scope.

The three link together: cards cite datasets; a Space loads your model ID.


Login and push_to_hub

hf auth login
from transformers import AutoModelForSequenceClassification, AutoTokenizer

dir_ = "./rt-distilbert-final"
model = AutoModelForSequenceClassification.from_pretrained(dir_)
tok = AutoTokenizer.from_pretrained(dir_)
repo = "YOUR_USER/rt-distilbert-demo"

model.push_to_hub(repo)
tok.push_to_hub(repo)

Trainer can also take TrainingArguments(push_to_hub=True, hub_model_id=repo) and trainer.push_to_hub(). Repos are public by default; private ones need Hub permissions.

Fill the card before you push: task, id2label, hyperparameters, scores, license. Empty READMEs are hard to trust.


Local ↔ Hub

from transformers import AutoTokenizer, AutoModelForCausalLM

# Download (cached)
m = AutoModelForCausalLM.from_pretrained(
    "distilbert/distilgpt2", device_map="auto", dtype="auto"
)
# Save locally
m.save_pretrained("./offline-distilgpt2")
AutoTokenizer.from_pretrained("distilbert/distilgpt2").save_pretrained(
    "./offline-distilgpt2"
)
# Later, fully offline:
# AutoModelForCausalLM.from_pretrained("./offline-distilgpt2")

In CI, use HF_TOKEN; never commit the token. hf download org/name pulls files without Python.


Ollama and Skills

Quantized Hub weights can feed this site’s Ollama tutorial for daily chat. Research, generate() ablations, and Spaces stay on Transformers.

Coding agents can batch-edit cards or upload datasets via Hugging Face Skills. The main path is still: you can from_pretrained and you read the card.


Next steps

评论