Support quantization for tokamax gmm v2 - #4451
Conversation
2f59d6c to
f814413
Compare
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
| # this scale inside the kernel. | ||
| dlhs_dout = _dlhs_scale_grad_by_rhs_scale(dlhs_dout, rhs, group_sizes, transpose_rhs) | ||
| rhs = rhs.qvalue | ||
|
|
There was a problem hiding this comment.
lhs needs to be quantized here, since we are skipping it in the fwd pass when gmm_v2_fwd is enabled.
| if quantization_rule.act_qtype and not isinstance(lhs, qpl.QArray): | |
| lhs = qpl.quantize( | |
| lhs, | |
| quantization_rule.act_qtype, | |
| channelwise_axes=[] if quantization_rule.disable_channelwise_axes else [0], | |
| calibration_method=quantization_rule.act_calibration_method, | |
| ) | |
There was a problem hiding this comment.
Thanks for the catch! I have corrected the asdtype to qpl.quantize for lhs quantization in bwd.
4b8242f to
201a8fc
Compare
83da967 to
7557153
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.
| ("tokamax_v1_fp8", "fp8_full", False, 1), | ||
| ("tokamax_v2_bf16", "", True, 1), | ||
| ("tokamax_v2_fp8", "fp8_full", True, 1), | ||
| ("tokamax_v2_bf16", "", True, 2), |
There was a problem hiding this comment.
nit: tokamax_v2_bf16_ep, and similar to test name bellow
| ici_expert_parallelism: int, | ||
| ): | ||
| """Smoke train with small config.""" | ||
| sharding_tolerance = 0.22 if ici_expert_parallelism > 1 else 2e-2 |
There was a problem hiding this comment.
Do you need sharding_tolerance in your end-to-end run? If so, could we create a bug to track which part is unsharded. I think we should debug this with
maxtext/src/maxtext/configs/base.yml
Line 1077 in 17c7172
| "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?
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
Unit test: smoke train
https://paste.googleplex.com/6354648482054144
Unit test: value and gradient equivalence
https://paste.googleplex.com/4962768028565504
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.