PR #4715 ยท permalinks pinned to head
b2782355
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.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.
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.
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.
| Risk | Why it is safe |
|---|---|
| A reader sees a half-written archive | Written as .tmp, then renamed; a rename within a folder is atomic, and readers skip .tmp. |
| Two nodes send the same kernels | The 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-pack | Only a .tmp is left. It is ignored and cleaned up later. |
| Small archives pile up | Merge 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 job | Kernels 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). |
| Row | What happens today | With 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
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.