This document is relevant for: Trn2, Trn3

MLP Backward MXFP8 Kernel API Reference#

Gradients for the MXFP8 SwiGLU MLP (hidden, gate/up weight, down weight).

Background#

mlp_backward_mxfp8_nki returns the hidden-state, gate/up weight, and down weight gradients of the MXFP8 SwiGLU MLP, consuming the forward’s activation checkpoint. Forward and backward both run two blocks of T/2 tokens.

API Reference#

Source code for this kernel API can be found at: mlp_bwd_mxfp8_kernel.py

mlp_backward_mxfp8_nki#

nkilib.experimental.mlp_mxfp8.mlp_bwd_mxfp8.mlp_backward_mxfp8_nki(hidden_states: nl.NkiTensor, gate_up_proj_weight: nl.NkiTensor, down_proj_weight: nl.NkiTensor, output_hidden_states_grad: nl.NkiTensor, gate_up_proj_act_checkpoint_T: nl.NkiTensor, config: MXFP8MOEBwdConfig = None, gate_up_weight_scales: nl.NkiTensor = None, down_weight_scales: nl.NkiTensor = None) → tuple#

Return gradients for hidden, gate/up weight, and down weight.

Parameters:
  • hidden_states (nl.NkiTensor) – Forward input hidden states [T, H].

  • gate_up_proj_weight (nl.NkiTensor) – Fused gate/up projection weights, BF16 [H, 2, I] (packed MXFP8 [2*I/4, H] with scales).

  • down_proj_weight (nl.NkiTensor) – Down projection weights, BF16 [I, H] (packed MXFP8 [H/4, I] with scales).

  • output_hidden_states_grad (nl.NkiTensor) – Gradient of the forward output.

  • gate_up_proj_act_checkpoint_T (nl.NkiTensor) – Forward activation checkpoint [2, 2, T/2, I] produced by mlp_forward_mxfp8_nki.

  • config (MXFP8MOEBwdConfig) – Kernel configuration; None uses defaults.

  • gate_up_weight_scales (nl.NkiTensor) – MX scales for the gate/up weights.

  • down_weight_scales (nl.NkiTensor) – MX scales for the down weights.

This document is relevant for: Trn2, Trn3