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
MatmulFusedPartialRMSNorm
struct MatmulFusedPartialRMSNorm
Fuses GEMV (M=1 matmul) with partial RMS normalization.
Computes y = x @ W.T, then applies RMS normalization to the first N_normed columns while passing the remaining columns through unchanged.
Implemented traitsβ
Methodsβ
executeβ
static def execute[dtype: DType, rank: Int, target: StringSlice[ImmStaticOrigin], transpose_b: Bool = True](normed_output: ManagedTensorSlice[IOSpec[_, _].Output, static_spec=normed_output.static_spec], unnormed_output: ManagedTensorSlice[IOSpec[_, _].Output, static_spec=unnormed_output.static_spec], input: ManagedTensorSlice[IOSpec[_, _].Input, static_spec=input.static_spec], weight: ManagedTensorSlice[IOSpec[_, _].Input, static_spec=weight.static_spec], gamma: ManagedTensorSlice[IOSpec[_, _].Input, static_spec=gamma.static_spec], epsilon: Float32, weight_offset: Scalar[dtype], ctx: DeviceContext)
Execute fused GEMV + partial RMS norm.
Calls gemv_and_partial_norm from nn.gemv_partial_norm which
computes y = x @ W.T, then partitions y into normed and
unnormed outputs.
Parameters:
- βdtype (
DType): Element type of all input and output tensors. - βrank (
Int): Tensor rank of the input and output tensors. - βtarget (
StringSlice[ImmStaticOrigin]): The target GPU device. - βtranspose_b (
Bool): Whether to transposeweightbefore the matmul (defaults toTrue).
Args:
- βnormed_output (
ManagedTensorSlice[IOSpec[_, _].Output, static_spec=normed_output.static_spec]): Output tensor holding the RMS-normalized leading columns of the matmul result. - βunnormed_output (
ManagedTensorSlice[IOSpec[_, _].Output, static_spec=unnormed_output.static_spec]): Output tensor holding the trailing columns of the matmul result, passed through unchanged. - βinput (
ManagedTensorSlice[IOSpec[_, _].Input, static_spec=input.static_spec]): Input activation tensorxof the GEMV. - βweight (
ManagedTensorSlice[IOSpec[_, _].Input, static_spec=weight.static_spec]): Weight matrixWof shape(N, K)(rank 2). - βgamma (
ManagedTensorSlice[IOSpec[_, _].Input, static_spec=gamma.static_spec]): RMS normalization scale vector (rank 1). - βepsilon (
Float32): Small constant added to the squared mean before the reciprocal square root for numerical stability. - βweight_offset (
Scalar[dtype]): Reserved for API consistency with other RMS norm ops; not consumed by this kernel. - βctx (
DeviceContext): The 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!