Skip to content

[alignment-megatron] PR6: SGLang Backend Surface#25

Draft
maocheng23 wants to merge 1 commit into
radixark:miles-mainfrom
maocheng23:maocheng/top-pr06-sglang-backend-surface
Draft

[alignment-megatron] PR6: SGLang Backend Surface#25
maocheng23 wants to merge 1 commit into
radixark:miles-mainfrom
maocheng23:maocheng/top-pr06-sglang-backend-surface

Conversation

@maocheng23
Copy link
Copy Markdown

Summary

  • Add a clean Megatron backend that can call SGLang-compatible math under a --use-sglang flag
  • First Megatron PR in the true-on-policy migration series

Changes

  • megatron/core/extensions/sglang.py: SGLangLinear, SGLangRMSNorm, SGLangFlashAttention and related modules
  • megatron/core/tensor_parallel/matmul_tp_inv.py: TP-invariant matmul dispatch
  • megatron/core/transformer/transformer_config.py: use_sglang config flag
  • megatron/training/arguments.py: --use-sglang CLI arg
  • megatron/core/tensor_parallel/layers.py: conditional SGLang backend selection
  • megatron/core/models/gpt/gpt_layer_specs.py: SGLang-compatible layer spec builder
  • tests/unit_tests/extension/test_sglang_extension.py: unit tests

Done when

  • Megatron can build SGLang-compatible linear/norm modules without changing default training

Test plan

  • Extension import test
  • Config/arg parsing test for use_sglang
  • Backend selection test proving default Megatron modules are unchanged

🤖 Generated with Claude Code

Add a clean Megatron backend that calls SGLang-compatible math under a flag:
- sglang.py: SGLangLinear, SGLangRMSNorm, SGLangFlashAttention and related modules
- matmul_tp_inv.py: TP-invariant matmul dispatch for Megatron layers
- transformer_config.py: use_sglang config flag
- arguments.py: --use-sglang CLI arg
- layers.py: conditional SGLang backend selection in TP layers
- gpt_layer_specs.py: SGLang-compatible layer spec builder
- test_sglang_extension.py: import, config, and default-path-unchanged tests

Default training path remains unchanged when use_sglang is off.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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