Skip to content

Commit a60b28c

Browse files
Add FP4 [E2M1] support to Maxtext [Model convergence not tested yet].
PiperOrigin-RevId: 952967390
1 parent ad841c4 commit a60b28c

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

src/maxtext/configs/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class QuantizationType(str, Enum):
8484
"""Supported quantization schemes."""
8585

8686
NONE = ""
87+
FP4 = "fp4"
8788
INT4 = "int4"
8889
INT8 = "int8"
8990
INTMP = "intmp"

src/maxtext/layers/quantizations.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,9 @@ def make_qt_rule(dtype) -> list[qwix.QtRule]:
824824
case "int8":
825825
return make_qt_rule(jnp.int8)
826826

827+
case "fp4" | "fp4_e2m1":
828+
return make_qt_rule(jnp.float4_e2m1fn)
829+
827830
case "fp8_e5m2":
828831
return make_qt_rule(jnp.float8_e5m2)
829832

@@ -841,7 +844,7 @@ def make_qt_rule(dtype) -> list[qwix.QtRule]:
841844
def get_qt_provider(config):
842845
"""Get quantization rules based on the config."""
843846
match config.quantization:
844-
case "int4" | "int8" | "fp8" | "fp8_e5m2" | "fp8_e4m3" | "fp8_full":
847+
case "int4" | "int8" | "fp4" | "fp4_e2m1" | "fp8" | "fp8_e5m2" | "fp8_e4m3" | "fp8_full":
845848
return qwix.QtProvider(get_quantization_rule(config))
846849
case "fp8_gpu":
847850
return NvidaFp8Provider(get_quantization_rule(config))

0 commit comments

Comments
 (0)