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 function
grouped_quantize_dynamic_scaled_fp4_async_kernel
def grouped_quantize_dynamic_scaled_fp4_async_kernel[output_dtype: DType, scales_dtype: DType, input_dtype: DType, scales_tile_rank: Int, scales_tile_shape: IndexList[scales_tile_rank], scales_desc_shape: IndexList[scales_tile_rank], scales_swizzle_mode: TensorMapSwizzle, output_layout: TensorLayout, input_layout: TensorLayout, row_offsets_layout: TensorLayout, scales_offsets_layout: TensorLayout, expert_ids_layout: TensorLayout, sf_layout: TensorLayout, num_threads: Int = Int(128)](output_tensor: TileTensor[output_dtype, output_layout, MutAnyOrigin], scales_tma_op: TMATensorTile[scales_dtype, scales_tile_rank, scales_tile_shape, scales_desc_shape], input_tensor: TileTensor[input_dtype, input_layout, ImmutAnyOrigin], row_offsets: TileTensor[DType.uint32, row_offsets_layout, ImmutAnyOrigin], scales_offsets: TileTensor[DType.uint32, scales_offsets_layout, ImmutAnyOrigin], expert_ids: TileTensor[DType.int32, expert_ids_layout, ImmutAnyOrigin], sf_tensor: TileTensor[DType.float32, sf_layout, ImmutAnyOrigin])
GPU kernel that quantizes per-expert BF16 activation tiles to NVFP4/MXFP4/MXFP8 with TMA-based scale-factor stores.
Each block locates its assigned expert via binary search on
row_offsets and scales_offsets, then quantizes the expert's
activation tile and writes scale factors back through TMA async
stores.
Parameters:
- βoutput_dtype (
DType): Element type of the quantized output tensor (inferred). - βscales_dtype (
DType): Element type of the block scale-factor tensor (inferred). - βinput_dtype (
DType): Element type of the input activation tensor (inferred). - βscales_tile_rank (
Int): Rank of the scales TMA tile descriptor (inferred). - βscales_tile_shape (
IndexList[scales_tile_rank]): Per-dimension tile shape of the scales TMA descriptor (inferred). - βscales_desc_shape (
IndexList[scales_tile_rank]): Per-dimension descriptor shape of the scales TMA descriptor (inferred). - βscales_swizzle_mode (
TensorMapSwizzle): Swizzle mode applied to the scales TMA descriptor (inferred). - βoutput_layout (
TensorLayout): TileTensor layout of the quantized output tensor (inferred). - βinput_layout (
TensorLayout): TileTensor layout of the input activation tensor (inferred). - βrow_offsets_layout (
TensorLayout): TileTensor layout of the per-expert row offsets tensor (inferred). - βscales_offsets_layout (
TensorLayout): TileTensor layout of the per-expert scales offsets tensor (inferred). - βexpert_ids_layout (
TensorLayout): TileTensor layout of the expert IDs tensor (inferred). - βsf_layout (
TensorLayout): TileTensor layout of the per-expert tensor-wise scale factor tensor (inferred). - βnum_threads (
Int): Number of threads per block in the launch grid (defaults to 128).
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!