Skip to content

[1/2] Support streaming teacher features for Megatron EAGLE3 - #3473

Draft
WEIXILIN0307 wants to merge 2 commits into
NVIDIA:mainfrom
WEIXILIN0307:specdec/megatron-vllm-poc
Draft

WEIXILIN0307 wants to merge 2 commits into
NVIDIA:mainfrom
WEIXILIN0307:specdec/megatron-vllm-poc

Conversation

@WEIXILIN0307

@WEIXILIN0307 WEIXILIN0307 commented Nov 18, 2026 •

Copy link
Copy Markdown

Summary

Provide fixed-length BF16 teacher features to offline Megatron-LM EAGLE3 using the existing ModelOpt vLLM HTTP/NIXL reader. The adapter supplies aligned token IDs, an unshifted loss mask and feature rows. The Megatron EAGLE forward applies the checkpoint's final norm to a streamed pre-norm residual before the teacher LM head.

Interface contract

  • For sequence length S, emit S+1 token IDs and mask entries and S BF16 rows in each feature tensor. Padded features and mask entries are zero. Megatron-LM shifts IDs and supervision once to form next-token labels.
  • The capture contains auxiliary planes in checkpoint order followed by a distinct pre-norm final plane. Qwen3-0.6B checkpoint IDs [1, 13, 24] map to vLLM completed-layer captures [2, 14, 25, 28]. Use matching teacher weights and tokenizer. Disk-backed post-norm features use the default forward path.
  • The connector needs one identifiable capture cache group and a four-dimensional per-layer cache view, either [blocks, tokens, planes, hidden] or [blocks, planes, tokens, hidden]. Set a block size distinct from the number of capture planes. Disable chunked prefill and prefix caching to capture the entire prompt in one scheduler step. Provide a capture slot of at least S tokens and a context limit of at least S+1 for the one-token completion request.

Reproduction

Start the BF16 Qwen3 teacher on its own GPU with the documented vLLM configuration. Set TEACHER_MODEL to the same local weights directory. Run the real-service test on a second GPU. Server command and capture settings

CUDA_VISIBLE_DEVICES=1 NIXL_BACKENDS=UCX UCX_TLS=tcp,sm,self,cuda_copy \
    EAGLE_STREAMING_TEST_URL=http://127.0.0.1:18876 EAGLE_STREAMING_TEST_TEACHER="$TEACHER_MODEL" \
    pytest -q tests/gpu_vllm/torch/speculative/plugins/test_rdma_hidden_states_connector.py \
        -k live_megatron_stream

Validation

  • The vLLM connector suite passed 9 tests with the live Qwen3 service enabled. The real HTTP/NIXL test checks padding on a short sample, captures exactly 256 prompt tokens after truncation, checks every plane against eager Transformers and rejects a trainer cap of 257 against a 256-token capture slot. The cache-layout tests also exercise non-contiguous blocks and interleaved requests.
  • The streaming dataset suite and Megatron pre-norm/post-norm GPU regression passed 66 tests together. The norm regression compares the logits and loss exactly. A separate 450-token live capture matched all reference teacher top-1 tokens, with 2.2% relative L2 logit error.

Related work

Refs #3349. The companion Megatron-LM draft owns trainer selection and batching. The RFC contains the full online throughput, end-to-end command time, memory, training loss and acceptance length comparison. Megatron-LM #9550 · RFC #3474

Before this PR is ready for review

  • Backward compatible: ✅
  • Copied third-party code or added a package dependency: N/A
  • Added regression tests: ✅
  • Updated changelog: ✅
  • Claude review: pending

@copy-pr-bot

copy-pr-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor
Pre-merge checks: Passed 1

Check name Status Explanation
Security Anti-Patterns Passed Summary: No security anti-pattern from the custom check appears in the lines this PR adds. Scope: The PR adds two commits to the speculative-decoding code, 49304a5 and 0e6a792. I diffed them again…
Full details: Security Anti-Patterns

Explanation

Summary: No security anti-pattern from the custom check appears in the lines this PR adds. Scope: The PR adds two commits to the speculative-decoding code, 49304a5 and 0e6a792. I diffed them against their parent, fe3dab7. The changed files are CHANGELOG.rst, examples/speculative_decoding/README.md, hf_streaming_dataset.py, megatron_eagle.py, and four test files. The local origin/main is older than the PR base, so a diff against origin/main also shows unrelated commits. I excluded those. Checks against the six criteria: 1. torch.load with weights_only=False: no match in added lines. 2. numpy.load with allow_pickle=True: no match. The word "pickle" does not appear in added lines. 3. trust_remote_code=True: no match in added lines, including the README and Python files. 4. Builtin eval() or exec() on external input: no match. The only hits are .bfloat16().eval() (nn.Module.eval, in a test/model setup) and a chained .eval(). Both put a model in evaluation mode and do not evaluate strings. 5. "# nosec": no match. 6. Dependency changes: no changes to pyproject.toml or requirement files in the PR commits. Also scanned for subprocess, shell=True, yaml and marshal in added lines. No matches. Limitations: I used grep-based pattern matching on the diff. I did not run Bandit or inspect the full files.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant