Skip to content

Support Kimi no-TE alignment path#1

Open
zrr1999 wants to merge 3 commits into
PFCCLab:release/4.0from
zrr1999:kimi-k2-no-te-alignment
Open

Support Kimi no-TE alignment path#1
zrr1999 wants to merge 3 commits into
PFCCLab:release/4.0from
zrr1999:kimi-k2-no-te-alignment

Conversation

@zrr1999

@zrr1999 zrr1999 commented Jul 7, 2026

Copy link
Copy Markdown

Summary

  • add SWIFT_MEGATRON_NO_TE gated local/no-TE Megatron-Core layer specs for Kimi alignment
  • add MLA DotProductAttention compatibility for local no-TE specs
  • remap TE-saved fused norm checkpoint keys when loading no-TE specs
  • dequantize Kimi FP8 weight_scale_inv tensors into regular BF16 params under SWIFT_MEGATRON_NO_TE

Validation

  • python -m py_compile swift/megatron/model/gpt_bridge.py swift/megatron/model/register.py swift/megatron/utils/megatron_lm_utils.py
  • sampled full Kimi-K2-Instruct FP8 weight_scale_inv branch smoke: exact BF16 dequant match
  • reduced 2-layer Kimi SFT no-TE forward loss comparisons reached 20-step and 100-step BITWISE_PASS in the repro workspace

Scope

Default TransformerEngine behavior is unchanged. New behavior is gated by SWIFT_MEGATRON_NO_TE for Kimi alignment/repro workflows.

@zrr1999

zrr1999 commented Jul 7, 2026

Copy link
Copy Markdown
Author

Update: pushed final no-TE EP2 alignment patch in 21d9bb68149565bf6a1f50ce45f35757c7e77e02.

What changed:

  • In explicit no-TE alignment mode (SWIFT_MEGATRON_NO_TE=1), patch Megatron-Core SequentialMLP to handle exact duplicate per-expert hidden/prob chunks deterministically.
  • If a local expert receives exact duplicated halves, compute one half and duplicate the output. This avoids BF16 GEMM batch-size drift observed when EP dispatch changes local expert batch from n rows to exact duplicated 2n rows.
  • Patch is gated to the no-TE alignment path and checks exact hidden/prob duplication; it is not sample/coordinate/loss-specific.

Validation evidence (Kimi-K2 2-layer BF16 SFT, native ms-swift/Megatron-Core, no-TE):

  • EP2 PR patch vs EP1 reference: BITWISE_PASS, 100 steps, first_bad_step=null
    • reports/TORCH_NO_TE_EP2_MS_SWIFT_PR_PATCH_VS_EP1_100STEP_COMPARE.md
  • EP2 PR patch vs Paddle native reference: BITWISE_PASS, 100 steps, first_bad_step=null
    • reports/NO_TE_EP2_MS_SWIFT_PR_PATCH_VS_PADDLE_100STEP_COMPARE.md
  • EP1 preservation with this patch vs EP1 reference: BITWISE_PASS, 100 steps
    • reports/TORCH_NO_TE_EP1_MS_SWIFT_PR_PATCH_VS_EP1_REFERENCE_100STEP_COMPARE.md
  • EP1 preservation with this patch vs Paddle native reference: BITWISE_PASS, 100 steps
    • reports/NO_TE_EP1_MS_SWIFT_PR_PATCH_VS_PADDLE_100STEP_COMPARE.md

Mechanism evidence:

  • Manual native expert recompute showed the same EP1 expert module/weights produce saved EP1 output for n rows and saved EP2 output for exact duplicated 2n rows; max diff is one BF16 quantum (0.0078125).
  • reports/TORCH_NO_TE_EXPERT_BATCHSIZE_INVARIANCE_STEP2ONLY.md

Claim boundary: validated for the current 2-layer BF16 no-TE EP=2 alignment scope; not a full 61-layer/FP8 claim.

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