For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).
Mojo module
fp4_utils
Provides low-level FP4 encode/decode utilities and scale-factor helpers.
comptime valuesβ
E2M1_TO_FLOAT32β
comptime E2M1_TO_FLOAT32 = SIMD(SIMD(0), SIMD(0.5), SIMD(1), SIMD(1.5), SIMD(2), SIMD(3), SIMD(4), SIMD(6), SIMD(-0.0), SIMD(-0.5), SIMD(-1), SIMD(-1.5), SIMD(-2), SIMD(-3), SIMD(-4), SIMD(-6), __list_literal__=NoneType(None))
FP4_E2M1_MANTISSA_WIDTHβ
comptime FP4_E2M1_MANTISSA_WIDTH = 1
FP4_E2M1_MAX_EXPONENTβ
comptime FP4_E2M1_MAX_EXPONENT = 2
MXFP4_SF_DTYPEβ
comptime MXFP4_SF_DTYPE = DType.float8_e8m0fnu
MXFP4_SF_VECTOR_SIZEβ
comptime MXFP4_SF_VECTOR_SIZE = 32
MXFP8_SF_DTYPEβ
comptime MXFP8_SF_DTYPE = DType.float8_e8m0fnu
MXFP8_SF_VECTOR_SIZEβ
comptime MXFP8_SF_VECTOR_SIZE = 32
NVFP4_SF_DTYPEβ
comptime NVFP4_SF_DTYPE = DType.float8_e4m3fn
NVFP4_SF_VECTOR_SIZEβ
comptime NVFP4_SF_VECTOR_SIZE = 16
SF_ATOM_Kβ
comptime SF_ATOM_K = 4
SF_ATOM_Mβ
comptime SF_ATOM_M = Tuple(Int(32), Int(4))
SF_K_GROUP_SIZEβ
comptime SF_K_GROUP_SIZE[SF_VECTOR_SIZE: Int] = (Int(4) * SF_VECTOR_SIZE)
Parametersβ
- βSF_VECTOR_SIZE (
Int):
SF_MN_GROUP_SIZEβ
comptime SF_MN_GROUP_SIZE = ((load_from_mem SF_ATOM_M.__getitem_param__[Int(0)]()) * (load_from_mem SF_ATOM_M.__getitem_param__[Int(1)]()))
Functionsβ
- β
cast_f4e2m1x2_to_fp16x2: Converts two FP4 E2M1 nibbles packed in one byte to two float16 values using SM100 PTX. - β
cast_float_to_fp4e2m1_amd: Converts up to eight floating-point values to packed FP4 E2M1 using AMD CDNA4 intrinsics. - β
cast_fp32_to_fp4e2m1: Converts eight float32 values to a packed FP4 E2M1 word using SM100 PTX instructions. - β
cast_fp_to_fp4e2m1: Rounds each floating-point element to the nearest FP4 E2M1 representable value. - β
cast_uint_to_fp4e2m1: Unpacks FP4 E2M1 nibbles packed inside unsigned integers to floating-point values. - β
compute_mxfp4_even_scale: Computes the OCP MXFP4 E8M0 scale using even-mode rounding. - β
convert_ref_scales_to_mxfp8_format: Converts reference float32 block scales into the 5D MXFP8 E8M0 scale-factor layout. - β
decode_e2m1_to_bf16: Decodes E2M1 nibbles to bfloat16 with branch-free bit arithmetic. - β
decode_e2m1_to_f16: Decodes E2M1 nibbles to float16 by exponent injection (Preston's trick). - β
decode_e2m1_to_f32: Decodes E2M1 nibbles to float32 with branch-free bit arithmetic. - β
decode_e2m1_to_f32_inject: Decodes E2M1 nibbles to float32 by exponent injection (Preston's trick). - β
get_batched_scale_factor: Loads a scale factor from a 6D batchedLayoutTensorat the given batch, row, and column. - β
get_scale_factor: Loads a scale factor from a 5D non-batchedLayoutTensorat the given row and column. - β
get_scaling_kind: Selects the SM100 UMMA kind matching the operand and scale-factor types. - β
set_batched_scale_factor: Stores a scale factor into a 6D batchedLayoutTensorat the given batch, row, and column. - β
set_scale_factor: Stores a scale factor into a 5D non-batchedLayoutTensorat the given row and column.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!