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 struct
MXFP4TokenFormat
struct MXFP4TokenFormat[fp4_dtype: DType, scales_dtype: DType, output_layout: TensorLayout, scales_layout: TensorLayout, //, _hid_dim: Int, _top_k: Int, _alignment: Int = Int(0), *, fuse_a_scale_preshuffle: Bool = False]
Token format for MX (microscaling) FP4 quantization.
Packs each token as FP4 values with block-wise MX scale factors (one
float8_e8m0fnu scale per MXFP4_SF_VECTOR_SIZE elements). Achieves the
highest compression ratio of all built-in token formats. Setting
fuse_a_scale_preshuffle=True folds the grouped-matmul scale preshuffle
into the dispatch-wait copy path (KS224 up-projection fusion).
Parametersβ
- βfp4_dtype (
DType): FP4 element dtype (e.g.DType.uint8with nibble packing). - βscales_dtype (
DType): MX scale dtype (DType.float8_e8m0fnu). - βoutput_layout (
TensorLayout): Layout of the FP4 outputTileTensor. - βscales_layout (
TensorLayout): Layout of the scale outputTileTensor. - β_hid_dim (
Int): Hidden dimension; must be divisible by the group size (MXFP4_SF_VECTOR_SIZE). - β_top_k (
Int): Number of experts each token is routed to. - β_alignment (
Int): Override for the byte alignment of the wire buffer; 0 selectsget_device_alignment(). - βfuse_a_scale_preshuffle (
Bool): WhenTrue, fuses the per-expert scale preshuffle into the tile copy for reduced memory traffic.
Fieldsβ
- βoutput_tokens (
MXFP4TokenFormat[_hid_dim, _top_k, _alignment, fuse_a_scale_preshuffle=fuse_a_scale_preshuffle].TensorType): - βoutput_scales (
MXFP4TokenFormat[_hid_dim, _top_k, _alignment, fuse_a_scale_preshuffle=fuse_a_scale_preshuffle].ScalesTensorType): - βmax_padded_M (
Int):
Implemented traitsβ
AnyType,
Copyable,
DevicePassable,
ImplicitlyCopyable,
ImplicitlyDeletable,
Movable,
RegisterPassable,
TokenFormat,
TrivialRegisterPassable
comptime membersβ
alignmentβ
comptime alignment = _alignment if _alignment.__bool__() else get_device_alignment()
device_typeβ
comptime device_type = MXFP4TokenFormat[_hid_dim, _top_k, _alignment, fuse_a_scale_preshuffle=fuse_a_scale_preshuffle]
dispatch_smem_sizeβ
comptime dispatch_smem_size = 0
dispatch_wait_tile_shapeβ
comptime dispatch_wait_tile_shape = Tuple(Int(128), Int(1))
group_sizeβ
comptime group_size = MXFP4_SF_VECTOR_SIZE
hid_dimβ
comptime hid_dim = _hid_dim
ScalesTensorTypeβ
comptime ScalesTensorType = TileTensor[scales_dtype, scales_layout, MutUntrackedOrigin]
TensorTypeβ
comptime TensorType = TileTensor[fp4_dtype, output_layout, MutUntrackedOrigin]
top_kβ
comptime top_k = _top_k
Methodsβ
__init__β
def __init__(output_tokens: TileTensor[fp4_dtype, output_layout, address_space=output_tokens.address_space, linear_idx_type=output_tokens.linear_idx_type], output_scales: TileTensor[scales_dtype, scales_layout, address_space=output_scales.address_space, linear_idx_type=output_scales.linear_idx_type], max_padded_M: Int = Int(0)) -> Self
get_type_nameβ
fp4_quant_sizeβ
scales_sizeβ
token_sizeβ
scales_offsetβ
copy_token_to_send_bufβ
static def copy_token_to_send_buf[src_type: DType, block_size: Int, buf_addr_space: AddressSpace = AddressSpace.GENERIC](buf_p: Pointer[UInt8, address_space=buf_addr_space, _safe=False], src_p: Pointer[Scalar[src_type], address_space=src_p.address_space, _safe=False], input_scale: Float32)
copy_msg_to_output_tensorβ
def copy_msg_to_output_tensor[buf_addr_space: AddressSpace = AddressSpace.GENERIC](self, buf_p: Pointer[UInt8, address_space=buf_addr_space, _safe=False], token_index: Int, expert_slot: Int = Int(0), expert_start: Int = Int(0))
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!