|
36 | 36 | from MaxText.layers import attentions, linears, quantizations, nnx_wrappers |
37 | 37 | from MaxText.layers.initializers import NdInitializer, nd_dense_init, default_bias_init, variable_to_logically_partitioned |
38 | 38 |
|
| 39 | +if jax.__version__ >= "0.8.0": |
| 40 | + from tokamax._src.ops.ragged_dot import api as tokamax_api |
| 41 | + |
39 | 42 | set_xla_metadata = xla_metadata.set_xla_metadata |
40 | 43 |
|
41 | 44 |
|
@@ -807,16 +810,26 @@ def gmm(inputs, kernel, tiling, group_sizes, expert_assignments): |
807 | 810 | min(tiling[2], n), |
808 | 811 | ) |
809 | 812 | if self.config.megablox: |
810 | | - output = mblx.gmm( |
811 | | - lhs=inputs, |
812 | | - rhs=kernel, |
813 | | - group_sizes=group_sizes, |
814 | | - preferred_element_type=self.dtype, |
815 | | - tiling=tiling, |
816 | | - lhs_quantize_dtype=lhs_quantize_dtype, |
817 | | - rhs_quantize_dtype=rhs_quantize_dtype, |
818 | | - use_qwix_quantization=self.config.use_qwix_quantization, |
819 | | - ) |
| 813 | + if self.config.use_tokamax_gmm: |
| 814 | + output = tokamax_api.ragged_dot( # pylint: disable=possibly-used-before-assignment |
| 815 | + lhs=inputs, |
| 816 | + rhs=kernel, |
| 817 | + group_sizes=group_sizes, |
| 818 | + precision=jax.lax.Precision.DEFAULT, |
| 819 | + preferred_element_type=self.dtype, |
| 820 | + implementation="mosaic", |
| 821 | + ) |
| 822 | + else: |
| 823 | + output = mblx.gmm( |
| 824 | + lhs=inputs, |
| 825 | + rhs=kernel, |
| 826 | + group_sizes=group_sizes, |
| 827 | + preferred_element_type=self.dtype, |
| 828 | + tiling=tiling, |
| 829 | + lhs_quantize_dtype=lhs_quantize_dtype, |
| 830 | + rhs_quantize_dtype=rhs_quantize_dtype, |
| 831 | + use_qwix_quantization=self.config.use_qwix_quantization, |
| 832 | + ) |
820 | 833 | else: |
821 | 834 | rhs_inputs = kernel |
822 | 835 | if isinstance(kernel, aqt.QTensor): |
|
0 commit comments