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
naive_blockwise_scaled_fp8_grouped_matmul
def naive_blockwise_scaled_fp8_grouped_matmul[c_type: DType, a_type: DType, b_type: DType, a_scales_type: DType, b_scales_type: DType, a_offsets_type: DType, expert_ids_type: DType, c_layout: Layout, a_layout: Layout, b_layout: Layout, a_scale_layout: Layout, b_scale_layout: Layout, a_offsets_layout: Layout, expert_ids_layout: Layout, //, BLOCK_DIM_N: Int = Int(32), BLOCK_DIM_M: Int = Int(16), transpose_b: Bool = True, scales_granularity_mnk: Optional[IndexList[Int(3)]] = None, elementwise_lambda_fn: Optional[def[dtype: DType, width: SIMDLength, *, alignment: Int = Int(1)](IndexList[Int(2)], SIMD[dtype, width]) capturing thin -> None] = None](c: LayoutTensor[c_type, c_layout, address_space=c.address_space, element_layout=c.element_layout, layout_int_type=c.layout_int_type, linear_idx_type=c.linear_idx_type, masked=c.masked, alignment=c.alignment], a: LayoutTensor[a_type, a_layout, address_space=a.address_space, element_layout=a.element_layout, layout_int_type=a.layout_int_type, linear_idx_type=a.linear_idx_type, masked=a.masked, alignment=a.alignment], b: LayoutTensor[b_type, b_layout, address_space=b.address_space, element_layout=b.element_layout, layout_int_type=b.layout_int_type, linear_idx_type=b.linear_idx_type, masked=b.masked, alignment=b.alignment], a_scales: LayoutTensor[a_scales_type, a_scale_layout, address_space=a_scales.address_space, element_layout=a_scales.element_layout, layout_int_type=a_scales.layout_int_type, linear_idx_type=a_scales.linear_idx_type, masked=a_scales.masked, alignment=a_scales.alignment], b_scales: LayoutTensor[b_scales_type, b_scale_layout, address_space=b_scales.address_space, element_layout=b_scales.element_layout, layout_int_type=b_scales.layout_int_type, linear_idx_type=b_scales.linear_idx_type, masked=b_scales.masked, alignment=b_scales.alignment], a_offsets: LayoutTensor[a_offsets_type, a_offsets_layout, address_space=a_offsets.address_space, element_layout=a_offsets.element_layout, layout_int_type=a_offsets.layout_int_type, linear_idx_type=a_offsets.linear_idx_type, masked=a_offsets.masked, alignment=a_offsets.alignment], expert_ids: LayoutTensor[expert_ids_type, expert_ids_layout, address_space=expert_ids.address_space, element_layout=expert_ids.element_layout, layout_int_type=expert_ids.layout_int_type, linear_idx_type=expert_ids.linear_idx_type, masked=expert_ids.masked, alignment=expert_ids.alignment], max_num_tokens_per_expert: Int, num_active_experts: Int, ctx: DeviceContext)
Dispatches the naive blockwise scaled FP8 grouped matmul kernel on the GPU.
Enqueues naive_blockwise_scaled_fp8_grouped_matmul_kernel with one
expert per grid-Z slice, tiling the per-expert M_local x N output
with BLOCK_DIM_M x BLOCK_DIM_N thread blocks.
Args:
- βc (
LayoutTensor[c_type, c_layout, address_space=c.address_space, element_layout=c.element_layout, layout_int_type=c.layout_int_type, linear_idx_type=c.linear_idx_type, masked=c.masked, alignment=c.alignment]): Rank-2 output accumulator tensor holding all expert outputs. - βa (
LayoutTensor[a_type, a_layout, address_space=a.address_space, element_layout=a.element_layout, layout_int_type=a.layout_int_type, linear_idx_type=a.linear_idx_type, masked=a.masked, alignment=a.alignment]): Rank-2 FP8 input matrix in K-major format. - βb (
LayoutTensor[b_type, b_layout, address_space=b.address_space, element_layout=b.element_layout, layout_int_type=b.layout_int_type, linear_idx_type=b.linear_idx_type, masked=b.masked, alignment=b.alignment]): Rank-3 FP8 weight tensor indexed by expert, in K-major format. - βa_scales (
LayoutTensor[a_scales_type, a_scale_layout, address_space=a_scales.address_space, element_layout=a_scales.element_layout, layout_int_type=a_scales.layout_int_type, linear_idx_type=a_scales.linear_idx_type, masked=a_scales.masked, alignment=a_scales.alignment]): Per-block scales forain M-major format. - βb_scales (
LayoutTensor[b_scales_type, b_scale_layout, address_space=b_scales.address_space, element_layout=b_scales.element_layout, layout_int_type=b_scales.layout_int_type, linear_idx_type=b_scales.linear_idx_type, masked=b_scales.masked, alignment=b_scales.alignment]): Per-block scales forbindexed by expert. - βa_offsets (
LayoutTensor[a_offsets_type, a_offsets_layout, address_space=a_offsets.address_space, element_layout=a_offsets.element_layout, layout_int_type=a_offsets.layout_int_type, linear_idx_type=a_offsets.linear_idx_type, masked=a_offsets.masked, alignment=a_offsets.alignment]): Prefix-sum offsets delimiting each expert's rows ina. - βexpert_ids (
LayoutTensor[expert_ids_type, expert_ids_layout, address_space=expert_ids.address_space, element_layout=expert_ids.element_layout, layout_int_type=expert_ids.layout_int_type, linear_idx_type=expert_ids.linear_idx_type, masked=expert_ids.masked, alignment=expert_ids.alignment]): Expert id (or-1to skip) for each grid-Z slice. - βmax_num_tokens_per_expert (
Int): Maximum row count assigned to any single expert. - βnum_active_experts (
Int): Number of active experts to dispatch. - βctx (
DeviceContext): Device context used to enqueue the kernel.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!