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
1 change: 1 addition & 0 deletions docs/source/models/supported-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The following is a table of supported models for the PyTorch backend:
| `HunYuanMoEForCausalLM` [^5] | Hunyuan MoE | `tencent/Hunyuan-A13B-Instruct` |
| `InternLM3ForCausalLM` [^5] | InternLM3 | `internlm/internlm3-8b-instruct` |
| `KimiK25ForConditionalGeneration` | Kimi-K2.5 | `moonshotai/Kimi-K2.5` |
| `LagunaForCausalLM` | Laguna-XS | `poolside/laguna-XS.2` |
| `LlamaForCausalLM` | Llama 3.1, Llama 3, Llama 2, LLaMA | `meta-llama/Meta-Llama-3.1-70B` |
| `Llama4ForConditionalGeneration` | Llama 4 | `meta-llama/Llama-4-Scout-17B-16E-Instruct` |
| `MiniMaxM2ForCausalLM` [^5] | MiniMax M2/M2.1/M2.7 | `MiniMaxAI/MiniMax-M2.7` |
Expand Down
20 changes: 13 additions & 7 deletions tensorrt_llm/_torch/configs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
from tensorrt_llm._torch.configs.deepseek_v3 import DeepseekV3Config
from tensorrt_llm._torch.configs.laguna import LagunaConfig


def _register_custom_configs_with_transformers() -> None:
# Make AutoConfig.from_pretrained / AutoTokenizer.from_pretrained accept
# model_types that TRT-LLM understands but upstream transformers does not
# (DeepSeek-V3.2 and Kimi K2 both ship config.json with these model_types
# and rely on TRT-LLM's local DeepseekV3Config workaround).
# (DeepSeek-V3.2, Kimi K2, and Laguna ship config.json with these
# model_types and rely on TRT-LLM's local config workarounds).
#
# Without this, transformers 5.5.x falls back to a bare PreTrainedConfig
# that lacks attributes like `max_position_embeddings`, and
# AutoTokenizer.from_pretrained then raises AttributeError before any
# tokenizer can be constructed. Bypass AutoConfig.register's model_type
# consistency check (DeepseekV3Config.model_type is "deepseek_v3") by
# writing into the underlying mapping directly.
# consistency check for aliases (for example, DeepseekV3Config.model_type
# is "deepseek_v3") by writing into the underlying mapping directly.
from transformers.models.auto.configuration_auto import CONFIG_MAPPING

for model_type in ("deepseek_v32", "kimi_k2"):
custom_configs = {
"deepseek_v32": DeepseekV3Config,
"kimi_k2": DeepseekV3Config,
"laguna": LagunaConfig,
}
for model_type, config_class in custom_configs.items():
if model_type in CONFIG_MAPPING:
continue
CONFIG_MAPPING.register(model_type, DeepseekV3Config, exist_ok=True)
CONFIG_MAPPING.register(model_type, config_class, exist_ok=True)


_register_custom_configs_with_transformers()
del _register_custom_configs_with_transformers

__all__ = ["DeepseekV3Config"]
__all__ = ["DeepseekV3Config", "LagunaConfig"]
23 changes: 23 additions & 0 deletions tensorrt_llm/_torch/configs/laguna.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from transformers.configuration_utils import PretrainedConfig


# This is a workaround until we use a version of transformers that supports
# Laguna. Namely: v5.7.0 or higher.
class LagunaConfig(PretrainedConfig):
Comment thread
DomBrown marked this conversation as resolved.
Resolved
model_type = "laguna"
keys_to_ignore_at_inference = ["past_key_values"]
37 changes: 34 additions & 3 deletions tensorrt_llm/_torch/model_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,12 +513,42 @@ def load_hf_quant_config(hf_quant_config, moe_backend, checkpoint_dir=None):
raise ValueError(
f"Unsupported weights_quant_strategy: {weights_quant_strategy}. "
"Supported strategies: 'channel', 'block'.")
elif (weights_quant_config["num_bits"] == 4
and weights_quant_config.get("type") == "float"
and weights_quant_strategy == "tensor_group"):
# llm-compressor NVFP4: weights FP4 with FP8 per-group scales
# (group_size=16), scaled by an FP32 global scale.
if inputs_quant_strategy != "tensor_group":
raise ValueError(
f"Unsupported inputs_quant_strategy for NVFP4: {inputs_quant_strategy}."
)
group_size = weights_quant_config["group_size"]
if group_size != 16:
raise ValueError(
f"Unsupported group_size: {group_size}. Supported: 16 for NVFP4."
)
quant_config.quant_algo = QuantAlgo.NVFP4
quant_config.group_size = group_size
else:
raise ValueError(
f"Unsupported quant_bits: {weights_quant_config['num_bits']}. "
"Supported: 8.")
"Supported: 8 (FP8) or 4 (NVFP4).")

# kv_cache_scheme (llm-compressor): FP8 per-tensor KV cache.
kv_cache_scheme = hf_quant_config.get("kv_cache_scheme")
if kv_cache_scheme is not None:
if (kv_cache_scheme.get("num_bits") == 8
and kv_cache_scheme.get("type") == "float"):
quant_config.kv_cache_quant_algo = QuantAlgo.FP8
else:
raise ValueError(
f"Unsupported kv_cache_scheme: {kv_cache_scheme}.")

quant_config.exclude_modules = hf_quant_config.get("ignore", [])
if hf_exclude_modules is not None:
quant_config.exclude_modules = list(
set(hf_exclude_modules + hf_quant_config.get("ignore", [])))
else:
quant_config.exclude_modules = hf_quant_config.get("ignore", [])
elif hf_quant_config.get("quant_method") == "nvfp4":
quant_config.quant_algo = QuantAlgo.NVFP4
group_size = hf_quant_config.get("group_size", 16)
Expand Down Expand Up @@ -740,7 +770,8 @@ def _recursive_update_config(config: transformers.PretrainedConfig,
quant_config, layer_quant_config = cls._build_modelopt_quant_config(
normalized, checkpoint_dir, moe_backend_hint)
# quantized ckpt in other formats
elif hasattr(pretrained_config, "quantization_config"):
elif getattr(pretrained_config, "quantization_config",
None) is not None:
hf_quant_config = pretrained_config.quantization_config
quant_config, layer_quant_config = cls.load_hf_quant_config(
hf_quant_config,
Expand Down
2 changes: 2 additions & 0 deletions tensorrt_llm/_torch/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .modeling_hunyuan_moe import HunYuanMoEV1ForCausalLM
from .modeling_hyperclovax import HCXVisionForCausalLM
from .modeling_kimi_k25 import KimiK25ForConditionalGeneration
from .modeling_laguna import LagunaForCausalLM
from .modeling_llama import LlamaForCausalLM
from .modeling_llava_next import LlavaNextModel
from .modeling_minimaxm2 import MiniMaxM2ForCausalLM
Expand Down Expand Up @@ -58,6 +59,7 @@
"Gemma3ForCausalLM",
"Gemma3VLM",
"HCXVisionForCausalLM",
"LagunaForCausalLM",
"HunYuanDenseV1ForCausalLM",
"HunYuanMoEV1ForCausalLM",
"KimiK25ForConditionalGeneration",
Expand Down
Loading
Loading