Skip to content

build(docker): let the runtime UID use the image's uv cache offline - #4456

Merged
ko3n1g merged 4 commits into
mainfrom
ko3n1g/build/runtime-uv-cache
Oct 6, 2026
Merged

ko3n1g merged 4 commits into
mainfrom
ko3n1g/build/runtime-uv-cache

Conversation

@ko3n1g

@ko3n1g ko3n1g commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Background / motivation

  • Goal: run NeMo RL's L0/L1 scripts air-gapped under the unprivileged runtime UID (65532) that the release image already prepares for. NeMo CI agents run rows this way on gcp-h100: no egress, UV_OFFLINE=1, UV_CACHE_DIR=/opt/nemo_rl_cache/uv.
  • The image ships every wheel the venvs were built from, but non-root code cannot use them:
    • The cache is at /root/.cache/uv, and /root is drwx------ (checked in the release image's layer tar).
    • /opt/nemo_rl_cache/uv is created empty for UID 65532 (install -d in the runtime-UID block).
    • Only the venv top directories are chowned, so site-packages stays root-owned.
  • uv refuses to start with a cache it cannot write. Reproduced with uv 0.11:
    error: Failed to initialize cache at `.../cache`
      Caused by: failed to open file `.../cache/sdists-v9/.git`: Permission denied (os error 13)
    
  • The final uv sync --frozen --all-groups --no-install-project is exact, so the main venv holds no backend extra.
  • Result: as non-root and offline, every uv run --extra <backend> shard fails before pytest starts:
    • uv run --extra mcore|automodel|vllm|sglang|trtllm|modelopt|nemo_gym
    • Megatron_1-4, Megatron_Policy_1-3, Automodel*, Vllm_*, Sglang, Trtllm, Nemo_Gym
  • So does every plain uv run that has to re-install the editable project from another checkout path.

What changed

  • docker/Dockerfile: one uv cache, UV_CACHE_DIR=/opt/nemo_rl_cache/uv, for the build and every runtime identity. The layers that fill the cache hand it, and the venvs built from it, to RUNTIME_UID:RUNTIME_GID.
  • docker/Dockerfile: a build-time probe, as the runtime UID, that uv opens the cache and checks the venv offline.
  • .github/workflows/cicd-main.yml: the uv-cache export copies from the new path.
  • ray.sub and docs/cluster.md: UV_CACHE_DIR_OVERRIDE mounts at the container cache path, overridable with CONTAINER_UV_CACHE_DIR.

Details

  • No layer duplication. Ownership is set in the layer that creates the data:
    • The dependency layer runs chown -R over the cache, /opt/nemo_rl_venv and /opt/ray_venvs at the end of the same RUN. The venvs are hardlinked against the cache, so each inode changes owner once and nothing is copied up.
    • The TRT-LLM and release-stage prefetch layers chown only the root-owned entries they add (find … -uid 0). Earlier entries already belong to the runtime UID, so nothing is copied up there either.
  • Root behaviour is unchanged. The image still defaults to root, and root reads and writes the same cache.
  • Build cache seed. The uv-cache-seed rsync now targets ${UV_CACHE_DIR}. Seeds exported from older images (/root/.cache/uv contents) still apply, because only the destination moved.
  • Builder-local caches stay in /root/.cache. These are the TRT-LLM wheel and ccache mounts. They are never part of the image.
  • Runtime-UID probe (runtime-UID block):
    • uv cache dir equals UV_CACHE_DIR;
    • the runtime UID owns the cache and the main venv's purelib;
    • UV_OFFLINE=1 uv sync --frozen --inexact --no-install-project --no-install-workspace succeeds. That is the lock check every offline uv run does first.
  • ray.sub: images built before this change ignore the new mount target and keep using their own /root/.cache/uv, so nothing breaks; the override just has no effect on them.

Tested

  • docker buildx build --check -f docker/Dockerfile .: no warnings.
  • bash -n ray.sub: OK.
  • pre-commit run --files docker/Dockerfile .github/workflows/cicd-main.yml ray.sub docs/cluster.md: passed.
  • Root cause evidence:
    • The release image rl@sha256:b50ada68… (main fb8396ada) has /root at drwx------ 0/0 and the populated cache under /root/.cache/uv. /opt/nemo_rl_cache/uv is only created empty, in the final layer.
    • uv 0.11 refuses a cache it cannot write (error above).
  • H100 container build: CI run 37107298972, job Build H100 container / build passed. The image is rl:37107298972 (sha256:cce5f46a…).
    • The same run's L0_Unit_Tests_Other has 1 failure, 2973 passed: test_single_controller_actor.py::test_opd_advantage_stage_pools_raw_gap_separately_under_tropd (AttributeError: 'SingleControllerActor' object has no attribute '_train_data_dump'). main fb8396ada fails the same test the same way (run 37111913568), so it is not from this change.
  • Air-gapped run on this image. NeMo CI cluster e2e test lane 990000000003/1 on gcp-h100: isolated rank (no egress), repository profile nemo-rl v8 (digest f6c3757d…), image rl@sha256:cce5f46a… built from build(docker): let the runtime UID use the image's uv cache offline #4456 (rl:37107298972), source ko3n1g/fix/offline-test-execution @ 40467c738 (build(docker): let the runtime UID use the image's uv cache offline #4456 + fix(test): keep test-suite dry runs from installing audio deps #4461 on main fb8396ada), 2 GPUs per shard:
    • L0_Unit_Tests_Other: 2973 passed, 1 failed, the same pre-existing main failure. The editable nemo-rl rebuilt offline (Built nemo-rl @ file:///mnt/checkpoint-workspace/RL), and automodel_env was created offline from the image's uv cache (256 packages). On the baseline image rl@sha256:b50ada68… this shard stopped before pytest: the offline editable rebuild could not find setuptools.
    • L0_Unit_Tests_Automodel: passed, 263 passed, 15 skipped.
    • L0_Unit_Tests_Vllm_1: passed, 136 passed, 26 skipped.
    • L0_Unit_Tests_Nemo_Gym: 146 passed, 1 error in test_nemo_gym.py::test_nemo_gym_sanity. NeMo Gym creates each server venv at runtime with seed packages, and offline uv finds no pip in the cache (Because pip was not found in the cache … the network was disabled), so example_multi_step_resources_server exits. The image only prefetches Gym venvs when NEMO_GYM_PREFETCH_CONFIGS is set, and it is empty by default. That is a separate gap, not part of this change.
    • Cleanup: every row and the inventory were cancelled and verified gone, and the Session's headless listing and GPU occupancy both read 0.

🤖 Generated with Claude Code

The release image ships a complete uv cache, but at /root/.cache/uv,
which /root's 0700 mode hides from the unprivileged runtime UID (65532)
the image already prepares for. The /opt/nemo_rl_cache/uv directory that
UID is given is empty, and the venvs' site-packages stay root-owned.
uv refuses to start with a cache it cannot write, so a non-root
`uv run --extra <backend>` (every Megatron, Automodel, vLLM, SGLang,
TRT-LLM and Gym unit shard) cannot install the extra without network.
The final `uv sync --all-groups` is exact, so no extra is preinstalled.

- Set UV_CACHE_DIR=/opt/nemo_rl_cache/uv for the build and the runtime.
- Chown the cache and the venvs to RUNTIME_UID in the layers that create
  them. The venvs are hardlinked against the cache, so this changes each
  inode's owner once and copies nothing; later layers only chown the
  root-owned entries they add.
- Probe at build time, as the runtime UID, that uv opens the cache and
  checks the venv offline.
- Point the CI uv-cache export and ray.sub's UV_CACHE_DIR_OVERRIDE mount
  at the new path.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: oliver könig <[email protected]>
@ko3n1g ko3n1g added the CI:L0 Run doctests and unit tests label Oct 3, 2026
@copy-pr-bot

copy-pr-bot Bot commented Oct 3, 2026

Copy link
Copy Markdown

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@ko3n1g

ko3n1g commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 5285a9c

@github-actions github-actions Bot added Documentation Improvements or additions to documentation CI Relating to CI labels Oct 3, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team October 3, 2026 07:44
@ko3n1g

ko3n1g commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 52b23d9

@kajalj22

kajalj22 commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

/review

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — no high-confidence actionable findings in this light review.

Inspected all four changed files and traced the affected cache seeding/export, worker-venv setup, and Slurm mount paths. The new cache location is consistent across the image, CI exports, and documented override.

Static inspection only; Docker builds, offline runtime-UID probes, and Slurm launches were not executed.

Review generated by codex

@kajalj22

kajalj22 commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

LGTM pending nightly pipeline runs without any issues

@ko3n1g

ko3n1g commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 52b23d9

@ko3n1g

ko3n1g commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

pipeline-id 71769204

@ko3n1g
ko3n1g merged commit 222b06a into main Oct 6, 2026
75 checks passed
@ko3n1g
ko3n1g deleted the ko3n1g/build/runtime-uv-cache branch October 6, 2026 11:35
kajalj22 added a commit that referenced this pull request Oct 19, 2026
Pulls in 594 commits from main, including PR #4456 which independently
moved the uv cache to /opt/nemo_rl_cache/uv for RUNTIME_UID offline
installs. Reconciles the two designs: the BuildKit cache mount now
materializes into UV_CACHE_DIR instead of /root/.cache/uv, and a new
STRIP_UV_CACHE build-arg (default off) lets size-sensitive builds opt
into deleting the materialized cache from the final image while
keeping it for main/nightly.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Signed-off-by: Kajal Jain <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:L0 Run doctests and unit tests CI Relating to CI Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants