Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Docker ROCm image: ship Unsloth Studio, as the CUDA image already does (#11218)

Leo Borcherdinge259903f8379
diff --git a/.github/workflows/docker-publish-rocm.yml b/.github/workflows/docker-publish-rocm.yml
index eaa103ce634..51229e45627 100644
--- a/.github/workflows/docker-publish-rocm.yml
+++ b/.github/workflows/docker-publish-rocm.yml
@@ -1,4 +1,6 @@
-# Builds and publishes the AMD ROCm Unsloth Docker image (docker/Dockerfile.rocm).
+# Builds and publishes the AMD ROCm Unsloth Docker images: the training base
+# (docker/Dockerfile.rocm, :latest) and Studio on top of it
+# (docker/Dockerfile.studio-rocm, :studio).
#
# No GPU runner needed: the ROCm torch wheels do not probe a device at install
# time, and the build-time check reads torch.version.hip, a constant baked into
@@ -267,10 +269,84 @@ jobs:
UNSLOTH_REF=${{ needs.prepare.outputs.unsloth_ref }}
UNSLOTH_ZOO_REF=${{ needs.prepare.outputs.zoo_ref }}
+ # Studio on the base this run pushed (docker/Dockerfile.studio-rocm), the ROCm
+ # half of docker-publish.yml's build-studio. The base by DIGEST, not by tag:
+ # :latest can already be a newer run's by the time this job starts. The Studio
+ # refs are the ones the base baked, so both venvs run the same commit even if
+ # upstream moved mid-run. Before tag: no stable tag moves until both digests
+ # exist, so :latest and :studio always come from one run (unlike the CUDA
+ # workflow, where :core moves before its Studio build starts).
+ build-studio:
+ needs: [prepare, build]
+ runs-on: ubuntu-latest
+ timeout-minutes: 150
+ outputs:
+ digest: ${{ steps.build.outputs.digest }}
+ steps:
+ - uses: actions/checkout@v7
+
+ # The 21GB base is pulled onto the runner and Studio adds a second torch on
+ # top, so this clears more than the base build does.
+ - name: Reclaim disk
+ run: |
+ sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc \
+ /opt/hostedtoolcache "$AGENT_TOOLSDIRECTORY" \
+ /usr/local/.ghcup /usr/share/swift \
+ /usr/local/share/powershell /usr/local/lib/node_modules \
+ /usr/local/julia* /opt/microsoft /usr/share/miniconda \
+ /opt/az /usr/local/share/boost /usr/local/share/chromium || true
+ sudo docker image prune -af >/dev/null 2>&1 || true
+ df -h /
+
+ - uses: docker/setup-buildx-action@v3
+
+ - name: Log in to Docker Hub
+ uses: docker/login-action@v4
+ with:
+ username: ${{ env.REGISTRY_USERNAME }}
+ password: ${{ secrets.DOCKER_API_KEY }}
+
+ - name: Resolve labels
+ id: meta
+ uses: docker/metadata-action@v6
+ with:
+ images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
+ # This one ships Studio itself, which is AGPL-3.0.
+ labels: |
+ org.opencontainers.image.licenses=Apache-2.0 AND AGPL-3.0-only
+
+ - name: Build and push (by digest)
+ id: build
+ uses: docker/build-push-action@v6
+ with:
+ context: ./docker
+ file: ./docker/Dockerfile.studio-rocm
+ platforms: linux/amd64
+ labels: ${{ steps.meta.outputs.labels }}
+ # No cache-from / cache-to, for the reason the base build gives.
+ outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
+ build-args: |
+ BASE_IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ needs.build.outputs.digest }}
+ UNSLOTH_STUDIO_REF=${{ needs.prepare.outputs.unsloth_ref }}
+ UNSLOTH_STUDIO_ZOO_REF=${{ needs.prepare.outputs.zoo_ref }}
+
+ # The Dockerfile hands install.sh UNSLOTH_ALLOW_CPU=1 for the GPU-less build
+ # only. Image-wide it would reach every process and turn off Unsloth's TRL
+ # trainer patches on GPU hosts (#10825), so check the artifact the registry
+ # serves rather than the Dockerfile text, as docker-publish.yml does.
+ - name: Assert the Studio image env cannot disable training
+ run: |
+ REF='${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build.outputs.digest }}'
+ ENV_JSON="$(docker buildx imagetools inspect "$REF" --format '{{json .Image}}' \
+ | jq -c '[.. | objects | select(has("config")) | .config.Env // []] | add')"
+ echo "$ENV_JSON" | jq -r '.[] | select(startswith("UNSLOTH_"))'
+ echo "$ENV_JSON" | jq -e 'map(select(startswith("UNSLOTH_ALLOW_CPU="))) | length == 0' >/dev/null \
+ || { echo "::error::Studio image env carries UNSLOTH_ALLOW_CPU, which disables Unsloth's TRL patches on GPU hosts"; exit 1; }
+
# Attach human-readable tags to the digest pushed above.
tag:
runs-on: ubuntu-latest
- needs: [prepare, build]
+ needs: [prepare, build, build-studio]
timeout-minutes: 15
outputs:
tags: ${{ steps.meta.outputs.tags }}
@@ -314,6 +390,41 @@ jobs:
docker buildx imagetools inspect "$tag"
done
+ # The same rules with a -studio leaf, in this job and right after the base's:
+ # a second job could be scheduled with another run's tag job in between, and
+ # the twins would then come from different builds. format(), not a bare
+ # ${{ }}-studio: the raw gfx line above is matched by name in
+ # tests/python/test_docker_rocm.py and must stay unique.
+ - name: Resolve Studio tags
+ id: meta_studio
+ uses: docker/metadata-action@v6
+ with:
+ images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
+ tags: |
+ type=raw,value=studio,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && needs.prepare.outputs.stable == 'true' }}
+ type=ref,event=tag,suffix=-studio,enable=${{ needs.prepare.outputs.stable == 'true' }}
+ type=schedule,pattern=nightly-studio,enable=${{ needs.prepare.outputs.stable == 'true' }}
+ type=raw,value=${{ format('{0}-studio', needs.prepare.outputs.rocm_gfx) }},enable=${{ needs.prepare.outputs.gfx_tag == 'true' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
+ type=sha,prefix=sha-,format=short,suffix=${{ needs.prepare.outputs.rocm_gfx != '' && format('-{0}', needs.prepare.outputs.rocm_gfx) || '' }}${{ needs.prepare.outputs.stable != 'true' && format('-r{0}', github.run_id) || '' }}-studio
+
+ - name: Create Studio manifest
+ env:
+ DIGEST: ${{ needs.build-studio.outputs.digest }}
+ TAGS_JSON: ${{ steps.meta_studio.outputs.json }}
+ run: |
+ TAG_FLAGS=()
+ while IFS= read -r t; do TAG_FLAGS+=(-t "$t"); done < <(jq -r '.tags[]' <<<"$TAGS_JSON")
+ docker buildx imagetools create "${TAG_FLAGS[@]}" "${REGISTRY}/${IMAGE_NAME}@${DIGEST}"
+
+ - name: Inspect the Studio result
+ env:
+ TAGS_JSON: ${{ steps.meta_studio.outputs.json }}
+ run: |
+ for tag in $(jq -r '.tags[]' <<<"$TAGS_JSON"); do
+ echo "=== $tag ==="
+ docker buildx imagetools inspect "$tag"
+ done
+
# The Docker Hub page is repository metadata that no push writes, so without
# this it stays whatever was set by hand. Mirrors docker-publish.yml's
# hub-readme job: synced from docker/DOCKERHUB-ROCM.md whenever :latest moved,
diff --git a/docker/.dockerignore b/docker/.dockerignore
index 89e60acc4c6..4d90c13494b 100644
--- a/docker/.dockerignore
+++ b/docker/.dockerignore
@@ -9,6 +9,7 @@
!fetch_llama_prebuilt.py
!supervisord.conf
!studio_launch.sh
+!studio_launch_rocm.sh
!studio_password.sh
!studio_run.sh
!studio_home.sh
diff --git a/docker/DOCKERHUB-ROCM.md b/docker/DOCKERHUB-ROCM.md
index fa295f1778d..a0610c8a611 100644
--- a/docker/DOCKERHUB-ROCM.md
+++ b/docker/DOCKERHUB-ROCM.md
@@ -75,6 +75,7 @@ That runs a real 5-step LoRA on a 1B model and fails loudly if the GPU is not us
| `sha-<commit>` | the same image, pinned to the commit it was built from |
| `nightly` | the scheduled weekly build |
| `gfx1150`, `gfx1151`, `gfx1152`, `gfx1200`, `gfx1201` | builds using AMD's per-architecture wheels, when published |
+| `studio` | `latest` plus Unsloth Studio's web UI on port 8000, from [`docker/Dockerfile.studio-rocm`](https://github.com/unslothai/unsloth/blob/main/docker/Dockerfile.studio-rocm). The other tags above have a `-studio` twin built on the same base: `nightly-studio`, `sha-<commit>-studio`, `gfx1151-studio`; there is no `latest-studio`, `studio` is that one |
Pin a digest for anything reproducible. `latest` moves.
@@ -108,7 +109,16 @@ Discrete RDNA2, RDNA4 and CDNA cards are not covered by that testing.
Included: PyTorch with ROCm, Unsloth, unsloth-zoo, transformers, TRL, PEFT, accelerate, bitsandbytes, triton-rocm, diffusers, timm.
-Not included, unlike `unsloth/unsloth`: Unsloth Studio and its web UI, JupyterLab, prebuilt llama.cpp and whisper.cpp, vLLM and xformers. This is a training image; GGUF tooling and the UI are CUDA-only for now.
+Not included in `latest`, unlike `unsloth/unsloth`: Unsloth Studio and its web UI, JupyterLab, prebuilt llama.cpp and whisper.cpp, vLLM and xformers. `latest` is a training image.
+
+The `studio` tag adds Unsloth Studio and a CPU llama.cpp for GGUF chat, still without JupyterLab, whisper.cpp, vLLM or xformers. Training and the UI use the GPU; GGUF chat runs on the CPU, since a ROCm llama.cpp bundle is per-architecture and would pin the image to one card. Studio's data (accounts, chats, outputs) lives at `/opt/unsloth-studio`, so mount a volume there to keep it, with `GPU_FLAGS` set as in the quick start:
+
+```bash
+docker run --rm $GPU_FLAGS --ipc=host -p 127.0.0.1:8000:8000 \
+ -v unsloth-studio-rocm:/opt/unsloth-studio \
+ -v "$HOME/.cache/huggingface":/workspace/.cache/huggingface \
+ unsloth/unsloth-rocm:studio
+```
## Environment
@@ -117,6 +127,7 @@ Not included, unlike `unsloth/unsloth`: Unsloth Studio and its web UI, JupyterLa
| `UNSLOTH_SKIP_GPU_CHECK=1` | skip the startup diagnostics |
| `HSA_OVERRIDE_GFX_VERSION` | present an unsupported card as a supported one. Ignored on images with native kernels for the card |
| `HF_TOKEN` | forwarded for gated models |
+| `UNSLOTH_STUDIO_PASSWORD` | `studio` tag: the initial admin password, first boot only; ignored once one is stored. Unset, Studio generates one and names the file it wrote in the log |
Model downloads land in `/workspace/.cache/huggingface`, which is in the container's writable layer unless you mount it. Mount it to keep them, and to reuse what the host has already downloaded.
@@ -127,4 +138,4 @@ The build's own record is in the image: `cat /etc/unsloth-rocm-build` reports th
- Source and issues: [github.com/unslothai/unsloth](https://github.com/unslothai/unsloth)
- Docker files: [`docker/`](https://github.com/unslothai/unsloth/tree/main/docker)
- Documentation: [docs.unsloth.ai](https://docs.unsloth.ai)
-- Licences: the image is labelled `Apache-2.0 AND AGPL-3.0-only`. [Apache-2.0](https://github.com/unslothai/unsloth/blob/main/LICENSE) covers the repository and the training stack. The [AGPL-3.0](https://github.com/unslothai/unsloth/blob/main/studio/LICENSE.AGPL-3.0) half is there for the one AGPL file this image ships, `/workspace/smoke_test_rocm.py`, which carries an `AGPL-3.0-only` header; Unsloth Studio itself is not in this image.
+- Licences: the image is labelled `Apache-2.0 AND AGPL-3.0-only`. [Apache-2.0](https://github.com/unslothai/unsloth/blob/main/LICENSE) covers the repository and the training stack. The [AGPL-3.0](https://github.com/unslothai/unsloth/blob/main/studio/LICENSE.AGPL-3.0) half is there for the one AGPL file this image ships, `/workspace/smoke_test_rocm.py`, which carries an `AGPL-3.0-only` header; Unsloth Studio itself is only in the `studio` tag.
diff --git a/docker/Dockerfile.studio-rocm b/docker/Dockerfile.studio-rocm
new file mode 100644
index 00000000000..f35b036ca0a
--- /dev/null
+++ b/docker/Dockerfile.studio-rocm
@@ -0,0 +1,126 @@
+# Unsloth Studio on AMD (ROCm): the ROCm training image + Studio's web UI.
+#
+# The AMD counterpart to Dockerfile.studio, which layers Studio on the CUDA core
+# image. Kept as its own file rather than a branch in that one: the CUDA build
+# bakes a CUDA llama.cpp, stages NVRTC and dedups the nvidia-* wheels against the
+# base venv, and none of those steps have a ROCm meaning.
+#
+# Not here yet, unlike unsloth/unsloth:studio: JupyterLab, sshd and supervisord.
+# The ROCm base ships no jupyterlab, so that whole chain (labextension build,
+# branding, the three-service supervisor) is a follow-up. This runs Studio alone.
+#
+# llama.cpp is installed as the CPU bundle: the builder has no GPU, and a ROCm
+# bundle is per-gfx-family, so baking one would pin this image to one arch. GGUF
+# chat therefore runs on the CPU here; training and the UI use the GPU.
+#
+# Build (on the published ROCm base, or one built from docker/Dockerfile.rocm):
+# docker buildx build --build-arg BASE_IMAGE=unsloth/unsloth-rocm:latest \
+# -f docker/Dockerfile.studio-rocm -t unsloth/unsloth-rocm:studio docker/
+# Run (Linux) with the wrapper, which adds the device nodes, the NUMERIC group ids
+# and the Studio volume, but publishes no port and picks :latest unless told:
+# UNSLOTH_IMAGE=unsloth/unsloth-rocm:studio UNSLOTH_PORTS="-p 127.0.0.1:8000:8000" \
+# UNSLOTH_STUDIO_VOLUME=unsloth-studio-rocm bash docker/run.sh --rocm
+# or by hand (group ids as numbers: the names do not exist inside the image):
+# docker run --rm --device /dev/kfd --device /dev/dri \
+# --group-add "$(getent group video | cut -d: -f3)" \
+# --group-add "$(getent group render | cut -d: -f3)" \
+# --ipc=host -p 127.0.0.1:8000:8000 \
+# -v unsloth-studio-rocm:/opt/unsloth-studio unsloth/unsloth-rocm:studio
+# Windows/WSL2 has no /dev/kfd: the card is reached over /dev/dxg, which the
+# wrapper and the entrypoint only learn in #11212. Until that lands, pass
+# /dev/dxg, the host's librocdxg and HSA_ENABLE_DXG_DETECTION=1 by hand, with
+# UNSLOTH_SKIP_GPU_CHECK=1 to get past the entrypoint's /dev/kfd gate.
+# UNSLOTH_STUDIO_PASSWORD sets the initial admin password, first boot only;
+# unset, Studio generates one.
+
+ARG BASE_IMAGE=unsloth/unsloth-rocm:latest
+
+FROM ${BASE_IMAGE}
+
+# Studio source ref to clone. Defaults to main; docker-publish-rocm.yml pins it
+# to the UNSLOTH_REF the base baked, so the published image is reproducible.
+ARG UNSLOTH_STUDIO_REF=main
+# unsloth-zoo ref overlaid into the Studio venv by install.sh --local, so Studio
+# runs the same zoo as the base.
+ARG UNSLOTH_STUDIO_ZOO_REF=main
+
+# UV_CACHE_DIR lives in the app dir: install.sh defaults it to
+# $UNSLOTH_STUDIO_HOME/cache/uv, which would fill a volume on the home with wheels.
+ENV UNSLOTH_STUDIO_HOME=/opt/unsloth-studio \
+ UNSLOTH_STUDIO_APP=/opt/unsloth-studio-app \
+ UV_CACHE_DIR=/opt/unsloth-studio-app/uv-cache \
+ UNSLOTH_STUDIO_PORT=8000 \
+ DEBIAN_FRONTEND=noninteractive
+
+RUN apt-get update \
+ && apt-get install -y --no-install-recommends curl git ca-certificates \
+ && rm -rf /var/lib/apt/lists/*
+
+# The linker this build finishes with, and the entrypoint reruns.
+COPY studio_home.sh /usr/local/bin/unsloth-studio-home
+
+# Clone + install Studio into a venv under $UNSLOTH_STUDIO_HOME, then move it to
+# $UNSLOTH_STUDIO_APP in the same layer (a later RUN would store it twice).
+#
+# The torch index comes from /etc/unsloth-rocm-build, which the base wrote with
+# the index it actually resolved against: the pytorch.org rocm leaf normally, or
+# repo.amd.com/rocm/whl/<family>/ on a per-arch (ROCM_GFX) build. Letting
+# install.sh detect instead would land on CPU wheels, since the builder has no GPU.
+#
+# fetch+checkout FETCH_HEAD, not `clone --branch`: CI passes a commit SHA.
+RUN set -eux \
+ && . /etc/unsloth-rocm-build \
+ && mkdir -p "${UNSLOTH_STUDIO_HOME}" \
+ && git init -q "${UNSLOTH_STUDIO_HOME}/src" \
+ && cd "${UNSLOTH_STUDIO_HOME}/src" \
+ && git remote add origin https://github.com/unslothai/unsloth \
+ && git fetch -q --depth 1 origin "${UNSLOTH_STUDIO_REF}" \
+ && git checkout -q FETCH_HEAD \
+ && UNSLOTH_STUDIO_HOME="${UNSLOTH_STUDIO_HOME}" \
+ UNSLOTH_TORCH_INDEX_URL="${TORCH_INDEX_URL}" \
+ UNSLOTH_ZOO_REF="${UNSLOTH_STUDIO_ZOO_REF}" \
+ # ROCM_GFX from the base's record too: install.sh leaves bitsandbytes out of a
+ # gfx906 install (no wheel carries its kernels) only when told the arch, since
+ # the GPU-less builder cannot probe it. Empty on a generic build, which
+ # install.sh reads as unset.
+ UNSLOTH_ROCM_GFX_ARCH="${ROCM_GFX}" \
+ UNSLOTH_LLAMA_CPP_BACKEND=cpu \
+ UNSLOTH_SKIP_WHISPER_INSTALL=1 \
+ UNSLOTH_PYTHON=3.12 \
+ UNSLOTH_ALLOW_CPU=1 \
+ bash install.sh --local \
+ # Assert the ROCm leaf, not the exact version: Studio's installer pins
+ # torch>=2.11,<2.12 while the base resolves whatever the ROCm index serves
+ # (2.12.1 today), so equality is unreachable here. The CUDA image can demand it
+ # because both sides land on the same wheel. What must hold is that Studio did
+ # not quietly fall back to CPU or CUDA wheels, and that both venvs run the same
+ # ROCm. The cost is two torch copies in one image; deduping them is a follow-up.
+ && BASE_ROCM="$(/opt/unsloth-venv/bin/python -c "from importlib.metadata import version; print(version('torch').split('+')[1])")" \
+ && "${UNSLOTH_STUDIO_HOME}/unsloth_studio/bin/python" -c "import sys; from importlib.metadata import version; v = version('torch'); assert '+rocm' in v, 'Studio venv torch ' + v + ' is not a ROCm build'; assert v.split('+')[1] == '${BASE_ROCM}', 'Studio venv torch ' + v + ' is not the base venv ROCm leaf ${BASE_ROCM}'; print('Studio venv python %d.%d torch' % sys.version_info[:2], v, 'on base ROCm leaf ${BASE_ROCM}')" \
+ # A gfx906 Studio venv must not expose the 4-bit backend the base removed.
+ && "${UNSLOTH_STUDIO_HOME}/unsloth_studio/bin/python" -c "import importlib.util as u; has = u.find_spec('bitsandbytes') is not None; assert not (has and '${ROCM_GFX}' == 'gfx906'), 'Studio venv has bitsandbytes on a gfx906 base'; print('Studio venv bitsandbytes:', has, 'ROCM_GFX:', '${ROCM_GFX}' or '(generic)')" \
+ # The UI is the point of this image, so a missing frontend build is fatal here
+ # rather than a 404 at runtime.
+ && test -f "${UNSLOTH_STUDIO_HOME}/src/studio/frontend/dist/index.html" \
+ && rm -rf "${UNSLOTH_STUDIO_HOME}/src/.git" \
+ "${UNSLOTH_STUDIO_HOME}/src/studio/frontend/node_modules" \
+ "${UV_CACHE_DIR}" \
+ /root/.cache \
+ && mkdir -p "${UNSLOTH_STUDIO_APP}" \
+ && find "${UNSLOTH_STUDIO_HOME}" -mindepth 1 -maxdepth 1 ! -name cache -exec mv -t "${UNSLOTH_STUDIO_APP}" {} + \
+ && bash /usr/local/bin/unsloth-studio-home \
+ && "${UNSLOTH_STUDIO_HOME}/unsloth_studio/bin/python" -c "import os, sys, studio; print('Studio venv', sys.prefix, 'imports studio from', studio.__file__); assert os.path.realpath(studio.__file__).startswith(os.path.realpath('${UNSLOTH_STUDIO_HOME}/src') + '/'), studio.__file__"
+
+# unsloth-studio-run is the CUDA image's Studio program: it hands Studio the
+# initial password only while none is stored. The launcher is this image's own,
+# since the CUDA one starts supervisord.
+COPY studio_run.sh /usr/local/bin/unsloth-studio-run
+COPY studio_launch_rocm.sh /usr/local/bin/unsloth-studio-launch
+RUN chmod +x /usr/local/bin/unsloth-studio-home /usr/local/bin/unsloth-studio-run \
+ /usr/local/bin/unsloth-studio-launch
+
+EXPOSE 8000
+
+# The base ENTRYPOINT (unsloth-entrypoint-rocm) runs its GPU pre-flight first,
+# then execs this.
+CMD ["/usr/local/bin/unsloth-studio-launch"]
diff --git a/docker/studio_launch_rocm.sh b/docker/studio_launch_rocm.sh
new file mode 100644
index 00000000000..e2c6a0757c6
--- /dev/null
+++ b/docker/studio_launch_rocm.sh
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+# Default CMD of the ROCm Studio image (Dockerfile.studio-rocm): Studio alone, no
+# supervisord. UNSLOTH_STUDIO_PASSWORD only sets the initial admin password, and
+# `unsloth studio` exits 1 when handed one after that, so a `docker restart` with
+# the variable still set (a Compose file) would never come back up. As
+# studio_launch.sh does: the value goes to a root-only file that unsloth-studio-run
+# reads while nothing is stored, and never into Studio's environment.
+set -euo pipefail
+
+unsloth-studio-home
+
+INITIAL_FILE="${UNSLOTH_STUDIO_INITIAL_PASSWORD_FILE:-/run/unsloth/studio-initial-password}"
+rm -f "$INITIAL_FILE"
+if unsloth-studio-run --stored; then
+ NOTE="password set on an earlier boot (inside the container: unsloth studio reset-password)"
+elif [[ -n "${UNSLOTH_STUDIO_PASSWORD:-}" ]]; then
+ mkdir -p "$(dirname "$INITIAL_FILE")"
+ (umask 077 && printf '%s' "$UNSLOTH_STUDIO_PASSWORD" > "$INITIAL_FILE")
+ NOTE="password from UNSLOTH_STUDIO_PASSWORD env"
+else
+ NOTE="password generated on first boot; Unsloth Studio names the file it wrote in its log below"
+fi
+unset UNSLOTH_STUDIO_PASSWORD
+echo "Unsloth Studio -> http://localhost:${UNSLOTH_STUDIO_PORT:-8000} (user unsloth, ${NOTE})"
+exec unsloth-studio-run
diff --git a/tests/python/test_docker_rocm.py b/tests/python/test_docker_rocm.py
index a38f7c9b78b..0820b3671de 100644
--- a/tests/python/test_docker_rocm.py
+++ b/tests/python/test_docker_rocm.py
@@ -25,6 +25,8 @@ _ENTRYPOINT = os.path.join(_DOCKER, "entrypoint-rocm.sh")
_DOCKERFILE = os.path.join(_DOCKER, "Dockerfile.rocm")
_SMOKE = os.path.join(_DOCKER, "smoke_test_rocm.py")
_WORKFLOW = os.path.join(_REPO, ".github", "workflows", "docker-publish-rocm.yml")
+_STUDIO_LAUNCH = os.path.join(_DOCKER, "studio_launch_rocm.sh")
+_STUDIO_DOCKERFILE = os.path.join(_DOCKER, "Dockerfile.studio-rocm")
_HUB_PAGE = os.path.join(_DOCKER, "DOCKERHUB-ROCM.md")
_README = os.path.join(_REPO, "README.md")
@@ -878,6 +880,50 @@ class TestRocmEntrypoint:
entry = open(_ENTRYPOINT, encoding = "utf-8").read()
assert "ROCM_GFX=gfx906 ROCM_VERSION=6.3.4" in entry
+ def test_the_studio_image_is_published_from_the_base_digest_with_the_same_refs(self):
+ """docker/Dockerfile.studio-rocm is built by the same run as the base, on the
+ base by digest (a tag can already be a newer run's) with the refs the base
+ baked, and takes the base's tags with a -studio leaf under the same gates."""
+ import yaml
+
+ wf = yaml.safe_load(open(_WORKFLOW, encoding = "utf-8"))
+ build = wf["jobs"]["build-studio"]
+ assert build["needs"] == ["prepare", "build"]
+ step = next(s for s in build["steps"] if s.get("id") == "build")
+ assert step["with"]["file"] == "./docker/Dockerfile.studio-rocm"
+ args = dict(ln.split("=", 1) for ln in step["with"]["build-args"].splitlines() if ln)
+ assert args["BASE_IMAGE"].endswith("@${{ needs.build.outputs.digest }}"), args
+ assert args["UNSLOTH_STUDIO_REF"] == "${{ needs.prepare.outputs.unsloth_ref }}"
+ assert args["UNSLOTH_STUDIO_ZOO_REF"] == "${{ needs.prepare.outputs.zoo_ref }}"
+
+ # no stable tag moves until both digests exist, and both manifests are created in ONE
+ # job, back to back. That orders the two writes WITHIN a run; it does not order two
+ # RUNS, which the per-run concurrency group deliberately lets overlap. Same shape as
+ # docker-publish.yml for latest + core, so the pairing window is repo-wide rather
+ # than this workflow's, and closing it needs a real lock: a shared concurrency group
+ # cancels a PENDING job (tests/studio/test_main_runs_survive_merge_bursts.py), which
+ # would drop a whole run's tags instead.
+ tag = wf["jobs"]["tag"]
+ assert tag["needs"] == ["prepare", "build", "build-studio"]
+ ids = [s.get("id") for s in tag["steps"]]
+ names = [s.get("name") for s in tag["steps"]]
+ assert ids.index("meta") < ids.index("meta_studio")
+ assert names.index("Create manifest") < names.index("Create Studio manifest")
+ assert "tag-studio" not in wf["jobs"]
+
+ def tag_lines(step_id):
+ meta = next(s for s in tag["steps"] if s.get("id") == step_id)
+ return [ln for ln in meta["with"]["tags"].splitlines() if ln.strip()]
+
+ studio, base = tag_lines("meta_studio"), tag_lines("meta")
+ assert len(studio) == len(base) == 5
+ for s_ln, b_ln in zip(studio, base):
+ assert "studio" in s_ln, s_ln
+ # the same enable= gate as the base line it mirrors
+ assert s_ln.split(",enable=", 1)[1:] == b_ln.split(",enable=", 1)[1:], (s_ln, b_ln)
+ create = next(s for s in tag["steps"] if s.get("name") == "Create Studio manifest")
+ assert create["env"]["DIGEST"] == "${{ needs.build-studio.outputs.digest }}"
+
def test_the_gfx_tag_needs_every_other_input_at_its_default(self):
"""A feature-branch ref plus rocm_gfx=gfx1151 must not replace the public
gfx1151 image: the gfx tag is gated like latest, minus the gfx itself."""
@@ -902,3 +948,96 @@ class TestRocmEntrypoint:
assert not re.search(r"RX\s*\d{4}", body), "marketing names in the entrypoint's arch table"
assert "gfx906" in body and "6.3" in body, "gfx906 needs the version-aware note"
+
+
+# ── studio_launch_rocm.sh ────────────────────────────────────────────────────
+
+
+def _studio_launch(
+ tmp_path,
+ *,
+ password = None,
+ stored = False,
+):
+ """Drive the launcher with unsloth-studio-run stubbed: `--stored` answers from a
+ marker, and the real call records the env and the initial-password file it saw."""
+ bindir = tmp_path / "bin"
+ bindir.mkdir()
+ initial = tmp_path / "initial-password"
+ seen = tmp_path / "seen"
+ if stored:
+ (tmp_path / "stored").write_text("")
+ _stub(str(bindir / "unsloth-studio-home"), "echo home-linked\n")
+ _stub(
+ str(bindir / "unsloth-studio-run"),
+ f'if [[ "${{1:-}}" == "--stored" ]]; then [[ -e "{tmp_path / "stored"}" ]]; exit; fi\n'
+ f"printf 'env=%s\\nfile=%s\\n' \"${{UNSLOTH_STUDIO_PASSWORD:-unset}}\" "
+ f'"$(cat "{initial}" 2>/dev/null || echo none)" > "{seen}"\n',
+ )
+ env = {
+ "PATH": str(bindir) + ":/usr/bin:/bin",
+ "HOME": str(tmp_path),
+ "UNSLOTH_STUDIO_INITIAL_PASSWORD_FILE": str(initial),
+ "UNSLOTH_STUDIO_PORT": "8123",
+ }
+ if password is not None:
+ env["UNSLOTH_STUDIO_PASSWORD"] = password
+ proc = subprocess.run(
+ [shutil.which("bash") or "/bin/bash", _STUDIO_LAUNCH],
+ env = env,
+ capture_output = True,
+ text = True,
+ timeout = 60,
+ )
+ recorded = (
+ dict(ln.split("=", 1) for ln in seen.read_text().splitlines()) if seen.exists() else {}
+ )
+ return proc, recorded, initial
+
+
+@_posix_shell
+class TestStudioLaunchRocm:
+ """UNSLOTH_STUDIO_PASSWORD only sets the FIRST admin password and `unsloth studio`
+ exits 1 when handed one afterwards, so the launcher must hand it over through the
+ file unsloth-studio-run reads while nothing is stored, and never as env."""
+
+ def test_the_first_boot_hands_the_password_over_by_file_not_env(self, tmp_path):
+ proc, seen, initial = _studio_launch(tmp_path, password = "s3cret pw")
+ assert proc.returncode == 0, proc.stderr
+ assert seen == {"env": "unset", "file": "s3cret pw"}, seen
+ assert stat.S_IMODE(os.stat(initial).st_mode) == 0o600
+ assert "password from UNSLOTH_STUDIO_PASSWORD env" in proc.stdout
+ assert "http://localhost:8123" in proc.stdout
+
+ def test_a_restart_with_the_variable_still_set_does_not_replay_it(self, tmp_path):
+ proc, seen, initial = _studio_launch(tmp_path, password = "s3cret pw", stored = True)
+ assert proc.returncode == 0, proc.stderr
+ assert seen == {"env": "unset", "file": "none"}, seen
+ assert not initial.exists()
+ assert "set on an earlier boot" in proc.stdout
+
+ def test_no_password_starts_studio_and_says_one_is_generated(self, tmp_path):
+ proc, seen, initial = _studio_launch(tmp_path)
+ assert proc.returncode == 0, proc.stderr
+ assert seen == {"env": "unset", "file": "none"}, seen
+ assert not initial.exists()
+ assert "generated on first boot" in proc.stdout
+
+ def test_a_stale_file_from_an_earlier_boot_is_cleared_first(self, tmp_path):
+ (tmp_path / "initial-password").write_text("old")
+ proc, seen, initial = _studio_launch(tmp_path, stored = True)
+ assert proc.returncode == 0, proc.stderr
+ assert not initial.exists() and seen["file"] == "none"
+
+ def test_the_image_runs_the_launcher_and_ships_the_run_helper(self):
+ body = open(_STUDIO_DOCKERFILE, encoding = "utf-8").read()
+ assert 'CMD ["/usr/local/bin/unsloth-studio-launch"]' in body
+ assert "COPY studio_run.sh /usr/local/bin/unsloth-studio-run" in body
+ assert "COPY studio_launch_rocm.sh /usr/local/bin/unsloth-studio-launch" in body
+ # the CUDA image's studio-password program waits on JupyterLab, which this
+ # image does not run; nothing here may invoke or ship it
+ assert "studio_password" not in body
+ # the gfx906 base removes bitsandbytes; the Studio venv must be told the arch
+ assert 'UNSLOTH_ROCM_GFX_ARCH="${ROCM_GFX}"' in body
+ ignore = open(os.path.join(_DOCKER, ".dockerignore"), encoding = "utf-8").read()
+ assert "!studio_launch_rocm.sh" in ignore and "!studio_run.sh" in ignore