.. meta::
    :description: SwiGLU MLP forward with MXFP8-quantized matmuls, one contiguous token block per core.
    :date-modified: 11/30/2026

.. currentmodule:: nkilib.experimental.mlp_mxfp8.mlp_fwd_mxfp8

MLP Forward MXFP8 Kernel API Reference
======================================

SwiGLU MLP forward with MXFP8-quantized matmuls, one contiguous token block per core.

Background
-----------

``mlp_forward_mxfp8_nki`` computes a single SwiGLU MLP, ``(SiLU(hidden @ gate) * (hidden @ up)) @ down``, with MXFP8-quantized matmuls and no routing or expert affinities. It runs two blocks of T/2 tokens per core and returns the activation checkpoint consumed by ``mlp_backward_mxfp8_nki``.

API Reference
--------------

**Source code for this kernel API can be found at**: `mlp_fwd_mxfp8_kernel.py <https://github.com/aws-neuron/nki-library/blob/2.34/src/nkilib_src/nkilib/experimental/mlp_mxfp8/mlp_fwd_mxfp8/mlp_fwd_mxfp8_kernel.py>`_

mlp_forward_mxfp8_nki
^^^^^^^^^^^^^^^^^^^^^

.. py:function:: mlp_forward_mxfp8_nki(hidden_states: nl.NkiTensor, gate_up_proj_weight: nl.NkiTensor, down_proj_weight: nl.NkiTensor, config: MXFP8MOEFwdConfig=None, gate_up_weight_scales: nl.NkiTensor=None, down_weight_scales: nl.NkiTensor=None) -> tuple

   Compute a SwiGLU MLP with one contiguous token block per core.

   :param hidden_states: Input hidden states ``[T, H]`` on HBM; T a positive multiple of 256.
   :type hidden_states: ``nl.NkiTensor``
   :param gate_up_proj_weight: Fused gate/up projection weights, BF16 ``[H, 2, I]`` (packed MXFP8 ``[2*H/4, I]`` with scales).
   :type gate_up_proj_weight: ``nl.NkiTensor``
   :param down_proj_weight: Down projection weights, BF16 ``[I, H]`` (packed MXFP8 ``[I/4, H]`` with scales).
   :type down_proj_weight: ``nl.NkiTensor``
   :param config: Kernel configuration (tiling, dtypes, and per-projection ``quant_scheme`` via ``gate_up_config`` / ``down_config``); ``None`` uses defaults.
   :type config: ``MXFP8MOEFwdConfig``
   :param gate_up_weight_scales: MX scales for the gate/up weights; required for packed MXFP8 weights.
   :type gate_up_weight_scales: ``nl.NkiTensor``
   :param down_weight_scales: MX scales for the down weights; required for packed MXFP8 weights.
   :type down_weight_scales: ``nl.NkiTensor``
