TorchSpec icon indicating copy to clipboard operation
TorchSpec copied to clipboard

Support co-locate training and inference (#81)

Open zhubohao911 opened this issue 6 months ago โ€ข 0 comments

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

  • --full green on 4ร—H100 under CUDA IPC default โ€” test_phase4_tiny_one_step, test_phase7_tiny_loss_decreases, 4-GPU test_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-step test_phase6_peak_alloc_flatness, 50-step test_phase7_convergence_loss_decreases.
  • 4 latent dp_size>1 bugs found by --full that the 1-GPU smoke could not surface, plus 1 same-shape bug found preemptively by audit โ€” all fixed (detail in pr92_detail.md).
  • Round 9 โ€” CUDA IPC default hung at step 0 under MPS. Root cause: a destructive capability probe (reduce_tensor smoke 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-pipe ack-pipelining is a 3.9ร— protocol-level win on the engine send() stall but low-priority (the transport is ~1 % of a colocate step). A 3000-step 4-GPU stability soak ran clean.
  • Round 11 โ€” ipc-pipe productionized + issue-#81 follow-ups GPU-validated in one 4ร—H100 pod session: --stability 1000-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 --full run 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:
    1. DFlashTrainer._init_target_lm_head โ€” 5 trainer-side collectives (dist.barrier / broadcast / 3ร— all_reduce) ran with no group=, defaulting to the union world; only trainers entered the method โ†’ deadlock. Scoped to get_gloo_group() (same shape as round-7 set_model_state_dict / dcp.save fixes; Eagle3Trainer already carried it).
    2. colocate_loop._build_tensor_specs โ€” trainer declared 2 tensors, engine always sent 3 (last_hidden_states is unconditional in the colocate engine), per-tensor IPC ack handshake blocked on the third. Spec now always declares last_hidden_states; store_last_hidden_states removed.

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-main baselines. 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 at engine_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 > 1 in colocate_loop.py โ€” guarded with NotImplementedError("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.

zhubohao911 avatar May 07 '26 08:05 zhubohao911