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
fp4_gemv_kernel
def fp4_gemv_kernel[c_type: DType, c_layout: TensorLayout, a_layout: TensorLayout, p_layout: TensorLayout, s_layout: TensorLayout, elementwise_lambda_fn: Optional[def[dtype: DType, width: SIMDLength, *, alignment: Int = Int(1)](IndexList[Int(2)], SIMD[dtype, width]) capturing thin -> None]](c: TileTensor[c_type, c_layout, MutAnyOrigin], a: TileTensor[DType.bfloat16, a_layout, ImmutAnyOrigin], packed: TileTensor[DType.uint8, p_layout, ImmutAnyOrigin], scales: TileTensor[DType.float8_e4m3fn, s_layout, ImmutAnyOrigin], n: Int, k: Int)
One warp per output column; 32 lanes stride down K decoding FP4 -> fp32.
c is [1, N], a the bf16 activation [1, K], packed the FP4 weight
[N, K//2] (lo-nibble first), scales the FP8-E4M3 block scales
[N, ceil(K/16)]. Accumulation is fp32.
Parameters:
- βc_type (
DType): Output element type (fp16, bf16, fp32). Accumulation is fp32. - βc_layout (
TensorLayout):TileTensorlayout of the outputc. - βa_layout (
TensorLayout):TileTensorlayout of the activationa. - βp_layout (
TensorLayout):TileTensorlayout of the packed FP4 weight. - βs_layout (
TensorLayout):TileTensorlayout of the FP8 block scales. - βelementwise_lambda_fn (
Optional[def[dtype: DType, width: SIMDLength, *, alignment: Int = Int(1)](IndexList[Int(2)], SIMD[dtype, width]) capturing thin -> None]): Optional fused epilogue applied on the width-1 store.
Args:
- βc (
TileTensor[c_type, c_layout, MutAnyOrigin]): Output tile tensor[1, N]receiving the GEMV result. - βa (
TileTensor[DType.bfloat16, a_layout, ImmutAnyOrigin]): Bf16 activation tile tensor[1, K], the single activation row. - βpacked (
TileTensor[DType.uint8, p_layout, ImmutAnyOrigin]): FP4-packed weight tile tensor[N, K//2](lo-nibble first). - βscales (
TileTensor[DType.float8_e4m3fn, s_layout, ImmutAnyOrigin]): FP8-E4M3 block scales tile tensor[N, ceil(K/16)]. - βn (
Int): Number of output columns (rows of the transposed weight). - βk (
Int): Inner dimension length; must be a multiple ofNVFP4_SF_VECTOR_SIZE(16).
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!