[feat] Init true on policy with qwen_dense - #2
Open
maocheng23 wants to merge 28 commits into
Open
Conversation
This was referenced Apr 28, 2026
…or --tokenizer-worker-num > 1 (sgl-project#24769) Co-authored-by: maocheng23 <35615230+maocheng23@users.noreply.github.com> Co-authored-by: lawrence-harmonic <185285563+lawrence-harmonic@users.noreply.github.com>
…a keys for prefix cache isolation (sgl-project#24770) Co-authored-by: Charles Chen <pychen96@gmail.com>
…solution under shuffled CUDA_VISIBLE_DEVICES (sgl-project#24901) Co-authored-by: Byron Hsu <byron@periodiclabs.ai> Co-authored-by: Cursor <cursoragent@cursor.com>
…t to unpicklable server_args and large meta_info (sgl-project#24902) Co-authored-by: Byron Hsu <byron@periodiclabs.ai> Co-authored-by: Cursor <cursoragent@cursor.com>
…NCCL all-gather for cross-DP info sync (sgl-project#24903) Co-authored-by: Byron Hsu <byron@periodiclabs.ai> Co-authored-by: Cursor <cursoragent@cursor.com>
…ache() for in-place pause mode to avoid OOM (sgl-project#24905) Co-authored-by: Byron Hsu <byron@periodiclabs.ai> Co-authored-by: Cursor <cursoragent@cursor.com>
…t_len for absolute routing slice control (sgl-project#24904) Co-authored-by: Byron Hsu <byron@periodiclabs.ai> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: zyzshishui <zyzshishui@gmail.com> Co-authored-by: Yuzhen Zhou <82826991+zyzshishui@users.noreply.github.com>
…call id. (sgl-project#25196) Co-authored-by: Jiajun Li <jiajun.li@MacBook-Pro-F7J34QJK2C-jiajunli.local>
…#25327) Co-authored-by: Qiaolin-Yu <liin1211@outlook.com>
Add deterministic TP kernels for true-on-policy alignment: - matmul_tp_inv: TP-invariant persistent matmul via DeepGEMM/Triton - tree_all_reduce_sum: fixed-order binary tree allreduce - moe_sum_tree_reduce: deterministic per-token MoE expert combine - tensor_model_parallel_tree_all_reduce in communication_op.py - Unit tests in test/registered/core/test_tp_invariant_ops.py Kernels are dormant unless explicitly enabled by later on-policy flags. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: zju-stu-lizheng <lizheng.cs@zju.edu.cn> Co-authored-by: zyxiyy02 <282300612+zyxiyy02@users.noreply.github.com> Co-authored-by: Yi Zhang <1109276519@qq.com>
Expand test_tp_invariant_ops.py from 15 to 55 tests covering all PR1
kernel invariance properties:
- Cross-TP invariance (bitwise torch.equal): TP=1 == TP=N for
K={512,1024,2048,4096} in BF16/FP32/FP16, including torch.ops dispatch
- Determinism: same TP degree, two runs == bitwise identical for
production K={3584,5120,4096} (Qwen3-4B/30B hidden sizes)
- MoE slot/EP invariance: permuting expert slot assignments gives
bitwise identical results (FP32, BF16, with remote experts, H=7168 E=64)
- fp32_accum path: deterministic and correct output dtype
- Input validation: matmul rejects non-2D/dim mismatch, MoE rejects
shape mismatches and non-power-of-two E
- Edge cases: K < BLOCK_K, K == BLOCK_K, K non-aligned, single expert,
duplicate expert IDs, all-remote, odd tree count
- Distributed: multi-GPU tree all-reduce correctness + BF16 bitwise
determinism (requires torchrun)
Documents the invariance contract: cross-TP equality holds when
K/(BLOCK_K * tp_size) is a power of two (isomorphic tree). For
non-isomorphic cases, the guarantee is determinism at fixed TP degree.
Made-with: Cursor
Co-authored-by: zju-stu-lizheng <lizheng.cs@zju.edu.cn>
Co-authored-by: zyxiyy02 <282300612+zyxiyy02@users.noreply.github.com>
Co-authored-by: Yi Zhang <1109276519@qq.com>
Add runtime flags and deterministic path selection for true-on-policy mode: - server_args: rl_on_policy_target (fsdp/fsdp_tp) flag and related args - linear.py: TP-invariant row-linear and tree-allreduce path selection - communicator.py: deterministic allreduce in gather/scatter paths - cuda_graph_runner.py: CUDA graph guards for prefill-only deterministic mode - model_runner.py: on-policy mode initialization - on_policy_utils.py: shared utilities for on-policy path selection Default serving path remains unchanged when flags are off. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: zju-stu-lizheng <lizheng.cs@zju.edu.cn> Co-authored-by: zyxiyy02 <282300612+zyxiyy02@users.noreply.github.com> Co-authored-by: Yi Zhang <1109276519@qq.com>
Make dense Qwen3 rollout numerically compatible with Megatron scoring: - layernorm.py: RMSNorm forward_native with fp32 precision control - logits_processor.py: CUDA graph-safe dtype handling for lm_head - on_policy_utils.py: dense deterministic math helpers - qwen2.py/qwen3.py: fp32_residual, override_orig_dtype, attention backend - tp_invariant_ops: refinements for dense matmul paths - Updated PR1/PR2 tests for compatibility Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: zju-stu-lizheng <lizheng.cs@zju.edu.cn> Co-authored-by: zyxiyy02 <282300612+zyxiyy02@users.noreply.github.com> Co-authored-by: Yi Zhang <1109276519@qq.com>
Co-authored-by: zju-stu-lizheng <lizheng.cs@zju.edu.cn> Co-authored-by: zyxiyy02 <282300612+zyxiyy02@users.noreply.github.com> Co-authored-by: Yi Zhang <1109276519@qq.com>
Co-authored-by: zju-stu-lizheng <lizheng.cs@zju.edu.cn> Co-authored-by: zyxiyy02 <282300612+zyxiyy02@users.noreply.github.com> Co-authored-by: Yi Zhang <1109276519@qq.com>
Co-authored-by: zju-stu-lizheng <lizheng.cs@zju.edu.cn> Co-authored-by: zyxiyy02 <282300612+zyxiyy02@users.noreply.github.com> Co-authored-by: Yi Zhang <1109276519@qq.com>
Co-authored-by: zju-stu-lizheng <lizheng.cs@zju.edu.cn> Co-authored-by: zyxiyy02 <282300612+zyxiyy02@users.noreply.github.com> Co-authored-by: Yi Zhang <1109276519@qq.com>
Co-authored-by: zju-stu-lizheng <lizheng.cs@zju.edu.cn> Co-authored-by: zyxiyy02 <282300612+zyxiyy02@users.noreply.github.com> Co-authored-by: Yi Zhang <1109276519@qq.com>
Co-authored-by: zju-stu-lizheng <lizheng.cs@zju.edu.cn> Co-authored-by: zyxiyy02 <282300612+zyxiyy02@users.noreply.github.com> Co-authored-by: Yi Zhang <1109276519@qq.com>
Co-authored-by: zju-stu-lizheng <lizheng.cs@zju.edu.cn> Co-authored-by: zyxiyy02 <282300612+zyxiyy02@users.noreply.github.com> Co-authored-by: Yi Zhang <1109276519@qq.com>
Co-authored-by: zju-stu-lizheng <lizheng.cs@zju.edu.cn> Co-authored-by: zyxiyy02 <282300612+zyxiyy02@users.noreply.github.com> Co-authored-by: Yi Zhang <1109276519@qq.com>
Co-authored-by: zju-stu-lizheng <lizheng.cs@zju.edu.cn> Co-authored-by: zyxiyy02 <282300612+zyxiyy02@users.noreply.github.com> Co-authored-by: Yi Zhang <1109276519@qq.com>
Co-authored-by: zju-stu-lizheng <lizheng.cs@zju.edu.cn> Co-authored-by: zyxiyy02 <282300612+zyxiyy02@users.noreply.github.com> Co-authored-by: Yi Zhang <1109276519@qq.com>
Co-authored-by: zju-stu-lizheng <lizheng.cs@zju.edu.cn> Co-authored-by: zyxiyy02 <282300612+zyxiyy02@users.noreply.github.com> Co-authored-by: Yi Zhang <1109276519@qq.com>
Co-authored-by: zju-stu-lizheng <lizheng.cs@zju.edu.cn> Co-authored-by: zyxiyy02 <282300612+zyxiyy02@users.noreply.github.com> Co-authored-by: Yi Zhang <1109276519@qq.com>
isort/ruff/black reformatting on files touched by the true-on-policy substrate, contract, and Qwen3-dense wiring. No semantic changes. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: zju-stu-lizheng <lizheng.cs@zju.edu.cn> Co-authored-by: zyxiyy02 <282300612+zyxiyy02@users.noreply.github.com> Co-authored-by: Yi Zhang <1109276519@qq.com>
…icy config Co-authored-by: zju-stu-lizheng <lizheng.cs@zju.edu.cn> Co-authored-by: zyxiyy02 <282300612+zyxiyy02@users.noreply.github.com> Co-authored-by: Yi Zhang <1109276519@qq.com>
maocheng23
force-pushed
the
feat/true_on_policy_qwen_dense
branch
from
May 17, 2026 23:14
82b0b7e to
e883df8
Compare
maocheng23
force-pushed
the
feat/true_on_policy_qwen_dense
branch
from
May 18, 2026 06:15
ab1389b to
76c42c7
Compare
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.
Summary
Initial framework introducing true-on-policy for Qwen3-dense across SGLang, Megatron, and Miles. This is one of three tightly-coupled PRs that must land together — they share a single contract identifier
qwen3_dense_true_on_policy_v1defined by a vendored schema in each repo.Companion PRs (must land in lockstep):
Target
Bit-identical (exact-zero) logprob parity between the SGLang rollout engine and the Megatron trainer for every scored response token at TP=1, TP>1, PP>1, and Ulysses CP for Qwen3-4B (dense).
Design
Three-layer contract architecture:
SGLangSpecProviderlayer classes.The contract object owns its own runtime policy — adding a new architecture (e.g. Qwen3-MoE) is one new contract object + one new model profile entry, not edits across three repos.
In this PR (SGLang)
python/sglang/srt/true_on_policy/package:schema.py— vendored shared identity, byte-identical with Megatron and Miles copiescontracts.py—SGLangTrueOnPolicyContractwithpolicy_for(server_args)factory; resolver is registry lookup, not branchconfig.py— policy-aware helpers (is_true_on_policy_enabled,should_force_bfloat16_*,should_use_tp_invariant_*)python/sglang/srt/tp_invariant_ops/package: deterministic K-block fixed-tree matmul + tree all-reduce Triton kernelslayers/{linear,layernorm,sampler,activation,communicator,logits_processor}.pylayers/rotary_embedding/{base,mrope}.pylayers/attention/vision.pymodel_executor/{model_runner,cuda_graph_runner,forward_batch_info}.pymodels/qwen3.py— dense, parity-validated pathmodels/{qwen3_moe,qwen2,qwen2_moe,sdar,sdar_moe,step3p5}.py— defensive helper-API alignment (these models are not yet declared true-on-policy ready; alignment keeps helper API consistent for future contract additions)--true-on-policy-contractCLI flag;--rl-on-policy-targetdemoted to legacy fallback (zero in-tree readers)patch_prefill_only_deterministic_inference_for_cuda_graph— env/server_args mutation guttedValidation
test_on_policy_wiring.py,test_dense_deterministic_math.py)Out of scope
rl_on_policy_targetfield — zero remaining in-tree readers; cosmetic cleanupTest plan
_ReplicatedLossAllGatherLastDimfix)🤖 Generated with Claude Code