Skip to content

README: mount the Hugging Face cache in the Docker quickstart - #11062

Merged
danielhanchen merged 1 commit into
mainfrom
docs/readme-docker-model-cache
Sep 16, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
docs/readme-docker-model-cache

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Reported in #10923: models downloaded inside the container disappear on docker rm.

The cause, measured

Inside unsloth/unsloth@sha256:3b88aa35b378e83db3f567cfb668931695f7bac951dcef37fa6a1f5e2e96fae1:

HF_HOME                         = /workspace/.cache/huggingface
HF_HUB_CACHE                    = /workspace/.cache/huggingface/hub
Studio's own resolver           = /workspace/.cache/huggingface/hub
Studio's state (accounts/chats) = /opt/unsloth-studio/cache
mounted                         = /opt/unsloth-studio only

huggingface_hub and Studio's get_hf_cache_paths().hub_cache agree on the destination, and that destination is on no volume, so it lives in the container's writable layer. The unsloth-studio volume covers accounts, chats and Studio state, not model weights.

Reproduced and fixed, by container replacement

A restart does not cross the boundary where the writable layer is discarded, so the test removes the container and starts a fresh one from the same digest, then resolves the model with HF_HUB_OFFLINE=1:

LEG A (the quickstart as documented)
  container 1: downloaded to /workspace/.cache/huggingface/hub/models--...
  fresh container, HF_HUB_OFFLINE=1 -> OFFLINE_RESOLVE=MISS LocalEntryNotFoundError

LEG B (same, plus this mount)
  container 1: downloaded to /workspace/.cache/huggingface/hub/models--...
  fresh container, HF_HUB_OFFLINE=1 -> OFFLINE_RESOLVE=OK

The change

docker/DOCKERHUB.md already mounts $HOME/.cache/huggingface in its quickstart and documents the path in its volume table, and docker/run.sh passes the same flag. The README was the outlier, so the mount here is copied from docker/DOCKERHUB.md verbatim rather than inventing a third variant. A host bind mount also lets the container reuse models the host has already downloaded.

The surrounding sentence changes too: "the unsloth-studio volume keeps your accounts, chats and trained models" reads as though downloads are covered, so it now says which store keeps what.

Not fixed here

This does not close #10923. The command that reporter followed is on unsloth.ai/docs/get-started/install/docker, which documents neither this mount nor the unsloth-studio volume and describes a container layout that no longer matches the image. That page is maintained outside this repository and needs the same correction.

Reported in #10923: models downloaded in the container disappear on docker rm.

Measured in unsloth/unsloth@sha256:3b88aa35b378: HF_HOME is
/workspace/.cache/huggingface, huggingface_hub and Studio's own resolver both
put downloads under it, and it is on no volume, so it lives in the container's
writable layer. The unsloth-studio volume covers accounts, chats and Studio
state, not model weights.

Reproduced by container replacement rather than restart: a fresh container from
the same digest could not resolve a previously downloaded model with
HF_HUB_OFFLINE=1, and could once the cache was mounted.

The mount is copied verbatim from docker/DOCKERHUB.md, which already documents
it, so the README stops being the outlier rather than inventing a third
variant. The surrounding sentence now says which store keeps what, since
'keeps your accounts, chats and trained models' reads as though downloads are
covered too.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-16T02:34:58.379823Z e13d451 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e13d45145a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread README.md
-p 8000:8000 -p 8888:8888 \
-e UNSLOTH_STUDIO_PASSWORD="mypassword" -e JUPYTER_PASSWORD="mypassword" \
-v "$PWD":/workspace/host \
-v "$HOME/.cache/huggingface":/workspace/.cache/huggingface \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid writing the host Hugging Face cache as root

When this quickstart is used on Linux/WSL and native Hugging Face tools also use $HOME/.cache/huggingface, the latest image runs its services as root (docker/DOCKERHUB.md:129), so models downloaded through the container leave root-owned directories, refs, and lock files in the user's cache. Subsequent host-side downloads or cache maintenance can then fail with permission errors, breaking the advertised shared-cache workflow; use a named volume or otherwise arrange host-UID ownership rather than binding the live user cache to this root process.

Useful? React with 👍 / 👎.

@danielhanchen
danielhanchen merged commit 2ab07c9 into main Sep 16, 2026
8 checks passed
@danielhanchen
danielhanchen deleted the docs/readme-docker-model-cache branch September 16, 2026 02:43
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…hai#11062)

Reported in unslothai#10923: models downloaded in the container disappear on docker rm.

Measured in unsloth/unsloth@sha256:3b88aa35b378: HF_HOME is
/workspace/.cache/huggingface, huggingface_hub and Studio's own resolver both
put downloads under it, and it is on no volume, so it lives in the container's
writable layer. The unsloth-studio volume covers accounts, chats and Studio
state, not model weights.

Reproduced by container replacement rather than restart: a fresh container from
the same digest could not resolve a previously downloaded model with
HF_HUB_OFFLINE=1, and could once the cache was mounted.

The mount is copied verbatim from docker/DOCKERHUB.md, which already documents
it, so the README stops being the outlier rather than inventing a third
variant. The surrounding sentence now says which store keeps what, since
'keeps your accounts, chats and trained models' reads as though downloads are
covered too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unsloth studio docker instructions don't save downloaded models.

1 participant