Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion csrc/fused_moe/noAuxTcKernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ void NoAuxTc(TensorView scores, TensorView bias, int64_t n_group, int64_t topk_g
TVM_FFI_ICHECK(topk_values.dtype() == data_type)
<< "topk_values must have the same dtype as scores";
TVM_FFI_ICHECK(encode_dlpack_dtype(topk_indices.dtype()) == int32_code)
<< "topk_indices must have the same dtype as scores";
<< "topk_indices must be int32 dtype";

// Validate and extract routing_replay_out
// NOTE: dim0 >= num_tokens is intentionally NOT checked — with CUDA graphs the buffer
Expand Down
13 changes: 13 additions & 0 deletions docs/api/fused_moe.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ Utility Functions
interleave_moe_scales_for_sm90_mixed_gemm
fused_topk_deepseek

Multi-LoRA MoE (BGMV)
---------------------

Batched Gather-Matrix-Vector kernels for serving multiple LoRA adapters on
top of a Mixture-of-Experts layer (shrink + expand).

.. autosummary::
:toctree: ../generated

bgmv_moe
bgmv_moe_shrink
bgmv_moe_expand

CUTLASS Fused MoE
-----------------

Expand Down
1 change: 1 addition & 0 deletions docs/api/quantization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ importable.
:toctree: ../generated

nvfp4_quantize_cute_dsl
nvfp4_quantize_per_token_cute_dsl

.. currentmodule:: flashinfer.quantization.kernels.mxfp4_quantize

Expand Down
47 changes: 46 additions & 1 deletion flashinfer/quantization/kernels/nvfp4_quantize.py
Original file line number Diff line number Diff line change
Expand Up @@ -1797,7 +1797,52 @@ def nvfp4_quantize_per_token_cute_dsl(
sf_layout: int = SF_LAYOUT_128x4,
enable_pdl: bool | None = None,
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
"""Per-token NVFP4 activation quantization using CuTe-DSL."""
r"""Per-token NVFP4 activation quantization using the CuTe-DSL kernel.

Unlike :func:`nvfp4_quantize_cute_dsl`, which applies a single global
scale, this variant computes one quantization scale **per row (token)** of
the activation. Each row is scaled independently so that its largest
magnitude maps to the NVFP4 dynamic range, and the resulting per-token
scale is returned alongside the packed FP4 output and the E4M3 block
scale factors.

- E4M3 block scale factors (FP8), ``sf_vec_size = 16``
- E2M1 output format (4-bit, 2 values per byte)
- Supports 128x4, 8x4, and linear scale-factor layouts

The kernel is compiled once per ``(K, dtype, sf_layout, pdl)`` tuple and
handles varying ``M`` (number of tokens) at runtime without recompilation.

Parameters
----------
input : torch.Tensor
2-D activation tensor of shape ``[M, K]`` with dtype fp16/bf16. ``K``
must be divisible by ``NVFP4_SF_VEC_SIZE`` (16).
global_scale_inv : torch.Tensor
Scalar tensor (``float32``) holding the inverse global scale applied on
top of the per-token scale. A Python ``float`` is also accepted and
wrapped into a tensor internally.
sf_layout : int
Scale-factor layout (``0=128x4``, ``1=8x4``, ``2=linear``).
enable_pdl : bool, optional
Whether to enable Programmatic Dependent Launch. Auto-detected from
device capability (SM >= 9.0) when ``None``; pass ``False`` to force it
off.

Returns
-------
Tuple[torch.Tensor, torch.Tensor, torch.Tensor]
``(fp4_output, scale_output, per_token_scale)`` where:

- ``fp4_output`` is the packed quantized tensor of shape ``[M, K/2]``
with dtype ``uint8`` (two E2M1 values per byte).
- ``scale_output`` holds the E4M3 block scale factors (``uint8``)
reshaped to ``[padded_rows, padded_sf_cols]``. The padding depends on
``sf_layout``: ``linear`` keeps ``M`` rows, while ``128x4`` / ``8x4``
pad rows and columns up to the layout tile.
- ``per_token_scale`` is the per-row quantization scale of shape
``[M]`` with dtype ``float32``.
"""
from ...utils import device_support_pdl

_valid_sf_layouts = (SF_LAYOUT_128x4, SF_LAYOUT_8x4, SF_LAYOUT_LINEAR)
Expand Down
Loading