Skip to content

feat(docker): add CUDA container image for mlxcel and mlxcel-server - #3543

Merged
inureyes merged 8 commits into
mainfrom
feature/issue-3484-cuda-container-image
Nov 28, 2026
Merged

inureyes merged 8 commits into
mainfrom
feature/issue-3484-cuda-container-image

Conversation

@inureyes

@inureyes inureyes commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds docker/Dockerfile.cuda: a shell-less chiseled Ubuntu runtime image and a debug image (the whole nvidia/cuda cudnn-devel image plus mlxcel) for linux/amd64 and linux/arm64, running as uid 65532 with /models and /cache volumes. The previous attempt stopped at the CUDA header license gate; #3540 removed the non-redistributable includes, so the runtime image now ships.

What changed

  • The runtime image copies exactly scripts/ci/nvrtc_header_allowlist.txt into /usr/local/cuda/include (docker/copy-cuda-headers.sh, no second list). The build fails if a listed header is missing or any other file is there. docker/copy-cuda-headers_test.sh covers the guard and runs in CI.
  • CUDA and cuDNN files come from NVIDIA's CUDA apt repository. The signing key fingerprints are pinned, and the packages are unpacked without installing. Nothing is copied out of an nvidia/cuda image, because the NGC container license allows a derived image only when it includes the whole container (1.c, 4.c). Package versions go to /opt/mlxcel/share/cuda-packages.txt.
  • Libraries come from a readelf closure plus a measured dlopen set, with a glibc/libstdc++ version guard.
  • amd64 defaults to Ubuntu 26.04 with CUDA 13.5, because the x86_64 release runner builds with CUDA 13.5 and its binaries need GLIBC_2.43. arm64 stays on Ubuntu 24.04 with CUDA 13.0.
  • NOTICE records the CUDA EULA and cuDNN distribution basis and adds the bundled CCCL (Apache-2.0 with LLVM exceptions) and CUTLASS/CuTe (BSD-3-Clause) headers. README.md and docs/installation.md describe the image.
  • The /health wording is corrected, not the server: with -m the listener binds only after load and warmup, so probes are refused until the server returns 200. The image has no HEALTHCHECK.
  • Security review: HOME=/cache means -m owner/name reads /cache/.cache/huggingface/hub before /models without an owner check, so a /cache other host uids can write lets them substitute a model. The docs now recommend a 65532-owned or private-group bind; a resolver fix is left for a follow-up.

Test plan

GB10, local build of main at 15e63955 (#3508, #3509, #3540), arm64 runtime image, all GPU runs under gpu-lock.

  • Cold-cache mlxcel generate under strace inside the runtime image: exit 0, 0 to 12 PTX files. It opened 11 toolkit headers, all allow-listed, and no header outside the toolkit and bundled include roots.
  • Server smoke as 65532, named volume, root:root 0777 bind with the trusted root, and 65532:65532 2775 bind with the trusted root unset. In every case the chat completion returned text, docker stop took under 1 s with exit 0, and the second start compiled nothing and left the cache identical. CLI generate worked and --entrypoint sh failed.
  • The literal --platform linux/amd64,linux/arm64 build from v0.8.1, cache-only, for runtime and debug; amd64 runtime also from v0.9.0-beta.3 (glibc 2.43 rootfs).
  • The GPU runs used the image before the review follow-up 3ab35c1f (copyright files, build-step hardening); that version was only rebuilt, not run.
  • docker/copy-cuda-headers_test.sh (5 cases, including a planted math_constants.h and a symlink).
  • Not run: any amd64 container or x86_64 GPU (including NVRTC 13.5), release binaries at run time (no release has fix(server): drain gracefully on SIGTERM and SIGINT #3508/fix(cuda): let the PTX disk cache trust a container volume root #3509/fix(cuda): make NVRTC JIT need only redistributable CUDA headers #3540 yet), either debug image at run time, kernels Qwen3 does not reach. Record: docs/benchmark_results/docker-cuda-smoke-gb10-2026-11-29.md.

Owner review requested: the license basis in NOTICE (CUDA EULA Attachment A and 1.1.2, cuDNN supplement, NGC container license 1.c/4.c/7) is my reading of those documents, not legal advice.

Closes #3484

Add docker/Dockerfile.cuda with a chiseled Ubuntu runtime target and a cudnn-devel debug target, both carrying /opt/mlxcel, user 65532, HOME=/cache, MLXCEL_CACHE_DIR=/cache/mlxcel under MLXCEL_CACHE_TRUSTED_ROOT=/cache, and the mlxcel-server entrypoint. Binaries come from the release zips (sha256-checked) or, with MLXCEL_SOURCE=local, from a build context. Every RUN runs on the build platform, so a linux/amd64 image builds on an arm64 host without emulation; docker/collect-runtime-libs.sh resolves libraries with readelf plus the measured dlopen set and fails the build on an unresolved soname or a binary that needs a newer glibc than the rootfs.

The runtime target must not be published yet: NVRTC opens cuda_runtime.h, cooperative_groups.h and math_constants.h, which Attachment A of the CUDA EULA does not list. The GB10 smoke record, the x86_64 GLIBC_2.43 finding and the measured file lists are in docs/benchmark_results/docker-cuda-smoke-gb10-2026-11-29.md.

Refs #3484
The /health 503 never appeared because mlxcel-server binds only after load and warmup, which the server log shows; say so instead of blaming the poll interval. Rename the timing column to what was measured (a full non-streaming chat response), note that the header trace ran in a cudnn-devel probe container, and mark the release runners' CUDA minor, the distroless cc-debian13 glibc and the Ubuntu 26.04 amd64 path as unverified.

Refs #3484
Since #3540 the NVRTC JIT reads only the CUDA headers in scripts/ci/nvrtc_header_allowlist.txt, so the runtime target can carry them. The image now copies exactly that list into /usr/local/cuda/include (docker/copy-cuda-headers.sh, no second list) and the build fails if any other file is there; docker/copy-cuda-headers_test.sh covers the guard in CI.

The CUDA and cuDNN libraries and headers now come from NVIDIA's CUDA apt repository, signature-checked against pinned key fingerprints and unpacked without installing, instead of being copied out of an nvidia/cuda image, whose container license allows a derived image only when it includes the whole container. Package versions are recorded in /opt/mlxcel/share/cuda-packages.txt. The debug target stays the whole cudnn-devel image.

amd64 now defaults to Ubuntu 26.04 with CUDA 13.5, matching the x86_64 release runner (its binaries need GLIBC_2.43); arm64 stays on Ubuntu 24.04 with CUDA 13.0. NOTICE records the CUDA and cuDNN distribution basis and the bundled CCCL and CUTLASS headers; README and docs/installation.md describe the image and its readiness behavior.

Refs #3484
Rewrite the GB10 record for a build of main at 15e6395 (includes #3508, #3509 and #3540). A cold-cache Qwen3-4B-4bit generation inside the runtime image under strace opened 11 CUDA toolkit headers, all in the allow-list, and succeeded; the server smoke (uid 65532, chat completion, CLI generate, docker stop drain, PTX cache reuse on a named volume, a root:root 0777 bind mount and a private-group 2775 bind mount) passed again. The record also states the license basis, the amd64 cross builds on Ubuntu 26.04 with CUDA 13.5, and what was not run.

Refs #3484
@inureyes inureyes added status:review Under review type:enhancement New features, capabilities, or significant additions priority:medium Medium priority platform:linux Linux (CUDA / packaging) specific labels Nov 28, 2026
@inureyes

Copy link
Copy Markdown
Member Author

Implementation Review Summary

Intent

Ship a shell-less, non-root CUDA runtime image (plus a debug image) of the release binaries for amd64 and arm64, carrying only redistributable NVIDIA files and exactly the allow-listed NVRTC headers (#3484).

Static review only; no image was built for this review. No CRITICAL or HIGH findings, so nothing was changed on the branch.

Findings Addressed

None needed.

Remaining Items

  • OpenBLAS (BSD-3-Clause), libgfortran5 (GPL-3.0 with the GCC Runtime Library Exception) and, on amd64, libquadmath0 are unpacked from Ubuntu debs and only their .so files are copied, so their /usr/share/doc/<pkg>/copyright files are dropped and NOTICE does not name them. Chisel slices carry their own copyright files; these three do not. Worth adding to the owner license review: either copy the copyright files (libgfortran5's doc dir is a symlink to gcc-N-base, which is not downloaded) or record them in NOTICE. (MEDIUM)
  • Closes #3484 will close the issue on merge while two acceptance items stay open: the x86_64 CUDA host run and the combined two-platform build. Consider Refs #3484 or a follow-up issue for the amd64 run. (MEDIUM)
  • .dockerignore matches the issue's list and admits every COPY source (docker/, scripts/ci/nvrtc_header_allowlist.txt, LICENSE, NOTICE), but as a deny-list it still sends ignored trees such as webui/node_modules/ and local scratch dirs (4.3 GB .work/ on one dev checkout). An allow-list (* then !docker/, !scripts/ci/nvrtc_header_allowlist.txt, !LICENSE, !NOTICE) would keep the context to what the Dockerfile reads. (LOW)
  • AMD64_CUDA_VERSION / ARM64_CUDA_VERSION patch levels pin only the debug base tag; the runtime apt download takes the newest *-13-0 / *-13-5 packages, so the two targets can differ in CUDA patch level. cuda-packages.txt records what was taken. (LOW)
  • The runtime image sets no NVIDIA_REQUIRE_CUDA, so a driver too old for CUDA 13.5 fails at first CUDA call instead of at container start; the debug image inherits it from the base. (LOW)
  • Small shell robustness gaps that later checks already catch: copy-cuda-headers.sh --check passes on a nonexistent directory; the dpkg-deb -x loop in cuda-debs is piped into sort under sh without pipefail; an empty inc would cp -a /.; for pattern in ${DLOPEN_LIBS} globs against the cwd. (LOW)
  • Wording: NOTICE calls the debug target the "unmodified" cudnn-devel image although /etc/passwd and /etc/group gain one line each; docs/installation.md says "since v0.9.0" where only betas were measured, does not list CUDNN_VERSION, CHISEL_VERSION or MLXCEL_RELEASE_URL, and its example auto-downloads into an empty volume while the record used a pre-populated bind, so the in-container download path is unmeasured. (LOW)

Verification

  • All stated requirements implemented (amd64 container run and two-platform build recorded as not run)
  • No placeholder/mock code remaining
  • Integrated into project code flow (header guard test wired into the CUDA architecture lists CI job; README and installation guide link the image)
  • Project conventions followed (license headers, executable bits, record under docs/benchmark_results/, same-repo refs only)
  • Existing modules reused where applicable (header set read from scripts/ci/nvrtc_header_allowlist.txt, no second list)
  • No unintended structural changes
  • Tests pass: the new docker/copy-cuda-headers_test.sh step passes in CI and shellcheck is clean; binary assets fails on tests/fixtures/audio/speech.flac, which comes from feat(models): add LiquidAI d1-omni (d1_omni) decision model #3533 on main and is not touched by this PR

Checked and fine: keyring fingerprint pin (primary keys only, both repos), cross-arch apt setup in both cuda-debs and the OpenBLAS step, chisel --arch, the readelf closure and glibc/GLIBCXX guard, the copy-then-walk header guard (symlinks and non-regular entries refused), env/volumes/user matching the issue contract and the docs, both default nvidia/cuda base tags exist on Docker Hub, and the CCCL v3.1.3 / CUTLASS v4.4.2 versions in NOTICE match upstream MLX's CUDA CMake.

Review follow-ups for the CUDA image. OpenBLAS, libgfortran5 and libquadmath0 are unpacked from Ubuntu debs, which dropped their Debian copyright files; the image now carries them under /opt/mlxcel/share/copyright (from the gcc base package where the library's doc directory is a symlink), the build fails if one is missing, and NOTICE names them. NOTICE no longer calls the debug target unmodified.

Build steps now fail instead of continuing on a failed deb extraction, an empty CUDA include directory, or a --check of a missing directory, and DLOPEN_LIBS globs are no longer expanded against the current directory. .dockerignore also excludes .work/ and node_modules/. The docs state that the CUDA patch level pins only the debug base, list the remaining build arguments, and note that an in-container model download was not measured.

Rebuilt on GB10: amd64 runtime from v0.9.0-beta.3 and arm64 runtime from v0.8.1 (both cache-only).

Refs #3484
The image sets HOME=/cache, and the model resolver probes the HuggingFace cache at $HOME/.cache/huggingface/hub without owner or mode checks and before the /models store. On a world-writable /cache bind, which the guide gave as its example, another host uid can plant a snapshot that -m owner/name loads instead of the model in /models. MLXCEL_CACHE_TRUSTED_ROOT keeps the PTX cache safe on such a mount, but its threat model does not cover the HF cache.

The guide now recommends a bind owned by 65532 (0700) or a private group with 2775, and says why a 0777 bind should be avoided on shared hosts. Named volumes are unaffected. Docs only; the resolver itself is unchanged.

Refs #3484
@inureyes

Copy link
Copy Markdown
Member Author

Security and performance review

Static review only (no docker build). One HIGH finding, fixed in docs by 3e2b7e8; no CRITICAL findings.

Addressed

  • HIGH: docs/installation.md suggested a root:root 0777 bind for /cache. The image sets HOME=/cache, and the resolver probes $HOME/.cache/huggingface/hub (src/downloader/store.rs, hf_cache_snapshot) with no owner or mode check, ahead of the /models store (resolver step 2b before 2c). On a world-writable /cache, another host uid can plant a snapshot that -m <owner>/<name> loads instead of the model in /models (weights, config, tokenizer and chat template substitution; no code execution shown). The trusted-root rule from fix(cuda): let the PTX disk cache trust a container volume root #3503 covers only the PTX cache. The guide now recommends a 65532-owned 0700 bind or a private group with 2775 and explains why to avoid 0777. Named volumes are not affected. A durable fix belongs in a follow-up: either set HF_HUB_CACHE to a path under an owner-checked directory in the image (changes the feat(docker): Add CUDA container image with mlxcel and mlxcel-server #3484 env contract and the unmeasured in-container download path, so it needs a GB10 re-run), or owner-check HF cache snapshots in the resolver.

Remaining (not fixed, below the fix threshold)

  • MEDIUM: the release zips are checked against a .sha256 from the same release, and the chisel tarball against a .sha384 from the same release. That proves integrity, not authenticity. CHISEL_VERSION is pinned, so its sha384 can be pinned in the Dockerfile. For the mlxcel zips, an optional MLXCEL_SHA256_* build arg or GitHub artifact attestations (the release workflow publishes none today) would add a pin from outside the release.
  • MEDIUM: the docs example -p 8080:8080 publishes a server with no API key on every host interface. 0.0.0.0 inside the container is part of the image contract, but the example could use -p 127.0.0.1:8080:8080 or mention LLAMA_API_KEY / --api-key-file. Settings and router endpoints already refuse non-loopback without a key; inference does not.
  • LOW: sha256sum -c verifies the file named inside the .sha256, not ${asset}.zip. Release files use bare names (release.yml:755), so this matters only for MLXCEL_SOURCE=local; comparing the hash against the expected file name would remove the gap.
  • LOW: nvidia/cuda and ubuntu bases are pinned by tag rather than digest, and only cuDNN is version-pinned among the NVIDIA packages (cuda-packages.txt records what was taken).
  • LOW: mtp-policy hints under /cache/mlxcel are read without an owner check. They are performance hints only.

Checked and fine

The NVIDIA keyring check compares every primary key against fingerprints pinned in the Dockerfile, and apt trusts only the CUDA repo in that stage. The Ubuntu archive is reached through the signed ubuntu.sources. The header guard rejects symlinks, non-regular files, .. entries and unlisted files, and its test covers each case. The runtime has uid 65532, no shell, a 1777 /tmp, and /cache and /models owned by 65532. The trusted root sits one level above MLXCEL_CACHE_DIR. No stage in the runtime target pulls the devel image. The 2.82 GB arm64 size comes mostly from keeping every cuDNN sub-library, a documented choice.

The container example in docs/installation.md published the port on every interface while the server has no API key by default. It now uses -p 127.0.0.1:8080:8080 and says to set LLAMA_API_KEY or pass --api-key-file before exposing it elsewhere.

The image layout line listed only /opt/mlxcel/{bin,include}, and the smoke record listed /opt/mlxcel/share without the copyright directory that the Dockerfile fills with the OpenBLAS Debian copyright files. Both now match docker/Dockerfile.cuda.

Validation: shellcheck is clean on the three docker scripts, check_cross_repo_refs.py lists only lablup/mlxcel issue numbers, insert_apache_header.py --check, check_env_var_docs.py, check_nvrtc_headers.py and the benchmark and report layout checks pass, and every relative link in the changed docs resolves.

Refs #3484
The literal two-platform build from the issue (v0.8.1, linux/amd64 and linux/arm64) now builds for both the runtime and debug targets on GB10, cache-only, which also pulls the new amd64 debug base (13.5.0 on Ubuntu 26.04) for the first time. The record now says the GPU runs used the image from before the review follow-ups, so the copyright directory and hardened steps were only built, not run. NOTICE limits the NVIDIA-GPU-only clause to the CUDA EULA, the one agreement where it was read.

Refs #3484
@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 28, 2026
@inureyes
inureyes marked this pull request as ready for review November 28, 2026 23:02
@inureyes
inureyes merged commit 66c1329 into main Nov 28, 2026
32 of 33 checks passed
@inureyes
inureyes deleted the feature/issue-3484-cuda-container-image branch November 28, 2026 23:02
inureyes added a commit that referenced this pull request Nov 28, 2026
## Summary

Adds `charts/mlxcel`, a Helm chart for `mlxcel-server` on a GPU node, plus a `helm-chart` CI job. One replica, `Recreate`, Service, optional Ingress, PDB and ServiceMonitor, PVCs for `/models` and (optionally) `/cache`. Three model modes: `hf` (a `download` initContainer, the default), `pvc` (snapshot already under `/models`) and router (`--models-dir`, `--models-max`); other combinations fail rendering with a message naming the value.

## Decisions beyond the issue text

- Default `model.source: hf`, so a default install works on an empty volume. The server always runs with `--offline` in model mode: only the initContainer fetches, `HF_TOKEN` never reaches the server, and `--revision` goes to the download only (a revision-qualified `-m` skips the `/models` store in the resolver).
- `HF_HOME`/`HF_HUB_CACHE` point into `/models/.huggingface`, closing the #3543 finding that `HOME=/cache` makes the resolver read `/cache/.cache/huggingface/hub` before `/models` without an owner check.
- `MLXCEL_CACHE_DIR=/cache/mlxcel` under the trusted root `/cache`, `fsGroup: 65532`, `fsGroupChangePolicy: OnRootMismatch`. No root container and no values switch for one; the container security context is fixed.
- The download initContainer inherits the server's `resources` (GPU limit) because the binary links the NVIDIA driver library; kubelet reuses init-container devices for the server.
- `enableServiceLinks: false` (a release named `mlxcel` would inject `MLXCEL_*` variables), `automountServiceAccountToken: false`, and `extraEnv` may not repeat a chart-set name (server-side apply rejects duplicates).
- Router mode with `model.hfToken` requires `apiKey.existingSecret` (the router's `POST /models` and `DELETE /models` are open without a key); `podSecurityContext` rejects uid, gid or `fsGroup` 0 even with schema validation skipped.
- Files outside `charts/**`: a one-line pointer in `docs/installation.md`, `scripts/ci/check_helm_chart.py` (template matrix, kubeconform, invariants, rejection cases), `scripts/ci/check_helm_chart_kind.sh` (restricted Pod Security admission with a negative control), and the record `docs/benchmark_results/helm-chart-kind-2026-11-29.md`.

## kind findings (kind v0.33.0, Kubernetes v1.37.0)

- emptyDir root `2777 0:65532`; kind `local-path` PVC root `777 0:0` (a hostPath PV, kubelet applies no `fsGroup`); hand-made `local` PV root `2775 0:65532`.
- On the `local` PV, `Always` relabeled the server-style entries on remount to `2770` dirs and `660` files; `OnRootMismatch` kept `2700`/`600`. The cache rules refuse group-writable directories and entries below the trusted root, so `Always` would disable the cache from the second pod on (from the source, not observed with the server).

## Changes during review

- The `helm-chart` job installs PyYAML with `uv pip`: the chart-testing action puts a pip-less venv first on PATH, which failed the first CI run.
- The router API-key requirement and the root-group rejection above came from the security review. The cache guidance in `values.yaml` and the README now warns against same-uid workloads on the cache volume (they pass the owner checks), not other uids (which can only turn the cache off).

## Test plan

- [x] `helm lint --strict` (default and every `ci/*-values.yaml`) and `ct lint` (chart-testing v3.15.0) pass
- [x] `scripts/ci/check_helm_chart.py` passes under Helm 4.3.2 and Helm 3.16.4, kubeconform v0.8.0 strict with the ServiceMonitor CRD schema
- [x] `scripts/ci/check_helm_chart_kind.sh` on kind: default (hf), hf, pvc and router releases admitted under `enforce=restricted`, control pod rejected
- [x] actionlint 1.7.12 with CI's shellcheck floor
- [x] `helm chart` CI job passes (lint, ct lint, kubeconform, kind install under restricted Pod Security)
- [ ] Not validated: any GPU pod (Ready on Qwen3-4B, no cache refusal line, PTX reuse after restart and pod replacement, cold/warm time to Ready), device reuse from initContainer to server, an in-cluster download. No Kubernetes cluster with a GPU was available.

Closes #3486
inureyes added a commit that referenced this pull request Nov 30, 2026
Bilingual reports for the eight PRs of epic #3488: #3508 (graceful drain), #3509 (CUDA PTX cache trust), #3530 (ROCm hsaco cache trust), #3540 (NVRTC redistributable headers), #3543 (CUDA container image), #3549 (Helm chart), #3550 (GHCR image publishing) and #3554 (chart OCI publishing and docs).

Each report names what the PR record leaves unvalidated: a real GHCR push, a GPU pod on a cluster, the amd64 and debug images. The HuggingFace cache follow-up is #3570.
@inureyes inureyes added this to the 0.9 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform:linux Linux (CUDA / packaging) specific priority:medium Medium priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(docker): Add CUDA container image with mlxcel and mlxcel-server

1 participant