Skip to content

fix(converter): lay out fused MLA a_proj for inference TP - #117

Merged
chaokunyang merged 1 commit into
inclusionAI:mainfrom
Le8r0nJames:zjw/fused-mla-a-proj-tp-layout
Aug 19, 2026
Merged

fix(converter): lay out fused MLA a_proj for inference TP#117
chaokunyang merged 1 commit into
inclusionAI:mainfrom
Le8r0nJames:zjw/fused-mla-a-proj-tp-layout

Conversation

@Le8r0nJames

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes silent weight corruption when converting the fused MLA a_proj from
Megatron-Core to SGLang with inference tensor parallelism.

SGLang consumes the fused MLA parameter on each inference TP rank as
[q_i; kv_i]. AWEX applies generic TP chunking along dimension 0, but the
converter previously produced the full tensor as [q_all; kv_all]. Chunking
that layout does not give each rank its corresponding Q and KV shards.

The incorrect and correct layouts have the same shape, so the transfer can
complete without an error while silently corrupting attention weights. This
causes post-update generations and train/inference log-probabilities to
degrade.

This PR:

  • packs the full fused tensor as [q_0; kv_0; q_1; kv_1; ...] before
    inference TP chunking;
  • preserves the plain [q; kv] concatenation when training attention TP is
    disabled and the tensor is delivered uncut;
  • validates tensor dimensions and TP divisibility before packing;
  • adds coverage for inference TP sizes 1, 2, and 4, layout invertibility, and
    invalid inputs.

Validation:

  • ruff format --check awex/converter/mcore_converter.py awex/tests/test_fused_mla_a_proj_layout.py
  • ruff check awex/converter/mcore_converter.py awex/tests/test_fused_mla_a_proj_layout.py
  • pytest -v awex/tests/test_fused_mla_a_proj_layout.py

Related issues

N/A

Does this PR introduce any user-facing change?

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

…allelism

SGLang consumes the fused MLA a_proj per tensor-parallel rank as [q_i ; kv_i],
and AWEX chunks the writer-side tensor on dim 0. A plain cat([q_all, kv_all])
therefore hands rank i a slice straddling q and kv. Both layouts have the same
shape, so the mismatch corrupts attention silently: generations stay
structurally intact and keep emitting EOS while the content degrades to token
soup, and the train/inference logprob divergence grows with every transfer.

Restore the interleaved packing for the train attention-TP case and keep the
plain concatenation when there is no train attention TP, where the parameter
reaches every rank uncut and has to match SGLang's own load_weights layout.
@Le8r0nJames
Le8r0nJames marked this pull request as ready for review August 17, 2026 09:09
@chaokunyang
chaokunyang merged commit a04b2f8 into inclusionAI:main Aug 19, 2026
3 checks passed
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.

2 participants