Skip to content

Cheatsheet: Share your work on the Hub

from huggingface_hub import notebook_login
notebook_login() # notebook
# hf auth login # terminal

Paste a token from your account settings; it is cached for later uploads.

RouteUse whenKey calls
push_to_hub APIAlmost alwayspush_to_hub=True, trainer.push_to_hub(), model.push_to_hub()
huggingface_hub libraryProgrammatic repo managementcreate_repo, upload_file
git + git-lfsFull manual controlgit lfs install, clone, add, commit, push
# During Trainer training:
training_args = TrainingArguments(
"bert-finetuned-mrpc", save_strategy="epoch", push_to_hub=True
)
# ... trainer.train() ...
trainer.push_to_hub() # final push + auto-generated model card
# Or directly on objects:
model.push_to_hub("dummy-model")
tokenizer.push_to_hub("dummy-model") # always push the tokenizer too

hub_model_id="org/name" targets an organization. trainer.push_to_hub() auto-writes a card with hyperparameters + metrics.

from huggingface_hub import create_repo, upload_file
create_repo("dummy-model") # private=True to hide; repo_type="dataset"/"space"
upload_file("config.json", path_in_repo="config.json",
repo_id="username/dummy-model") # HTTP, no git; <5GB per file
Terminal window
git lfs install
git clone https://huggingface.co/username/dummy-model
# model.save_pretrained(dir) + tokenizer.save_pretrained(dir)
git add . && git commit -m "First model version" && git push

git-lfs auto-tracks large weight files; small JSON files use plain git.

FileWhat it isHandler
config.jsonArchitecture + settingsgit
weights (*.bin / *.safetensors)The trained parametersgit-lfs
tokenizer filesVocab, tokenizer_config.json, special tokensgit
README.mdThe model cardgit

This is exactly the set from_pretrained expects, which is why one line loads it.

  • What it is for (the task, the intended use)
  • Where it came from (base checkpoint, training data)
  • What it cannot do (limitations, biases, language scope)
  • How to use it (a short code snippet)

A good card is the difference between a model others adopt and weights nobody touches.

  • Namespace: your username or an organization you can write to.
  • git-lfs: Git Large File Storage; tracks large binaries (weights) separately from plain git.
  • Model card: the repo’s README.md; documentation + honesty statement.
  • Hugging Face LLM Course, Chapter 4: “Sharing models and tokenizers.” huggingface.co/learn/llm-course/chapter4. Released under Apache 2.0; this lesson mirrors its structure with original prose.