Practice: Share your work on the Hub
Self-check
Section titled “Self-check”Seven short questions. Answer each before opening the collapsible.
1. Why do you need to authenticate before uploading, and how do you do it in a notebook?
Show answer
Uploading writes to your account, so the library needs a token proving who you are and which namespaces you can write to. In a notebook you call notebook_login() from huggingface_hub (in a terminal, hf auth login), paste a token from your account settings, and it is cached for later uploads.
2. What is the easiest way to upload a model you fine-tuned with the Trainer?
Show answer
Set push_to_hub=True in TrainingArguments. The Trainer then uploads to a repo in your namespace each time it saves, and a final trainer.push_to_hub() pushes the last version and generates a starter model card with the hyperparameters and evaluation results.
3. You push a model with model.push_to_hub("my-model"). Why is that not enough on its own?
Show answer
A model without its tokenizer is unusable: the next person needs the exact same text-to-numbers conversion you trained with. You must also run tokenizer.push_to_hub("my-model") so both sets of files live in the repo. Always push the tokenizer with the model.
4. What are the three routes for getting files onto the Hub, and how do they differ?
Show answer
The push_to_hub API (easiest, on the Trainer or directly on model/tokenizer objects), the huggingface_hub Python library (create_repo, upload_file, for programmatic repo management), and git plus git-lfs (the barebones path). They trade convenience for control; for almost all work the push_to_hub API is the right choice.
5. What does a usable model repository contain, and why exactly those files?
Show answer
A config.json (architecture and settings), the weights (a large file tracked by git-lfs), and the tokenizer files (vocabulary, tokenizer_config.json, special-tokens map). That is precisely the set from_pretrained looks for, which is why one line can load the model.
6. Why does the Hub use git-lfs and not plain git for some files?
Show answer
Model weight files are large (often hundreds of MB or more), and plain git handles large binaries poorly. git-lfs (Git Large File Storage) tracks the big files separately, while small text files like config and tokenizer JSON go through normal git. The higher-level tools do this split for you automatically.
7. What is a model card, and why is it called the real deliverable?
Show answer
The model card is the README.md at the root of the repo, in Markdown, documenting what the model does, what data it was trained on, its strengths and limitations, and how to use it. Without it, a repo of weights is nearly useless to anyone else. A good card is the difference between a model others adopt and a pile of weights nobody touches.
Try it yourself: push a model and write its card
Section titled “Try it yourself: push a model and write its card”About 10 minutes (you need a free Hugging Face account). You will publish a real, loadable model.
Part A: authenticate and push. In a notebook:
from huggingface_hub import notebook_loginnotebook_login() # paste a token from your account settings
from transformers import AutoModelForSequenceClassification, AutoTokenizercheckpoint = "bert-base-cased"model = AutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=2)tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model.push_to_hub("my-first-shared-model")tokenizer.push_to_hub("my-first-shared-model")Then visit huggingface.co/your-username/my-first-shared-model and open the “Files and versions” tab.
What you should see, and why
A new repo with config.json, a weights file (the large one, tracked by git-lfs), and the tokenizer files. Because that is exactly the file set from_pretrained expects, anyone can now load your model with AutoModelForSequenceClassification.from_pretrained("your-username/my-first-shared-model"). You just became the supply side of the same call you have used all track. (Delete the repo afterward if it was only a test.)
Part B: write the card. Edit the repo’s README.md (from the web interface is fine) to add: one line on what the model is for, the base checkpoint it came from, and one honest limitation.
What a minimal good card includes
Intended use (“a sentence-pair classifier fine-tuned for X”), the base model and data (“fine-tuned from bert-base-cased on the MRPC dataset”), and at least one limitation (“English only; reflects biases in its training data”). Even three honest lines beat an empty card. The point is that the next person can decide in thirty seconds whether your model fits their problem.
Part C (reasoning). A teammate pushes only model.push_to_hub(...) and you try to load and run it. What goes wrong, and what was missing?
What you should notice
You can load the model weights, but you have no tokenizer, so you cannot turn text into the input_ids the model needs, and any inference fails or silently uses a mismatched tokenizer. The fix is to push the tokenizer to the same repo. A model and its tokenizer are a pair; sharing one without the other ships something that cannot be run.
Flashcards
Section titled “Flashcards”Nine cards. Click any card to reveal the answer. Use the Print flashcards button to lay the set out one card per page for offline review.
Q. How do you authenticate to upload to the Hub?
notebook_login() from huggingface_hub in a notebook, or hf auth login in a terminal. You paste a token from your account settings; it is cached for later uploads.
Q. Easiest way to upload a Trainer-fine-tuned model?
Set push_to_hub=True in TrainingArguments (uploads as it saves), then call trainer.push_to_hub() at the end, which also generates a starter model card with hyperparameters and metrics.
Q. How do you push a model and tokenizer directly?
model.push_to_hub(‘name’) creates the repo and uploads model files; tokenizer.push_to_hub(‘name’) adds the tokenizer files to the same repo. Always push both.
Q. Why must you push the tokenizer with the model?
A model without its matching tokenizer is unusable: the next person needs the exact text-to-numbers conversion you trained with, or inference fails or mismatches.
Q. What are the three routes onto the Hub?
The push_to_hub API (easiest), the huggingface_hub library (create_repo, upload_file), and git plus git-lfs (barebones). They trade convenience for control.
Q. What files make up a usable model repo?
config.json (architecture/settings), the weights (large file, git-lfs), and tokenizer files (vocab, tokenizer_config.json, special-tokens map). Exactly what from_pretrained looks for.
Q. Why does the Hub use git-lfs?
Model weights are large binary files that plain git handles poorly. git-lfs (Git Large File Storage) tracks the big files; small JSON files use normal git. Higher-level tools do this split automatically.
Q. What is a model card, and where does it live?
The README.md at the repo root, in Markdown. It documents intended use, training data, strengths, limitations, and usage. It is the real deliverable: weights without a card are nearly useless to others.
Q. Why is sharing the engine of the ecosystem?
Almost every model you load exists because someone uploaded it. Sharing makes work versioned, loadable anywhere, and reusable; an honest model card is what makes it trustworthy, and trust is what the Hub runs on.