Skip to content
40 changes: 38 additions & 2 deletions tensorrt_llm/_torch/_experimental/modeling_v2/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# ModelingV2

One self-contained modeling codebase per deployment target, beside the
built-in model zoo rather than inside it.
Explicit deployment targets beside the built-in model zoo.

Where `_torch/models/modeling_deepseekv3.py` is one class serving V3, V3-Lite,
R1 and V3.2 across every GPU generation and parallel topology,
Expand All @@ -11,6 +10,43 @@ entries, sharing nothing with its siblings, and trusted through accuracy gates
instead of shared abstractions. The one-to-one correspondence between
`models/<x>/` here and `modeling_<x>.py` there is the point of the exercise.

Kimi K3 keeps its original MXFP4/SM100 deployments independent. The NVFP4
implementation is a separate copy under `models/kimi_k3_vl/kimi_k3_nvfp4/`,
shared by thin SM103 and SM107 target classes. NVFP4 retains checkpoint FP8
projection weights and activations: decode fuses KDA's gate, convolution,
recurrence and output normalization, and MLA's query/absorption/cache writes
and attention/V-B/output gate. The ordinary FP8 GEMMs remain responsible for
input and output projections. MLA's fused decode uses a BF16 KV cache with
64-token pages, or composes the fused FP8 projections with the native FP8
and NVFP4 cache/attention kernels. NVFP4 KV requires 128-token pages and the
V2 cache manager; its high-precision tail and packed scales retain the native
layout. The KDA fused decode and verify accept FP32 or BF16 recurrent-state
storage, with FP32 recurrence arithmetic and FP32 per-token draft records.
These KV and SSM storage choices are independent of the NVFP4 expert weights.
The fused Q-B projection follows the selected GEMM backend's FP8 recipe,
including weight resmoothing and UE8M0 activation scales where required.

| MLA KV storage | KDA SSM storage | KDA recurrence / draft records |
|---|---|---|
| BF16 | FP32 or BF16 | FP32 |
| FP8 E4M3 | FP32 or BF16 | FP32 |
| NVFP4 | FP32 or BF16 | FP32 |

For NVFP4 KV and BF16 recurrent-state storage:

```yaml
modeling_v2: require
enable_chunked_prefill: false
kv_cache_config:
dtype: nvfp4
tokens_per_block: 128
mamba_ssm_cache_dtype: bfloat16
use_kv_cache_manager_v2: true
```

The NVFP4 expert kernels remain separate from the MXFP4/MXFP8 kernels.
Every hardware and quantization target requires its own accuracy gates.

## Using it

```python
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""Kimi K3 MXFP4 / sm_103 / tp16_moetp16ep1."""
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""Kimi K3 MXFP4, SM103, attention TP16 and MoE TP16 x EP1."""

from tensorrt_llm._torch.model_config import ModelConfig
from tensorrt_llm.quantization.mode import QuantAlgo

from ..modeling import K3TargetSpec, ModelingV2KimiK3
from ..modeling import _check_construction as _check_target_construction

_TARGET = K3TargetSpec(sm=(10, 3), quant_algo=QuantAlgo.W4A8_MXFP4_MXFP8, moe_tp=16, moe_ep=1)


def _check_construction(model_config: ModelConfig) -> None:
_check_target_construction(model_config, _TARGET)


class ModelingV2KimiK3Mxfp4Sm103Tp16Moetp16ep1(ModelingV2KimiK3):
"""Concrete deployment of the shared Kimi K3 text model."""

target_spec = _TARGET
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""The shared Kimi K3 text checkpoint loader."""

from ..weights import PREDICTED_NON_LOAD as PREDICTED_NON_LOAD
from ..weights import load as load
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""Kimi K3 MXFP4 / sm_103 / tp16_moetp4ep4."""
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""Kimi K3 MXFP4, SM103, attention TP16 and MoE TP4 x EP4."""

from tensorrt_llm._torch.model_config import ModelConfig
from tensorrt_llm.quantization.mode import QuantAlgo

from ..modeling import K3TargetSpec, ModelingV2KimiK3
from ..modeling import _check_construction as _check_target_construction

_TARGET = K3TargetSpec(sm=(10, 3), quant_algo=QuantAlgo.W4A8_MXFP4_MXFP8, moe_tp=4, moe_ep=4)


def _check_construction(model_config: ModelConfig) -> None:
_check_target_construction(model_config, _TARGET)


class ModelingV2KimiK3Mxfp4Sm103Tp16Moetp4ep4(ModelingV2KimiK3):
"""Concrete deployment of the shared Kimi K3 text model."""

target_spec = _TARGET
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""The shared Kimi K3 text checkpoint loader."""

from ..weights import PREDICTED_NON_LOAD as PREDICTED_NON_LOAD
from ..weights import load as load
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""NVFP4 Kimi K3 targets with FP8 fused attention on SM103 and SM107."""
Loading