Repository navigation
build: export uv cache via a BuildKit cache mount; add opt-in STRIP_UV_CACHE - #4340
Conversation
The uv cache is written to a plain persisted directory in the hermetic stage, so it rides all the way into the shipped release image (~9GB amd64 / ~5GB arm64 of dead build-time cache with zero runtime use). Move it to a BuildKit cache mount, same pattern TRT-LLM's ccache/wheel cache already use: the cache never lands in any image layer, and a new uv-cache-export stage (mirroring trtllm-ccache-export) republishes it as its own scratch image for the next build's warm start. Update the uv-cache refresh job accordingly -- it now builds the uv-cache target directly instead of docker cp-ing /root/.cache/uv out of the shipped release image. Signed-off-by: Kajal Jain <[email protected]>
|
/ok to test eebf511 |
|
/review |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
The separate cache-export target is a reasonable approach, but the cache-mount conversion is incomplete and breaks the existing hardlink-based image layout. There is also a deterministic regression in the Megatron lockfile workflow caused by the duplicate UV_VERSION default. These should be fixed before merging. Review was static; container builds and CI tests could not be executed in this read-only environment.
Review generated by codex
Follow-up to the review findings on this PR (hardlink breakage across the mount boundary, cache not shared with the TRT-LLM/Dynamo/Gym RUNs, and a duplicate ARG UV_VERSION default breaking prepare-megatron-lock). - Retarget the uv cache mount to /root/.uv-cache-store (self-seeded via from=uv-cache-seed, mirroring trtllm-wheel-cache) and materialize a plain /root/.cache/uv copy at the start of every RUN that invokes uv (dependency install, TRT-LLM build, Dynamo install, worker-venv prefetch phase 2, Gym prefetch), synced back and deleted via a bash EXIT trap before each RUN's layer commits. This keeps hardlink-based installs working exactly as before (same filesystem throughout each RUN) while still never shipping the download cache itself. - Drop the now-unnecessary CACHE_KEY/.cache-key comparison machinery -- BASE_IMAGE/UV_VERSION/TARGETARCH are now part of the cache mount id itself, so a version or base-image bump naturally gets a fresh cache instead of relying on a manually-computed key. - Fix the duplicate ARG UV_VERSION=0.11.28 default in uv-cache-export by redeclaring it bare (inheriting base's value), matching the existing pattern the hermetic stage already uses. - Move uv-cache-seed resolution into _build_container.yml with an existence check (docker buildx imagetools inspect), mirroring resolve_seed() for the TRT-LLM caches, instead of unconditionally wiring an image ref that may not exist yet. Still not build-tested (no docker daemon available) -- this is exactly what the PR's test plan checklist covers before merge. Signed-off-by: Kajal Jain <[email protected]>
|
/ok to test 42a1544 |
|
/review |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
The cache export is now separated from the release image, and the temporary in-layer cache addresses cross-mount hardlinking. Two issues remain: registry seeds bypass the previous compatibility check, and removing CACHE_KEY breaks an existing unit test. Review was static; Docker builds and tests were not executed.
Review generated by codex
Addresses the second automated review round on this PR plus the L0_Unit_Tests_Other CI failure from the last push. - Key the uv registry cache seed tag by BASE_IMAGE/UV_VERSION/ HYBRID_EP_MULTINODE (sha256, mirroring the TRT-LLM ccache/wheel-cache tags), via a new "Resolve uv cache configuration" step in _build_container.yml. Previously the seed was a flat, unversioned :uv-cache tag, so a base-image bump would create a fresh local cache mount (new id) but still import a registry seed built against the old base image -- exactly the staleness the removed CACHE_KEY check used to catch, just via a different mechanism. - Promote HYBRID_EP_MULTINODE from a hardcoded `hermetic`-stage ENV to a global ARG (default 1), redeclared bare wherever the cache mount id needs it (hermetic already had BASE_IMAGE/UV_VERSION; now release and uv-cache-export do too). The ENV line itself stays a literal `ENV HYBRID_EP_MULTINODE=1` -- tests/unit/tools/test_docker_hybridep_build.py asserts that exact line. - That same test asserted the now-removed `CACHE_KEY=` line existed and referenced BASE_IMAGE/UV_VERSION/HYBRID_EP_MULTINODE. Updated it to check the equivalent invariant on the new mount `id=` line instead, preserving the single-node-vs-multi-node DeepEP wheel safety check it exists for. Verified locally (no pytest needed -- the test only reads the Dockerfile as text). Signed-off-by: Kajal Jain <[email protected]>
|
/ok to test 9d743b5 |
|
/review |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
The cache export is now separated from the release image, and the materialized working cache preserves same-filesystem hardlink installs. One configuration mismatch remains: overriding HYBRID_EP_MULTINODE makes the build and exporter use different cache mounts. The updated text-based regression test does not cover this behavior. Review was static; Docker builds and tests were not executed.
Review generated by codex
Addresses an unaddressed review comment (discussion on
docker/Dockerfile:645): the hermetic stage's ENV HYBRID_EP_MULTINODE=1
was a hardcoded literal, which takes precedence over the ARG for
${...} expansion in that stage and everything derived from it
(hermetic, release). uv-cache-export (FROM base, no such ENV)
correctly expanded the real ARG value. So a non-default
--build-arg HYBRID_EP_MULTINODE=0 build would populate its cache
mount under id ...-1 (from the 5 writer RUNs) but export/tag under
...-0 -- silently exporting an empty/stale cache under a key that
never matches what was actually built. No current CI path sets this
build-arg (both sides already agree at the "1" default), but it's a
real bug, not a hypothetical.
Fix: ENV HYBRID_EP_MULTINODE=${HYBRID_EP_MULTINODE} (pass-through),
matching how BASE_IMAGE/UV_VERSION are already handled. Updated
tests/unit/tools/test_docker_hybridep_build.py's literal-line
assertion to match (docker/Dockerfile.ngc_pytorch, which has no
cache-mount-id mechanism, keeps the old literal). Also hardened the
test's cache-mount check: it previously used next() to inspect only
the FIRST of 6 identical --mount=type=cache,id=uv-cache-... lines, so
a future copy-paste drift in any of the other 5 wouldn't have been
caught -- now every occurrence is checked and their id= segments must
all be identical. Verified locally (no pytest needed, pure text
assertions against the real Dockerfile).
Signed-off-by: Kajal Jain <[email protected]>
|
/ok to test 24d82e7 |
|
/review |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
No merge-blocking defects found in the revised change. The uv cache mount identity is consistent across writers and export, the registry seed is keyed by architecture and build configuration, and same-layer hardlink installs are preserved before cache cleanup. The redundant UV_VERSION default is also avoided.
Reviewed the changed files and relevant installation/prefetch callers against the base tree. Validation was static only; Docker builds and tests were not executed. End-to-end checks should still confirm release image size, retained hardlink sharing, and warm-start behavior on a fresh builder.
Review generated by codex
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]>
c436c57
Co-Authored-By: Claude Sonnet 5 <[email protected]> Signed-off-by: Kajal Jain <[email protected]>
|
/ok to test e8e82c2 |
|
/review reset=true |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
Review: PR #4340
The separate cache-export target and configuration-keyed registry seed are useful improvements. The earlier non-default HybridEP mismatch is fixed by the ARG-to-ENV passthrough.
A fresh review of all four changed files found one stripped-build size regression requiring correction and one regression-test suggestion, detailed inline.
Validation was static only: Docker builds, pytest, and pre-commit were not executed. Findings carry this reviewer's source verification only; suggested edits and acceptance checks require author verification.
Note: formal approval is not available for this request, so this review is posted as a comment only.
Review generated by codex
|
/ok to test 2320d60 |
|
/review reset=true |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
Review: PR #4340
No action needed — no high-confidence actionable findings were established in this fresh static review.
The latest review findings are resolved in the current source:
- The default-retention test now rejects nonempty argument defaults and checks the helper’s cache deletion, including a nonempty-match assertion.
- The shared shell helper has the required copyright and license header.
Inspected all six changed files and traced the directly affected cache lifecycle, build/export workflow, installation, prefetch, and regression-test paths. Earlier ownership-handoff, mount-identity, and nightly-dependency corrections remain present.
Validation was source-only. Docker builds, pytest, pre-commit, and workflow execution were not performed; this result carries only this reviewer’s source verification.
Review generated by codex
Review generated by codex. This was a full review. Request a full review with /review reset=true.
|
/ok to test 5aaa616 |
Signed-off-by: Kajal Jain <[email protected]> # Conflicts: # docker/Dockerfile
|
/ok to test cb5a03e |
|
/review |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
Review: PR #4340
No action needed — no qualifying findings in this follow-up.
The previously verified fixes remain present: the retention regression test rejects nonempty defaults and checks helper deletions, and the shared helper retains its license header and guarded stripping behavior.
Compared all six changed files with the previous reviewed head. Five are byte-identical; the Dockerfile adds system-library installation inside the existing Gym-prefetch gate. Three delegated inspections and parent verification covered the affected prefetch, cache, workflow and regression-test contracts without establishing an introduced regression.
Validation was source-only. Docker builds, pytest, pre-commit and workflows were not executed. Gym submodule source was unavailable, so its import-time behavior was not independently verified.
Review generated by codex
Review generated by codex. This was a findings-only review. Request a full review with /review reset=true.
Resolves the docker/Dockerfile conflict with NVIDIA-NeMo#4340 (uv cache mounts). The BUILD_DYNAMO RUN keeps this branch's form: docker/dynamo/install.sh now only downloads etcd and nats-server, so it is not a uv-writing RUN and takes no uv cache mount. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
main (#4340) replaced the update-uv-cache jobs with an in-build cache mount and seed export, so this branch drops its workflow change and takes main's. - Prune right after `uv_cache_restore force`, before any sync; the RUN's `uv_cache_persist prune` trap mirrors the result into the cache mount. - Dynamo keeps its throwaway UV_CACHE_DIR, so its RUN no longer needs the cache mount or the restore/persist helpers. - Placement test and docs updated for the new flow. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Kajal Jain <[email protected]>
main (#4340) replaced the update-uv-cache jobs, so retarget the test at the new mechanism: both builds use the uv-cache-test tag prefix, and the "Update uv cache image" step also runs on this PR. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Kajal Jain <[email protected]>
Summary
--mount=type=cache) instead of a plain directory, mirroring the pattern already used for the TRT-LLM ccache/wheel-cache in this Dockerfile. Content on a cache mount is never part of any image layer.UV_LINK_MODE=hardlinkinstalls materialize a plain same-filesystem copy of the cache atUV_CACHE_DIR(/opt/nemo_rl_cache/uv) at the start of eachuv-writingRUN(dependency install, TRT-LLM build, Dynamo install, worker-venv prefetch phase 2, Gym prefetch), and sync new downloads back to the cache mount via a bashEXITtrap before thatRUN's layer commits.uv-cache-export/uv-cachestage pair that republishes the cache mount's contents as its own small registry image, keyed bysha256(BASE_IMAGE-UV_VERSION-HYBRID_EP_MULTINODE)(mirroring the TRT-LLM cache tag scheme), so the next build can still warm-start from it._build_container.yml's "Resolve uv cache configuration"/"Resolve uv cache seed" steps compute and existence-check that tag before wiring it in, and "Update uv cache image" refreshes it onmainafter each build.STRIP_UV_CACHEbuild-arg (default off) controls whether the materialized cache ships in the final image. Off by default, somain/nightly builds keep the cache inUV_CACHE_DIR, preserving the RUNTIME_UID's ability to runuv run --extra <backend>fully offline. Size-sensitive builds (e.g. nemotron, built elsewhere) can pass--build-arg STRIP_UV_CACHE=1to delete the materialized cache from every uv-writing layer instead.Goal
Stop the uv download cache from being duplicated across every layer of the image by construction (the actual root cause of the nightly image bloat), while giving callers an explicit choice between keeping the cache in the final image (default, needed for offline installs) or stripping it out for a smaller image — with zero change to install behavior (hardlink sharing across venvs), the registry-backed warm-start cache for future builds, or GitHub Actions' separate BuildKit registry layer-cache (
cache-from/cache-to).Measured image size impact
H100 release image, compressed registry size (
docker buildx imagetools inspect --raw, summed layer + config sizes):STRIP_UV_CACHEoff, uv cache kept)--build-arg STRIP_UV_CACHE=1main(46,216,845,028 vs 46,238,403,941 bytes onmain), confirming this PR introduces no regression in the default (cache-kept) path.STRIP_UV_CACHE=1removes the uv download cache (prebuilt wheel downloads + unpacked archive payloads) from every image layer, since it's only needed during the dependency-install build step, not at runtime — cutting the shipped image by about a third. This option is intended for size-sensitive builds that don't need fully-offlineuv run --extra <backend>.Test plan
docker buildx build --target uv-cache -f docker/Dockerfile .builds successfully standalonedocker buildx build --target release -f docker/Dockerfile .(default args) — confirmUV_CACHE_DIRis present and owned byRUNTIME_UID, anduv run --extra <backend>works offline as the runtime userdocker buildx build --target release --build-arg STRIP_UV_CACHE=1 -f docker/Dockerfile .— confirmUV_CACHE_DIRis empty/absent in the resulting imagedocker run --rm <image> du -sh /opt/nemo_rl_venv /opt/ray_venvs/*before/after this PRbuild-container/build-container-gb200pass withUV_BUILD_CACHE=enabledtests/unit/tools/test_docker_hybridep_build.py::test_docker_images_build_deepep_with_multinode_hybrideppassesmain:Update uv cache imagestep succeeds and refreshes the keyed:uv-cache-<arch>-<key>taguv synclogs for cache hits)🤖 Generated with Claude Code