Repository navigation
Support quantization for tokamax gmm v2 - #4451
Conversation
2f59d6c to
f814413
Compare
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
4b8242f to
201a8fc
Compare
7557153 to
1ad5e94
Compare
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
RissyRan
left a comment
There was a problem hiding this comment.
LGTM, just minor comments, related to tolerance.
| "var_grad": grads_tgt, | ||
| } | ||
|
|
||
| relative_norm_diff_threshold = 0.22 if quantization else 0.012 |
There was a problem hiding this comment.
The tolerance seems high, and is this aligned with other existing quantization tests?
There was a problem hiding this comment.
Current quantization tests do not have correctness check for value or gradient. Quantization would inevitably introduce precision loss.
- For unit test, we can only have a loose check that gaps are not too large. It is hard to determine a proper threshold. Ultimately, we would need E2E to determine the quality.
- In this specific case, since we know what
megabloxortokamax gmm1was previously successful, we can compare the diff oftokamx gmm2against them.
I expanded the test cases, here
gmm_type={megablox, tokamax gmm1, tokamax gmm2}xquant_scheme={bf16, dynamic, fp8_static_wa }, wherefp8_dynamic=absmax for weight/activation/grad andfp8_static_wa=fixed weight+fixed activation+absmax grad- diff is against bf16 dense, log from my v5p-8
Observations:
- For the same gmm type: bf16 < fp8_dymanic < fp8_static_wa. This is expected.
- For the same quantization scheme, different gmm has similar diff. This is expected.
1. relative_norm_diff Across All Cases
| Test Case | output |
state_grad |
grad_gate-kernel |
grad_wi_0 |
grad_wi_1 |
grad_wo |
|---|---|---|---|---|---|---|
megablox_bf16_ep1 |
0.004347 |
0.007798 |
0.007537 |
0.007493 |
0.007523 |
0.006855 |
megablox_fp8_dynamic_ep1 |
0.064479 |
0.064210 |
0.022872 |
0.100576 |
0.100811 |
0.101557 |
megablox_fp8_static_ep1 |
0.153188 |
0.049933 |
0.031198 |
0.189635 |
0.190141 |
0.215808 |
tokamax_v1_bf16_ep1 |
0.004347 |
0.007794 |
0.007531 |
0.007492 |
0.007523 |
0.006855 |
tokamax_v1_fp8_dynamic_ep1 |
0.064479 |
0.064168 |
0.022875 |
0.100574 |
0.100811 |
0.101557 |
tokamax_v1_fp8_static_ep1 |
0.153188 |
0.049933 |
0.031198 |
0.189635 |
0.190141 |
0.215808 |
tokamax_v2_bf16_ep1 |
0.004347 |
0.007798 |
0.007537 |
0.007493 |
0.007523 |
0.006855 |
tokamax_v2_fp8_dynamic_ep1 |
0.064551 |
0.064635 |
0.023685 |
0.100734 |
0.100966 |
0.101706 |
tokamax_v2_fp8_static_ep1 |
0.153188 |
0.049926 |
0.031198 |
0.189628 |
0.190157 |
0.215808 |
tokamax_v2_bf16_ep4 |
0.004347 |
0.007798 |
0.007537 |
0.007099 |
0.007130 |
0.006371 |
tokamax_v2_fp8_dynamic_ep4 |
0.064549 |
0.065041 |
0.023742 |
0.100691 |
0.100953 |
0.101660 |
tokamax_v2_fp8_static_ep4 |
0.153188 |
0.049926 |
0.031198 |
0.189619 |
0.190156 |
0.215799 |
2. max_abs_diff Across All Cases
| Test Case | output |
state_grad |
grad_gate-kernel |
grad_wi_0 |
grad_wi_1 |
grad_wo |
|---|---|---|---|---|---|---|
megablox_bf16_ep1 |
2.44e-04 |
1.64e-11 |
5.95e-09 |
2.33e-10 |
1.75e-10 |
5.89e-11 |
megablox_fp8_dynamic_ep1 |
3.05e-03 |
1.04e-10 |
1.97e-08 |
1.11e-09 |
9.31e-10 |
3.16e-10 |
megablox_fp8_static_ep1 |
7.39e-03 |
8.37e-11 |
2.55e-08 |
2.62e-09 |
2.44e-09 |
6.86e-10 |
tokamax_v1_bf16_ep1 |
2.44e-04 |
1.64e-11 |
5.95e-09 |
2.33e-10 |
1.75e-10 |
5.89e-11 |
tokamax_v1_fp8_dynamic_ep1 |
3.05e-03 |
1.04e-10 |
1.97e-08 |
1.11e-09 |
9.31e-10 |
3.16e-10 |
tokamax_v1_fp8_static_ep1 |
7.39e-03 |
8.37e-11 |
2.55e-08 |
2.62e-09 |
2.44e-09 |
6.86e-10 |
tokamax_v2_bf16_ep1 |
2.44e-04 |
1.64e-11 |
5.95e-09 |
2.33e-10 |
1.75e-10 |
5.89e-11 |
tokamax_v2_fp8_dynamic_ep1 |
3.17e-03 |
1.05e-10 |
2.18e-08 |
1.08e-09 |
1.05e-09 |
3.26e-10 |
tokamax_v2_fp8_static_ep1 |
7.39e-03 |
8.37e-11 |
2.55e-08 |
2.62e-09 |
2.44e-09 |
6.86e-10 |
tokamax_v2_bf16_ep4 |
2.44e-04 |
1.64e-11 |
5.95e-09 |
1.75e-10 |
1.16e-10 |
4.43e-11 |
tokamax_v2_fp8_dynamic_ep4 |
3.36e-03 |
1.05e-10 |
2.18e-08 |
1.11e-09 |
1.06e-09 |
3.48e-10 |
tokamax_v2_fp8_static_ep4 |
7.39e-03 |
8.37e-11 |
2.55e-08 |
2.68e-09 |
2.44e-09 |
6.43e-10 |
There was a problem hiding this comment.
Thanks for the comprehensive tests!
tabakg
left a comment
There was a problem hiding this comment.
LGTM thank you!
One small suggestion for static scales relative error test: inspect the abs-max and insert appropriate scaling values in the test. This way we can avoid excessively loose bounds.
0ec0ad4 to
273a11b
Compare
273a11b to
a866edf
Compare
Description
Integrate quantization of Tokamax GMM V2. This is joint effort with @CaptainO5, built on top of PR#4197.
Bug: b/534817371
What this does
base.yml:use_gmm_v2=trueshould work for quantizationsrc/maxtext/kernels/megablox/ops.py: quantization and scaling integration of gmm2 / tgmm2tests.integration.tokamax_test: smoke traintests.unit.moe_test: value and gradient equivalenceops.py: modularize GMMfwdandbwdfunctions_gmm_fwdand_gmm_bwdwere large, monolithic functions containing complex branching and quantization logic. This is difficult to read and maintain.gmmchecks agaisnt empty rule to ensure quantization is applied; refactor conditionuse_qwix_quantizationto be co-occur withquantization; fix broken link for quantization doc.save_checkpoint_on_startto allow skipping for testinguse_gmm_v2Tests
Unit test
local v5p-8
Unit test: smoke train
log
Unit test: value and gradient equivalence
log
E2E test
We tested in b/534817371, convergence on par with bf16 for fsdp+ep or fsdp.
Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.