Repository navigation
perf: Dblanaru/persistent compile caches - #4715
Conversation
3da271d to
d5b40fb
Compare
d5b40fb to
b278235
Compare
There was a problem hiding this comment.
Thanks for this, and for the detailed measurements. The write-back design here (add only new files, never overwrite, one writer at a time) is a real improvement over earlier attempts at a shared compile cache, and the cache-key fix sent upstream (vllm#61211) is the right root-cause fix.
Please rebase first: the PR conflicts with main.
We'd like to keep the shared-filesystem design. The comments below are about making it safe at scale, easy to turn on for any node (including nodes that join later), and documented:
- (C4) Replace
NRL_VLLM_CACHE_ROOT_PER_ENGINEwith main's per-engine folder, filled from one sharedpolicy/vllmfolder. - (C17) Forward the cache variable names through the existing
extra_env_varspath instead of rebuildingVLLM_RAY_EXTRA_ENV_VARS_TO_COPYby hand. - (C5) Trainer background copy: a bad script path turns the cache off silently (the lost-kernel bug goes away with C16).
- (C16) Store each cache folder as a few compressed archives instead of thousands of small files, and let every node write back without a lock: a node claims new files with a small intent file before uploading, so the rest skip them.
- (C9) Default each compiler's folder from
NRL_LOCAL_COMPILE_CACHE. - (C18) Fail clearly when
flockis missing. - (C15) A vLLM engine that spans several nodes only gets a seeded cache on the actor's node; needs the start-up hook the description mentions.
- (C11) Clearer names under one
NRL_COMPILE_CACHE_prefix, and movecache_sync.shnext tocompile_cache.pyso its path needs no setting. - (C12) Add the guide, including the interface a Kubernetes/S3 setup can implement.
- (C14) License header and copyright year.
PR description: it describes five commits, including a VLLM_RAY_BUNDLE_INDICES patch, a worker start-up hook, serve_vllm_on_ray.py --apply-patches-only, docs/guides/persistent-jit-caches.md and test_vllm_compile_cache.py. The branch has three commits and none of those. Please update it.
Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-4715-shared-cache-load.html
Generated by Claude Code
331c6dd to
3f05c9c
Compare
|
Re: C16: kept rsync with the cheap fixes, as discussed on Slack; shipping the cache in the image is the longer-term plan. |
External vLLM pools (judges, reward models) compile their kernels into the container's ~/.cache and /tmp, so every job compiles them again. A pool with <POOL>_CACHE_DIR (on the shared filesystem) now copies that directory to node-local disk on every node before Ray starts, points vLLM, TorchInductor, Triton and FlashInfer at the copy (re-applied after the pool's ENV_VARS), and writes new entries back in the background. New tools/external_gym_vllm/ cache_sync.sh (seed, writeback, sidecar): write-back only adds files that are new and unchanged for a minute, never replaces one, and takes turns on a lock. CACHE_FORCE_FRESH=1 starts empty but still writes back. Large multi-node job with three judge pools (vLLM 0.25.1): judges ready about 417 -> 345 s after job start. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DanBlanaru <[email protected]>
…orkers The vLLM and Megatron workers compile their kernels into the container's ~/.cache and /tmp, so every job compiles them again. With NRL_CACHE_SYNC, NRL_COMPILE_CACHE_ROOT and NRL_LOCAL_COMPILE_CACHE set, each worker type uses its own cache, copied onto a node once (cache_sync.sh seed-once, under a node-local lock): the vLLM actor waits for this node's copy of the policy cache before creating its engine, and the Megatron worker copies its cache in the background (its kernels are first compiled at the first training step). NRL_<PREFIX>_<VAR> points each type's TorchInductor, Triton, FlashInfer, CUDA and FlashAttention-4 caches at its copy; NRL_VLLM_CACHE_ROOT_PER_ENGINE=0 keeps VLLM_CACHE_ROOT the same across jobs. A launcher starts the policy copy in its node setup, so it overlaps Ray start-up, and writes back with cache_sync.sh sidecar-types. Nothing changes unless configured. Large multi-node job, warm (vLLM 0.25.1, our fork): setup 426 s with the policy copy started at node setup vs 432 s with the workers copying in the background, and 667 s when every node copies both caches before Ray starts. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DanBlanaru <[email protected]>
…ds a cache With <POOL>_CACHE_DIR set, every node of a replica copies the pool's compile cache before Ray starts, and the head node publishes its IP only after its copy. The other nodes waited 120 s for that IP; on a warm multi-node job with a 1.8 GB cache the head finished ~3 min after the second node, which gave up and ended the job. Wait up to 15 min while a cache is configured. The write-back loops also stop if `sleep` fails (e.g. the container is gone) instead of spinning. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DanBlanaru <[email protected]>
… fixes - Two variables turn the caches on (NRL_COMPILE_CACHE_SHARED_DIR, NRL_COMPILE_CACHE_LOCAL_DIR); compiler folders default under <local>/<type>; NRL_COMPILE_CACHE_<TYPE>_DIR overrides one type's shared folder. Types are vllm and megatron. - cache_sync.sh moves next to compile_cache.py, which finds it there; a missing script, flock or rsync fails at start. - vLLM engines keep their own folder (main's per-engine name), filled from the node's copy; write-back merges them into vllm/vllm. - Before an engine compiles, one Ray task per node of its placement group seeds that node, so multi-node engines are covered. - The cache variables reach vLLM's workers through _apply_vllm_patches. - Copy-in failures only warn; the seed mark is dated at the copy's start; write-back remembers what it sent; the last pass waits for the lock. - docs/guides/persistent-jit-caches.md. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DanBlanaru <[email protected]>
vLLM before 0.31.1 loads compiled artifacts from the absolute path stored in its cache index, so an engine could not load a cache another engine wrote into its own folder (Ultra warm run: "No such file or directory" under another engine's vllm_engines/<n>). The per-node task now applies the upstream fix to the node's vLLM before the engine starts. Remove once vLLM >= 0.31.1. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DanBlanaru <[email protected]>
The Megatron workers compile kernels during setup, not at the first training step, so a background copy could land after them: those kernels missed the cache and their recompiled copies were written back as new files (Ultra warm run: 4,871 new Megatron files). The workers now wait for the copy, which the launcher can start before Ray so the wait is short. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DanBlanaru <[email protected]>
The backport's RuntimeError only fired in a job with persistent caches on; test_relative_artifact_backport checks a hand-written file, so it kept passing when vLLM changed. Add an anchor test next to the other source patches' (marked vllm) that applies it to the installed compilation/compiler_interface.py. new_snippet becomes a plain string so write_unpatched_copy can read it out of the patch source. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DanBlanaru <[email protected]>
3f05c9c to
65e4072
Compare
|
/ok to test 65e4072 |
|
(edit: mistakenly disabled, i've re-enabled i think the plan is still to land this one and circle back with a docker image solution) |
test_worker_initialization_preserves_only_restored_rng runs
MegatronPolicyWorkerImpl.__init__ against a hand-built namespace, so the
new compile_cache.seed("megatron") call raised NameError. Provide it and
check the constructor seeds the Megatron cache once.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: DanBlanaru <[email protected]>
|
/ok to test f490151 |
Title:
perf: persistent JIT compile caches for vLLM, Megatron and external vLLM poolsWhat does this PR do ?
Keeps the JIT compile caches (vLLM, TorchInductor, Triton, FlashInfer, FlashAttention-4, CUDA) in a shared folder between jobs, one cache per worker type: the vLLM generation engines, the Megatron trainer, and each external vLLM pool. A node copies the caches it needs to local storage before compiling, and new files are written back during and at the end of the job. Everything is off unless the new variables are set.
Issues
None filed. Today every job recompiles: the caches live in the container and disappear with it. On the Nemotron 3 Ultra RL smoke (64 nodes), policy engine-core start-up is 175 s cold and 39 s warm.
Usage
Two variables in the environment the Ray nodes start with, plus two background commands in
SETUP_COMMAND. Full example indocs/guides/persistent-jit-caches.md.External vLLM pool:
register_external_vllm_pool ... --cache-dir /lustre/.../compile_cache/genrm.Optional:
NRL_COMPILE_CACHE_VLLM_DIR/NRL_COMPILE_CACHE_MEGATRON_DIR(one type elsewhere),NRL_COMPILE_CACHE_FORCE_FRESH=1(start empty, still write back),NRL_COMPILE_CACHE_MIN_AGE_MIN(default 1),NRL_COMPILE_CACHE_SYNC_SCRIPT(another copy script, e.g. for object storage; interface in the guide).How it works
<shared>/<type>is copied to<local>/<type>, and each compiler points at<local>/<type>/{inductor,triton,flashinfer,cuda,fa4_cute}(compile_cache.env_overrides). vLLM's own cache is<local>/vllm/vllm.compile_cache.prepare_vllm_engine). Each task copies thevllmcache onto its node once, and fills the engine's ownVLLM_CACHE_ROOT(<local>/vllm_engines/<seed>) from it. Engines on one node keep separate folders, because vLLM writes its cache index without locking. This covers engines that span several nodes without patching vLLM's worker code.megatroncopy before anything compiles. Its kernels are compiled during setup.nemo_rl/utils/cache_sync.sh seed-type <type>copies once per node under a node-localflock. A launcher can start it beforeray startso the copy overlaps Ray start-up, and the workers then find it done.sidecar-types, run by the launcher on every node):ENDEDmarker, waits up to 2 minutes for the lock and reports what it couldn't publish.<local>/vllm/vllmfirst, so the shared cache gets one copy instead of one per engine.rsyncorflock, or only one of the two variables set, fails at start.vLLM versions
_patch_vllm_compile_cache_relative_artifactsinpatches.pyapplies the upstream fix (first released in 0.31.1) on every node of an engine. It raises if vLLM's source no longer matches. Remove it once vLLM >= 0.31.1.VLLM_RAY_BUNDLE_INDICESinto the compile-cache key. vllm#61211 fixed this upstream, but it isn't in main's pin. Until it is, each engine reuses only its own entries from an earlier job with the same placement, and engines don't share compiled graphs.Commits
perf(external-vllm): persistent compile caches for external vLLM pools:cache_sync.shand--cache-dirfor pools; every node of a replica is seeded beforeray start.perf(vllm,megatron): persistent per-type compile caches for NeMo RL workers:compile_cache.py, wired into the vLLM and Megatron workers.fix(external-vllm): wait longer for a replica's head node when it seeds a cache.perf(cache): one root per cache type, per-node engine seeding, review fixes: review comments C4, C5, C9, C11, C12, C14, C15, C16, C17, C18.fix(cache): backport vllm#52142 on every node of an engine.fix(cache): Megatron workers wait for their cache copy.Validation
Nemotron 3 Ultra RLVR smoke on 64 nodes with 4 GPUs each: 32 trainer, 20 generation (10 TP8 engines across 2 nodes each), 6 Gym and 6 judge nodes; 1 step. These ran this PR's code ported to the recipe's NeMo-RL branch (vLLM 0.25.1, with vllm#61211 applied as a patch), with the cache wiped before the cold run.
[tokens, 5120]) on the token count, which changes with every batch. So the cache grows by roughly that much per run until it is reset, as described in the guide.Tests
tests/unit/utils/test_cache_sync.py:seed-typewith the engine merge;flock.tests/unit/utils/test_compile_cache.py:tests/unit/tools/test_external_gym_vllm.py: updated for the new seed command.Run: the 11 tests above pass (CPU, torch 2.13,
--noconftest).ruff checkandruff format --checkare clean.Not run:
test_external_gym_vllm.py: it needs the full stack; I ran its pool checks separately.AI assistance (Claude) was used to write the change, tests and this description; I reviewed every changed line and ran the tests and jobs listed.
🤖 Generated with Claude Code