Feat(megatron): EAGLE3 drafter training on Megatron backend - #71
Merged
Conversation
Port the Megatron old-logprob hidden-state capture, PP>1 cross-stage exchange, and online drafter training to mainline (coexists with the existing FSDP/VeOmni paths). - oldlogprob_runtime: forward-hook capture on mcore decoder layers/final norm, SP-aware row selection, PP>1 cross-stage exchange via temp files (HCCL-free). _speco_pp_exchange_dir replaces the hardcoded /home/model/tmp path with a portable default (/dev/shm or tempfile). - rollout_publish: install the Megatron hidden-runtime patch for non-veomni actor backends alongside the FSDP/VeOmni patch. - speco_ray_trainer/base_trainer: accept actor.strategy=megatron, wire drafter collect/training plan + checkpointing. - examples: add run_qwen3-4b_actor_megatron_drafter_eagle3_vllm_npu.sh (name follows the actor-backend naming convention). Verified: py_compile on all 4 files; megatron patch funcs importable; tests/examples/test_example_scripts.py 31 passed. Co-authored-by: Claude
- actor_tp=4 actor_pp=2 -> actor_tp=8 actor_pp=1 to eliminate PP cross-stage pickle exchange overhead in old_log_prob hidden capture (514s/step vs 797s/step, ~35% faster) - Replace RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES with TORCH_COMPILE_DISABLE=1 Co-authored-by: opencode <opencode@ai>
…hooks - Extract _speco_augment_log_data method from inline logic in _speco_tracking_metrics_hook to reduce duplication across the kwargs/args code paths. - Add _speco_bubble_profiler_enabled and wire inject_bubble_metrics into the augmented log data when profiling is enabled. - Delegate hidden-layout resolution to resolve_drafter_hidden_states_layout (moved into oldlogprob_layer_ids) instead of inlining the algorithm/alpha checks in the trainer.
755651978
had a problem deploying
to
speco-npu-ci
August 28, 2026 07:14 — with
GitHub Actions
Failure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Basic information
Scope: Add Pipeline Parallelism (PP>1) and Sequence Parallelism (SP=True) support to the Megatron old-logprob hidden-state collection path, enabling EAGLE3 drafter co-training under TP+SP+PP topologies (e.g. Qwen3-4B TP4PP2, Qwen3-8B TP8PP1) on NPU.
Background: verl-SpeCo's EAGLE3 drafter online training captures specific-layer hidden states (aux layers + final-norm output) from the target model's
compute_old_log_probforward viaregister_forward_hook, then selects/merges/distributes them to drafter training workers. The previously mergedefad0aaonly supports Megatron TP; this PR adds PP>1 cross-stage exchange and fixes SP=True under PP async actors.Problem solved: When PP>1, aux layers are split across pipeline stages — each stage's forward hook can only capture its local layers, so captures must be exchanged across stages and merged at the last stage. SP=True additionally shards hidden states across TP ranks, requiring all TP ranks to participate in the exchange.
Key changes
oldlogprob_runtime.py). Non-last stages pickle captures to/dev/shm/speco_pp_exchange/pp_{rank}_fbb_tp{N}.pkl(atomic.tmp+rename); the last stage polls (30s timeout), loads, and merges. This avoids HCCL P2P (deadlocks on NPUisend/irecv) and Ray object-store blocking (which freezes the async-actor event loop and deadlocks pipeline HCCL collectives).ray.putof the final concatenated tensor at the last stage (owner is correct), instead of 132 per-microbatchray.puts that would pin object store → spill → disk pressure. Task runnerray.gets once and immediatelydels the ref.index_copy_reorder from micro-batch to full-batch order usingindicessaved byspeco_aggregate_output— fixes the sample-misalignment regression whereuse_dynamic_bsz=Truecaused acceptance to drop (2.03→1.98).c8fdc53): per-tp_rankfile tag (fbb_tp{N}) so every TP rank exchanges its distinct SP shard; sparse-aware device inference + CPU→device remap after pickle round-trip; dense conversion;tp_rank=0-only attach guard; expected-warning downgrade to debug.no_trainable_batchon step 2+.load_formatkey (acceptance=1.0),nbytes()TypeError, empty-file skip, context clear.Design notes
speco_megatron_postprocess,_megatron_post_stage_exchange_and_consume,_megatron_save_stage_captures) fully isolate the two paths; PP=1 is byte-for-byte identical toefad0aaand unaffected.verl_speco/via monkey-patch; Megatron-LM / MindSpeed / vllm-ascend / verl upstream core source is untouched.oldlogprob_runtime.pyhas 0 NPU code lines — device is inferred from saved-capture tensors;speco_mem_watchdog.pyis 100% platform-agnostic (/proc/meminfo+disk_usage+ OS signal).Test environment
ASCEND_RT_VISIBLE_DEVICES=0,1,2,3,4,5,6,7(8 NPUs)Qwen/Qwen3-4B)AngelSlim/Qwen3-4B_eagle3_AngelSlim)use_kl_in_reward=False,kl_loss_coef=0.001(low_var_kl)Test results
A. Qwen3-4B TP4PP2 SP=True — primary run
Drafter acceptance length (every 5 steps):
Stats: min=2.031, max=2.355, mean=2.284. Acceptance rose +12% in the first 15 steps, peaked at step 45, then stabilized around 2.28.
Validation accuracy (
val-core/math_dapo/acc/mean, every 5 steps):Val accuracy rose from 0.125 → ~0.52–0.56 (4× improvement).
Reward (
critic/score/mean): −0.762 (step 1) → +0.050 (step 10) → oscillates near 0 as training progresses.Step-5 timing breakdown (SP=True vs SP=False, seconds):
SP=True old_log_prob slightly higher (+11s, SP all-reduce) but step total slightly lower (−41s) — equivalent.
B. SP=True vs SP=False equivalence (step 10)
Equivalent — confirms the SP all-reduce deadlock is resolved; SP no longer needs to be disabled.
C. FSDP2 vs Megatron-TP8PP1 equivalence (Qwen3-8B, step 1-10)
Per-step acceptance and reward curves overlap to within <0.01 — verifies Megatron-TP drafter training is equivalent to FSDP2.
D. Stability