For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
Mojo struct
MXFormat
struct MXFormat
Names the element encoding of an OCP microscaling (MX) operand.
An MX operand is a block of elements sharing one float8_e8m0fnu scale;
this type names the encoding of the elements, which is all that varies
between MXFP4, MXFP6 and MXFP8.
Deliberately not tied to any vendor: AMD CDNA4 selects these through its
f8f6f4 MFMA selector and NVIDIA through its own block-scaled MMA, so the
numeric values here are ours and each backend maps them to its own encoding
(see CDNA4F8F6F4MatrixFormat.__init__ for the CDNA4 mapping). Kernels that
are not hardware-specific -- EP dispatch packing, quantization, layout
math -- should carry this type rather than a vendor selector.
Prefer deriving it from a dtype with from_dtype, so the format travels
with the data instead of being inferred at each call site.
Implemented traitsβ
AnyType,
Copyable,
Deinitable,
Equatable,
ImplicitlyCopyable,
Movable,
RegisterPassable,
TrivialRegisterPassable
comptime membersβ
FP4_E2M1β
comptime FP4_E2M1 = MXFormat(Int(4))
FP6_E2M3β
comptime FP6_E2M3 = MXFormat(Int(2))
FP6_E3M2β
comptime FP6_E3M2 = MXFormat(Int(3))
FP8_E4M3β
comptime FP8_E4M3 = MXFormat(Int(0))
FP8_E5M2β
comptime FP8_E5M2 = MXFormat(Int(1))
Methodsβ
__init__β
def __init__(value: Int) -> Self
__eq__β
from_dtypeβ
static def from_dtype[dtype: DType]() -> Self
Returns the MX format a quantized operand dtype denotes.
Parameters:
- βdtype (
DType): The storage dtype of the quantized elements.
Returns:
Self: The corresponding MX element format.
from_nameβ
static def from_name[name: StringSpan[ImmStaticOrigin]]() -> Self
Returns the MX format a graph-parameter name denotes.
Parameters:
- βname (
StringSpan[ImmStaticOrigin]): One ofmxfp4,mxfp6,mxfp6_e3m2,mxfp8,mxfp8_e5m2. The baremxfp6andmxfp8select the encoding each format defaults to, E2M3 and E4M3.
Returns:
Self: The corresponding MX element format.
bits_per_elementβ
def bits_per_element(self) -> Int
Returns how many bits one element of this format occupies.
This is the payload width, not the fragment width: 32 FP6 elements occupy 24 bytes but travel in a wider fragment on some hardware.
Returns:
Int: The element width in bits.
is_fp6β
def is_fp6(self) -> Bool
Returns whether this is one of the two six-bit encodings.
Returns:
Bool: True for FP6_E2M3 and FP6_E3M2.
fp6_formatβ
def fp6_format(self) -> FP6Format
Returns the FP6 element encoding, for the FP6 packing routines.
Both FP6 encodings occupy six bits and pack four codes into three bytes, so nothing downstream can tell them apart from the bytes alone -- this format is the only record of which one they hold.
Returns:
FP6Format: The matching FP6Format.