Datasets:

License:
docs / README.md
marvinseyfarth's picture
Upload README.md with huggingface_hub
de02b5d verified
---
license: other
---
# Uploading Pretrained Checkpoints to Hugging Face
This guide explains how to upload model checkpoints to a shared Hugging Face repository using `huggingface_hub`.
---
## 1. Prerequisites
Activate your conda environment, then install the Hugging Face Hub client **inside it**:
```bash
conda activate <your-env>
pip install huggingface_hub
```
Verify it is installed correctly:
```bash
python -c "import huggingface_hub; print(huggingface_hub.__version__)"
```
> **Note on CLI command name:** In `huggingface_hub` v1.0+, the CLI was renamed from `huggingface-cli` to **`hf`**. If you are on v1.x (check with the command above), use `hf` everywhere in this guide. If the command is still not found despite the package being installed, use the module fallback:
>
> ```bash
> python -m huggingface_hub.cli.hf --version
> ```
>
> Use `python -m huggingface_hub.cli.hf` as a drop-in replacement for `hf` anywhere below.
---
## 2. Create a Hugging Face Account
Go to [huggingface.co](https://huggingface.co) and create a personal account if you do not have one. Ask the organisation owner to add you as a member of the shared organisation so you have write access to the repository.
---
## 3. Log in
```bash
hf auth login
```
You will be prompted for an access token. Generate one at:
**huggingface.co → Settings → Access Tokens → New token** (role: **Write**)
Paste the token when prompted. Your credentials are stored locally and persist across sessions.
---
## 4. Create a Repository in the Organisation
Before uploading, you need a repository to upload to. Please use the same name as the github repo. Create one under the organisation with:
```bash
hf repos create AICM-HD/<repo-name> --repo-type model
```
Add `--private` if the repository should not be publicly visible:
```bash
hf repos create AICM-HD/<repo-name> --repo-type model --private
```
---
## 6. Checkpoint Naming Convention
Before uploading, rename checkpoints to make them unambiguous. A clear convention is:
```
{model}_{dataset}.pth
```
For example: `vqgan_chestct.pth`, `ldm_chestct.pth`, etc.
---
## 7. Upload Checkpoints
Replace `<repo>` with the actual repository name on Hugging Face.
**Upload a single file:**
```bash
hf upload AICM-HD/<repo> \
/path/to/local/checkpoint.pth \
checkpoint.pth \
--repo-type model
```
The third argument is the destination filename inside the repository.
**Upload all checkpoints at once from a folder:**
```bash
hf upload AICM-HD/<repo> \
/path/to/checkpoints/ \
. \
--repo-type model
```
This uploads the entire folder contents to the root of the repository.
---
## 8. Verify the Upload
Open the repository in a browser:
```
https://huggingface.co/<org>/<repo>
```
You should see the uploaded files listed under **Files and versions**. Click any file to confirm its size matches the local checkpoint.
You can also verify from the terminal:
```bash
hf repo info AICM-HD/<repo> --repo-type model
```
---
## 9. Downloading Checkpoints
Anyone with access to the repository can download checkpoints with:
```bash
pip install huggingface_hub
hf download AICM-HD/<repo> checkpoint.pth --local-dir checkpoints/
```
Or download everything at once:
```bash
hf download AICM-HD/<repo> --local-dir checkpoints/
```
If the repository is private, members must log in first (`hf auth login`) with their own access token.
---