Keep the shared compile cache as compressed archives, not thousands of small files

PR #4715 ยท permalinks pinned to head b2782355

Before
Every job compiles vLLM and the Megatron trainer from scratch.
This PR
Keeps compile caches on a shared filesystem as a plain folder tree. Each node copies the files in at start, and every 60 s copies new files back, one by one.
Status
Proposed, not implemented. The review keeps the PR's idea (a shared cache that grows across jobs) but asks to store it as compressed archives. A ~400-line prototype passed race tests: 8 nodes reading while others publish and a merge runs, a writer killed mid-copy, and 4 nodes each publishing their own files.
Background. There are two kinds of cache, one for each worker type, and each has a few compiler folders: policy = the vLLM generation engines (vllm/, triton/, flashinfer/, โ€ฆ) and megatron = the Megatron trainer (inductor/, triton/, โ€ฆ). The Gym judge pools have their own, the same way. A shared filesystem slows down most when many nodes open many small files at once, because every open goes to one metadata server. An earlier version of this feature was turned off for exactly that. Dotted words have a short explanation: hover or tap them.

Shared-filesystem traffic, today and with archives

Worked example: 4 nodes, an Ultra-sized cache. Measured: the vLLM policy cache is ~6,000 files, the Megatron trainer cache ~82,000 files. Each row applies to both, and to every compiler folder in them.

WHEN This PR (plain folder tree) With compressed archives Job startcopy-in every node copies each folder, file by file 4 ร— (6k vLLM + 82k trainer) = 352k file opens every node unpacks a few archives per folder tens of large reads per node, not 88k opens Every few minwrite-back each node re-sends every file it compiled same full list every pass, for the whole job pack only files not already shared (by name) 1 new archive, or just 1 folder listing Who publishes every node, file by file, one lock per folder a slow first publish can lose its lock every node: its own rank_* files and kernels files another node already sent are skipped Trainer copyin background "copied" marker is written when the copy ends kernels built during the copy: never sent "new" is decided by file name, not by time those kernels are sent ยท C5 Node joinslater worker copies in; nobody starts write-back its new kernels are never shared not asked yet: add a node-start command to cache_sync.sh when autoscaling lands vLLM engineon 2+ nodes only the NeMo-RL actor's node is copied in GPUs on the other nodes compile cold, every job start-up hook in each vLLM GPU worker every node copied in ยท C15

Red = extra load on the shared filesystem, or cache work that is lost. Green = what the review asks for. Underlined text links to the code.

One write-back pass, step by step

Node 2, folder policy/vllm. At job start it unpacked 6,000 files from the shared archives. Since then its engines compiled 50 new files: 42 have not changed for over a minute, 8 are newer.

# proposed, not implemented: what one pass does, per compiler folder
local   = files under policy/vllm/ unchanged for > 1 min        # 6,042 = 6,000 unpacked + 42 settled
shared  = names listed in the shared .idx files (cached locally) # 6,000, plus anything other nodes sent
new     = local - shared                                          # 42 (by NAME, so times and clocks don't matter)
if not new:
    stop                                                          # shared FS saw one folder listing
take the folder lock; re-read any .idx added since; new -= them   # another node may have sent some
tar + zstd the 42 files -> chunk-<time>-<host>-<pid>.tar.zst.tmp   # built locally, one file
copy it to the shared folder, write its .idx, then rename both     # readers never see a half-written archive
release the lock; shared += new
# next pass: the 8 newer files have settled -> a second, small archive
# pass after that: nothing new -> one folder listing, no copies

The copy step can be cp or rsync. What matters is that every archive has a unique name and is renamed into place, so no two nodes ever write the same file. Updating one shared archive in place is the race to avoid: when two nodes do it, the last one to finish silently drops the other's files.

RiskWhy it is safe
A reader sees a half-written archiveWritten as .tmp, then renamed; a rename within a folder is atomic, and readers skip .tmp.
Two nodes send the same kernelsThe lock plus the .idx re-check skip them. If both still send, it is a harmless duplicate: unpacking keeps the first copy, and the content is the same.
A writer is killed mid-packOnly a .tmp is left. It is ignored and cleaned up later.
Small archives pile upMerge at job start: one process (e.g. the driver) combines them into one archive per folder, lists what it replaced, and deletes old ones only after a grace period. It uses its own lock, never the writers' lock, so nodes keep publishing while it runs. It reads the shared archives, so it already has every node's files.
A TP or CP change on the next jobKernels whose shapes changed just miss and recompile. Inductor's cache key includes the graph and its input shapes, and it re-checks shape guards on load (codecache.py). Triton keys on source, compile-time constants and specializations (compiler.py).

The other rows, one example each

RowWhat happens todayWith the fix
Who publishes
Megatron, 4 nodes
The 4 nodes train on different batches, so they compile different kernel versions: node 1 builds kernels A and B, node 3 builds A and C. Each node rsyncs its files one by one, taking turns on one lock. A lock older than 10 min is treated as abandoned even if its writer is still copying, so a slow first publish can run alongside a second writer, and then delete that writer's lock. Node 1 sends one archive with A and B. Node 3 sees A in node 1's .idx and sends an archive with only C. Every node's own files reach the shared copy, and nothing is sent twice. Each writer only removes a lock it owns.
Trainer copy
background, C5
At 0:00 the trainer starts copying 82k files in the background, which takes about 5 min. At 3:00 step 1 compiles kernel K. At 5:00 the copy ends and the "copied" marker gets the time 5:00. Write-back only sends files newer than the marker, so K (3:00) looks like part of the copy and is never sent, in this job or any later one. "New" means "its name is not in any shared .idx". K's name isn't there, so the next pass sends it. Times no longer matter.
Node joins later
autoscaling
Two hours in, node 5 joins, runs ray start, and gets a vLLM worker. The worker copies the cache in, which works. But only the launcher's SETUP_COMMAND starts the write-back loop, so nothing node 5 compiles is ever shared. Not asked in this review, since there is no node-join path yet. When autoscaling lands, a small node-start command in cache_sync.sh (copy in, then start one write-back loop per node, behind a node lock) covers it.
vLLM engine on 2+ nodes
C15
A TP=8 engine on two 4-GPU nodes: the NeMo-RL actor runs on node 1, so only node 1 is copied in. Node 2's GPUs (ranks 4โ€“7) start with an empty cache and compile cold, every job. Write-back skips node 2 too, because it never got a "copied" marker. A start-up hook in each vLLM GPU worker process (described in the PR, not in the diff) runs the copy-in on its own node, so node 2 is copied in and publishes its ranks 4โ€“7.

Where the change lands: one script, cache_sync.sh (or a small Python module that calls tar), plus zstd in the image. The workers' calls and the variables stay the same. The same layout also works on S3, because archives are never changed after they are written.

C16 โ€” cache_sync.sh:40 C5 โ€” megatron_policy_worker.py:841 C15 โ€” compile_cache.py:48

Not covered by this review: vLLM engines with TP>1 share less. vLLM 0.29.0's cache key includes VLLM_RAY_BUNDLE_INDICES, which NeMo-RL sets per engine when TPร—PP > 1. Nothing breaks: an engine that gets the same GPU slots next job still hits, but different engines don't share. vLLM fixes this upstream (vllm#61211), so it improves on a later vLLM upgrade with no patch to maintain.

C4 โ€” vllm_worker.py:335 C17 โ€” vllm_worker.py:343

So what. The PR's write-back idea (only new files, never overwrite, one writer at a time) stays. Storing each folder as a few compressed archives turns ~352k file opens per job start into tens of large reads per node, and each write-back pass, every few minutes, sends a file at most once. Each job starts from one archive per folder. The comment links work for everyone once the review is published.