Support co-locate training and inference (#81)
Implements #81 โ colocate the Eagle3 / DFlash draft trainer and the sglang target engine on the same physical GPUs via CUDA MPS, removing the disaggregated layout's idle-GPU waste.
Gated behind colocate_strategy=mps + transfer_mode=nccl; the disaggregated baseline is untouched when the flags are off.
๐ Full iteration history โ every phase, follow-up round, N>1 bug fix, architectural correction, and rented-GPU validation run โ is preserved in
docs/colocate/implementation_log/pr92_detail.md. This description is the concise current summary.
Status โ feature-complete, GPU-validated at production scale
Phases 0โ8 plus follow-up rounds 1โ12. run_smoke_host.sh --full is green on 4รH100 under the CUDA IPC default transport (single-node). Two production-scale 20000-step / 40k-sample Qwen3-8B colocate runs landed clean on 2รH100 with rc=0 โ Eagle3 (CE1, round 11) and DFlash (C1, round 12) โ each beating the same-SGLang disagg baseline rerun on main in GPU-h.
How it works
| Layer | Mechanism |
|---|---|
| GPU sharing | CUDA MPS โ trainer + engine share each physical GPU; fractional Ray bundles; memory split train_frac + infer_frac + 0.10 โค 1 |
| Distributed | Union NCCL world (2N ranks = N trainers + N engines) โ trainer FSDP subgroup + engine TP + an all-rank gloo meta_group |
| Hidden-state transport | CUDA IPC zero-copy (default) โ engine exports a CUDA IPC handle, trainer maps it + one on-device DโD copy. TORCHSPEC_COLOCATE_IPC=0 โ gloo CPU-staging fallback. ~170ร faster than gloo on realistic payloads. Optional TORCHSPEC_COLOCATE_IPC_PIPELINE=1 adds a send-buffer pool + ack pipelining |
| sglang side | vendored colocate.patch (v0.5.10.post1 default; v0.5.8.post1 via SGLANG_PATCH_VERSION) |
Production-scale benchmark โ colocate beats disagg on GPU-h
Both cells matched against the same-SGLang disagg rerun on origin/main (dflash_eagle3_disagg_modal_rerun_on_main.md), retiring the cross-branch confound earlier benchmark versions carried.
| Cell | Steps | Samples | Throughput | GPU-h | Disagg baseline | Win |
|---|---|---|---|---|---|---|
| CE1 โ Eagle3 2+2 colocate (round 11) | 20000 | 40000 | ~13.25 samples/s | 1.68 / 40k (2 GPU) | E1-rerun = 12.72 samples/s, 3.49 / 40k (4 GPU) | ~2.1ร less GPU-h |
| C1 โ DFlash 2+2 colocate (round 12) | 20000 | 40000 | 7.51 samples/s | 2.96 / 40k (2 GPU) | D1-rerun = 10.00 samples/s, 4.44 / 40k (4 GPU) | ~1.5ร less GPU-h |
Wins decompose as 2.0ร (half the GPU count via MPS sharing) ร r (raw-throughput ratio): Eagle3 r โ 1.0; DFlash r โ 0.75 (heavier trainer โ more MPS contention). The architectural saving is reclaiming the idle disagg inference GPUs. Convergence holds for both cells โ CE1's final rolling loss (~2.09) matches disagg E1 (2.24 / 1.98); C1's (~3.81) sits inside the disagg D1 noise band (3.67 / 4.89). Full analysis: colocate_benchmark.md.
Validation highlights
--fullgreen on 4รH100 under CUDA IPC default โtest_phase4_tiny_one_step,test_phase7_tiny_loss_decreases, 4-GPUtest_phase4_one_step_completes_end_to_end, grad parity (smoke/determinism/full), checkpoint save+resume,test_colocate_ipc,test_colocate_tp2,test_colocate_multi_engine, 200-steptest_phase6_peak_alloc_flatness, 50-steptest_phase7_convergence_loss_decreases.- 4 latent
dp_size>1bugs found by--fullthat the 1-GPU smoke could not surface, plus 1 same-shape bug found preemptively by audit โ all fixed (detail inpr92_detail.md). - Round 9 โ CUDA IPC default hung at step 0 under MPS. Root cause: a destructive capability probe (
reduce_tensorsmoke test) shared a tensor over IPC and discarded it, poisoning the MPS context. Fixed โ non-destructive probe (e166c21) + active expandable-segments handling for IPC actors (e62c941). - Round 10 โ transport optimization investigated. No hand-written C++/CUDA/Triton kernel is needed (the path is a bandwidth-bound DโD copy plus driver-API calls);
ipc-pipeack-pipelining is a 3.9ร protocol-level win on the enginesend()stall but low-priority (the transport is ~1 % of a colocate step). A 3000-step 4-GPU stability soak ran clean. - Round 11 โ
ipc-pipeproductionized + issue-#81 follow-ups GPU-validated in one 4รH100 pod session:--stability1000-step (green), convergence vs Mooncake-disagg (loss curves overlap 0.006 % mean / 0.219 % max over 1000 steps), Qwen3-8B grad-parity smoke (green). The pipelined-transport--fullrun found + fixed one OOM on the memory-tight 8B config (pool retired-buffer leak + grow overshoot). - Round 12 โ DFlash colocate brought up at production scale. Two distinct, sequential DFlash-only deadlocks were surfaced and fixed in
f28dc73:DFlashTrainer._init_target_lm_headโ 5 trainer-side collectives (dist.barrier/broadcast/ 3รall_reduce) ran with nogroup=, defaulting to the union world; only trainers entered the method โ deadlock. Scoped toget_gloo_group()(same shape as round-7set_model_state_dict/dcp.savefixes; Eagle3Trainer already carried it).colocate_loop._build_tensor_specsโ trainer declared 2 tensors, engine always sent 3 (last_hidden_statesis unconditional in the colocate engine), per-tensor IPC ack handshake blocked on the third. Spec now always declareslast_hidden_states;store_last_hidden_statesremoved.
Docs
| Doc | What |
|---|---|
pr92_detail.md |
full iteration history of this PR, in depth (rounds 1โ12) |
implementation_log.md |
debug log โ RunPod / Vast sessions + follow-up rounds 1โ12 |
colocate_benchmark.md |
disagg-vs-colocate study (CE1 + C1 done; CE2 / C2 pending) |
transport_benchmark.md |
gloo-vs-CUDA-IPC transport benchmark |
transport_optimization.md |
transport kernel-vs-protocol investigation + MPS-validated A/B |
handoff_followups.md |
open follow-ups, self-contained handoff |
Open follow-ups (tracked, not blocking this PR)
- CE2 / C2 benchmark cells (4+4 colocate) โ code-ready, unrun; needs one 4รH100 pod and a matched 40k-sample run per cell against the existing disagg E2 / D2 rerun-on-
mainbaselines. Next productive item that does not need new hardware beyond a 4-GPU pod. - Multi-node 2-node colocate run โ code-complete (
ensure_mps_on_all_nodes, 2-node config) but untested at scale; needs a 2-node rented cluster. - Large
engine_tp_size(8-GPU TP per engine) โ rank math + data plane handle any TP size, only GPU-tested atengine_tp_size=2. - Colocate fail-fast for spec / default-PG mismatches โ round 12's two silent-deadlock failure modes could be turned into immediate errors via a runtime check in
Trainer.__init__(assert default PG โ union world) and a step-0 watchdog that dumps both sides' tensor specs on mismatch. Small change, high value. draft_accumulation_steps > 1incolocate_loop.pyโ guarded withNotImplementedError("Multi-step accumulation is parked"); out of scope unless the benchmark needs cell-for-cell parity with disagg ยง8.v0.5.10 pp_size>1โ blocked by an explicit guard, out of scope for the current colocate plan.
Environment
The bundled sgl_kernel wheel ships sm90+ kernels only (no Ampere / Ada) โ real GPU testing is H100 / H200 / B200.