Repository navigation
Enable quantized multi-token-prediction - #5141
Merged
Merged
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for quantizing Multi-Token Prediction (MTP) layers in MaxText when using FP8 quantization (fp8_full). It adds a new configuration parameter quantize_mtp (defaulting to false), along with validation rules, updates to Qwix quantization rules to target the mtp_block module path, and handling for cases where GMM quantization rules are absent. Additionally, a verification script and unit tests have been added to ensure correct interception behavior. There are no review comments, so I have no feedback to provide.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
shuningjin
force-pushed
the
shuningjin-mtp
branch
from
September 4, 2026 18:05
4ba5680 to
1ae817e
Compare
shuningjin
marked this pull request as ready for review
September 4, 2026 18:09
shuningjin
requested review from
A9isha,
NuojCheng,
RissyRan,
SurbhiJainUSC,
abhinavclemson,
aireenmei,
bvandermoon,
darisoy,
dipannita08,
gagika,
gobbleturk,
hengtaoguo,
huytransformer,
igorts-git,
jiangjy1982,
jshin1394,
khatwanimohit,
liudangyi,
michelle-yooh,
richjames0,
shralex,
vipannalla,
xibinliu and
zxhe-sean
as code owners
September 4, 2026 18:09
CaptainO5
approved these changes
Sep 4, 2026
RissyRan
approved these changes
Sep 5, 2026
copybara-service Bot
pushed a commit
that referenced
this pull request
Oct 6, 2026
`use_sliced_mla_proj` slices the single `wq_b` / `wkv_b` kernel param before a plain `lax.dot_general` (see `DenseGeneral(slice_bounds=...)`). With Qwix interception quantization (`use_qwix_quantization=True`), the layers keep `quant=None`, and Qwix intercepts that dot_general by module path. So the sliced projections are still quantized in both forward and backward. The current config check rejects every quantized config, which blocks sliced MLA projections for Qwix-quantized (e.g. fp8) training. ### Tests Updated `tests/unit/configs_value_test.py` (non-Qwix quantization still rejected, Qwix allowed, Qwix + batch split rejected). #### Auxiliary Test (similar to [PR#5141](#5141)) Sliced MLA (`use_sliced_mla_proj`) + Qwix: interception correct. [internal link] [full [internal link] ``` # use_sliced_mla_proj=false [QWIX] module='decoder/moe_layers/self_attention/wq_b' op=dot_general0 rule=0 ... [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wq_b' op=dot_general0 rule=0 # use_sliced_mla_proj=true [QWIX] module='decoder/moe_layers/self_attention/wq_b' op=dot_general0 rule=0 [QWIX] module='decoder/moe_layers/self_attention/wq_b' op=dot_general1 rule=0 ... [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wq_b' op=dot_general0 rule=0 [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wq_b' op=dot_general1 rule=0 ``` PiperOrigin-RevId: 994611405
4 tasks done
copybara-service Bot
pushed a commit
that referenced
this pull request
Oct 6, 2026
`use_sliced_mla_proj` slices the single `wq_b` / `wkv_b` kernel param before a plain `lax.dot_general` (see `DenseGeneral(slice_bounds=...)`). With Qwix interception quantization (`use_qwix_quantization=True`), the layers keep `quant=None`, and Qwix intercepts that dot_general by module path. So the sliced projections are still quantized in both forward and backward. The current config check rejects every quantized config, which blocks sliced MLA projections for Qwix-quantized (e.g. fp8) training. # Tests Updated `tests/unit/configs_value_test.py` (non-Qwix quantization still rejected, Qwix allowed, Qwix + batch split rejected). #### Auxiliary Test (similar to [PR#5141](#5141)) Sliced MLA (`use_sliced_mla_proj`) + Qwix: interception correct. [internal link] [full [internal link] ``` # use_sliced_mla_proj=false [QWIX] module='decoder/moe_layers/self_attention/wq_b' op=dot_general0 rule=0 --- [QWIX] module='decoder/moe_layers/self_attention/wkv_b' op=dot_general0 rule=0 --- [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wq_b' op=dot_general0 rule=0 --- [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wkv_b' op=dot_general0 rule=0 # use_sliced_mla_proj=true [QWIX] module='decoder/moe_layers/self_attention/wq_b' op=dot_general0 rule=0 [QWIX] module='decoder/moe_layers/self_attention/wq_b' op=dot_general1 rule=0 --- [QWIX] module='decoder/moe_layers/self_attention/wkv_b' op=dot_general0 rule=0 [QWIX] module='decoder/moe_layers/self_attention/wkv_b' op=dot_general1 rule=0 --- [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wq_b' op=dot_general0 rule=0 [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wq_b' op=dot_general1 rule=0 --- [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wkv_b' op=dot_general0 rule=0 [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wkv_b' op=dot_general1 rule=0 ``` # Checklist - [X] I have performed a self-review of my code. - [X] I have necessary comments in my code, particularly in hard-to-understand areas. - [X] I have run end-to-end tests tests and provided workload links above if applicable. - [X] I have made or will make corresponding changes to the doc if needed. PiperOrigin-RevId: 994611405
copybara-service Bot
pushed a commit
that referenced
this pull request
Oct 6, 2026
`use_sliced_mla_proj` slices the single `wq_b` / `wkv_b` kernel param before a plain `lax.dot_general` (see `DenseGeneral(slice_bounds=...)`). With Qwix interception quantization (`use_qwix_quantization=True`), the layers keep `quant=None`, and Qwix intercepts that dot_general by module path. So the sliced projections are still quantized in both forward and backward. The current config check rejects every quantized config, which blocks sliced MLA projections for Qwix-quantized (e.g. fp8) training. # Tests Updated `tests/unit/configs_value_test.py` (non-Qwix quantization still rejected, Qwix allowed, Qwix + batch split rejected). #### Auxiliary Test (similar to [PR#5141](#5141)) Sliced MLA (`use_sliced_mla_proj`) + Qwix: interception correct. [internal link] [full [internal link] ``` # use_sliced_mla_proj=false [QWIX] module='decoder/moe_layers/self_attention/wq_b' op=dot_general0 rule=0 --- [QWIX] module='decoder/moe_layers/self_attention/wkv_b' op=dot_general0 rule=0 --- [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wq_b' op=dot_general0 rule=0 --- [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wkv_b' op=dot_general0 rule=0 # use_sliced_mla_proj=true [QWIX] module='decoder/moe_layers/self_attention/wq_b' op=dot_general0 rule=0 [QWIX] module='decoder/moe_layers/self_attention/wq_b' op=dot_general1 rule=0 --- [QWIX] module='decoder/moe_layers/self_attention/wkv_b' op=dot_general0 rule=0 [QWIX] module='decoder/moe_layers/self_attention/wkv_b' op=dot_general1 rule=0 --- [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wq_b' op=dot_general0 rule=0 [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wq_b' op=dot_general1 rule=0 --- [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wkv_b' op=dot_general0 rule=0 [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wkv_b' op=dot_general1 rule=0 ``` # Checklist - [X] I have performed a self-review of my code. - [X] I have necessary comments in my code, particularly in hard-to-understand areas. - [X] I have run end-to-end tests tests and provided workload links above if applicable. - [X] I have made or will make corresponding changes to the doc if needed. PiperOrigin-RevId: 994611405
copybara-service Bot
pushed a commit
that referenced
this pull request
Oct 7, 2026
`use_sliced_mla_proj` slices the single `wq_b` / `wkv_b` kernel param before a plain `lax.dot_general` (see `DenseGeneral(slice_bounds=...)`). With Qwix interception quantization (`use_qwix_quantization=True`), the layers keep `quant=None`, and Qwix intercepts that dot_general by module path. So the sliced projections are still quantized in both forward and backward. The current config check rejects every quantized config, which blocks sliced MLA projections for Qwix-quantized (e.g. fp8) training. # Tests Updated `tests/unit/configs_value_test.py` (non-Qwix quantization still rejected, Qwix allowed, Qwix + batch split rejected). #### Auxiliary Test (similar to [PR#5141](#5141)) Sliced MLA (`use_sliced_mla_proj`) + Qwix: interception correct. [internal link] [full [internal link] ``` # use_sliced_mla_proj=false [QWIX] module='decoder/moe_layers/self_attention/wq_b' op=dot_general0 rule=0 --- [QWIX] module='decoder/moe_layers/self_attention/wkv_b' op=dot_general0 rule=0 --- [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wq_b' op=dot_general0 rule=0 --- [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wkv_b' op=dot_general0 rule=0 # use_sliced_mla_proj=true [QWIX] module='decoder/moe_layers/self_attention/wq_b' op=dot_general0 rule=0 [QWIX] module='decoder/moe_layers/self_attention/wq_b' op=dot_general1 rule=0 --- [QWIX] module='decoder/moe_layers/self_attention/wkv_b' op=dot_general0 rule=0 [QWIX] module='decoder/moe_layers/self_attention/wkv_b' op=dot_general1 rule=0 --- [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wq_b' op=dot_general0 rule=0 [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wq_b' op=dot_general1 rule=0 --- [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wkv_b' op=dot_general0 rule=0 [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wkv_b' op=dot_general1 rule=0 ``` # Checklist - [X] I have performed a self-review of my code. - [X] I have necessary comments in my code, particularly in hard-to-understand areas. - [X] I have run end-to-end tests tests and provided workload links above if applicable. - [X] I have made or will make corresponding changes to the doc if needed. PiperOrigin-RevId: 994611405
copybara-service Bot
pushed a commit
that referenced
this pull request
Oct 7, 2026
`use_sliced_mla_proj` slices the single `wq_b` / `wkv_b` kernel param before a plain `lax.dot_general` (see `DenseGeneral(slice_bounds=...)`). With Qwix interception quantization (`use_qwix_quantization=True`), the layers keep `quant=None`, and Qwix intercepts that dot_general by module path. So the sliced projections are still quantized in both forward and backward. The current config check rejects every quantized config, which blocks sliced MLA projections for Qwix-quantized (e.g. fp8) training. # Tests Updated `tests/unit/configs_value_test.py` (non-Qwix quantization still rejected, Qwix allowed, Qwix + batch split rejected). #### Auxiliary Test (similar to [PR#5141](#5141)) Sliced MLA (`use_sliced_mla_proj`) + Qwix: interception correct. [internal link] [full [internal link] ``` # use_sliced_mla_proj=false [QWIX] module='decoder/moe_layers/self_attention/wq_b' op=dot_general0 rule=0 --- [QWIX] module='decoder/moe_layers/self_attention/wkv_b' op=dot_general0 rule=0 --- [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wq_b' op=dot_general0 rule=0 --- [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wkv_b' op=dot_general0 rule=0 # use_sliced_mla_proj=true [QWIX] module='decoder/moe_layers/self_attention/wq_b' op=dot_general0 rule=0 [QWIX] module='decoder/moe_layers/self_attention/wq_b' op=dot_general1 rule=0 --- [QWIX] module='decoder/moe_layers/self_attention/wkv_b' op=dot_general0 rule=0 [QWIX] module='decoder/moe_layers/self_attention/wkv_b' op=dot_general1 rule=0 --- [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wq_b' op=dot_general0 rule=0 [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wq_b' op=dot_general1 rule=0 --- [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wkv_b' op=dot_general0 rule=0 [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wkv_b' op=dot_general1 rule=0 ``` # Checklist - [X] I have performed a self-review of my code. - [X] I have necessary comments in my code, particularly in hard-to-understand areas. - [X] I have run end-to-end tests tests and provided workload links above if applicable. - [X] I have made or will make corresponding changes to the doc if needed. PiperOrigin-RevId: 994611405
copybara-service Bot
pushed a commit
that referenced
this pull request
Oct 7, 2026
`use_sliced_mla_proj` slices the single `wq_b` / `wkv_b` kernel param before a plain `lax.dot_general` (see `DenseGeneral(slice_bounds=...)`). With Qwix interception quantization (`use_qwix_quantization=True`), the layers keep `quant=None`, and Qwix intercepts that dot_general by module path. So the sliced projections are still quantized in both forward and backward. The current config check rejects every quantized config, which blocks sliced MLA projections for Qwix-quantized (e.g. fp8) training. # Tests Updated `tests/unit/configs_value_test.py` (non-Qwix quantization still rejected, Qwix allowed, Qwix + batch split rejected). #### Auxiliary Test (similar to [PR#5141](#5141)) Sliced MLA (`use_sliced_mla_proj`) + Qwix: interception correct. [internal link] [full [internal link] ``` # use_sliced_mla_proj=false [QWIX] module='decoder/moe_layers/self_attention/wq_b' op=dot_general0 rule=0 --- [QWIX] module='decoder/moe_layers/self_attention/wkv_b' op=dot_general0 rule=0 --- [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wq_b' op=dot_general0 rule=0 --- [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wkv_b' op=dot_general0 rule=0 # use_sliced_mla_proj=true [QWIX] module='decoder/moe_layers/self_attention/wq_b' op=dot_general0 rule=0 [QWIX] module='decoder/moe_layers/self_attention/wq_b' op=dot_general1 rule=0 --- [QWIX] module='decoder/moe_layers/self_attention/wkv_b' op=dot_general0 rule=0 [QWIX] module='decoder/moe_layers/self_attention/wkv_b' op=dot_general1 rule=0 --- [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wq_b' op=dot_general0 rule=0 [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wq_b' op=dot_general1 rule=0 --- [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wkv_b' op=dot_general0 rule=0 [QWIX] module='mtp_block/mtp_layer_1/mtp_1_transformer_layer/self_attention/wkv_b' op=dot_general1 rule=0 ``` # Checklist - [X] I have performed a self-review of my code. - [X] I have necessary comments in my code, particularly in hard-to-understand areas. - [X] I have run end-to-end tests tests and provided workload links above if applicable. - [X] I have made or will make corresponding changes to the doc if needed. PiperOrigin-RevId: 994917175
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.
Description
Enables FP8 quantization support for Multi-Token Prediction (MTP) layers via Qwix interception.
Bug: b/552423947
Changes:
base.yml), Addedquantize_mtpflag (default:false). Requiresmtp_num_layers > 0andquantization='fp8_full'quantizaiton.py), Inget_fp8_full_qwix_rule_w_sparsity, expanded the rule target module path to include(decoder/.*layers.*|mtp_block/.*)whenquantize_mtp=True.multi_token_prediction_test.py):MTPQwixInterceptionTestAdditional Change:
fp8_full, main model's MoE blocks match Qwix rule. MTP's MoE blocks can have no Qwix rule ifquantize_mtp=False.More Context - model structure: log
Tests
Unit Tests
Verified Qwix interception tracing for
mtp_blockdot_general ops under CPU abstract evaluation:JAX_PLATFORMS=cpu pytest tests/unit/multi_token_prediction_test.py -k "MTPQwixInterceptionTest"Auxiliary Test
Qwix log: MTP interception correct. script, log
E2E Validation
Checklist
Before submitting this PR, please make sure (put X in square brackets):