-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[https://nvbugs/6185234][fix] register deepseek_v32 / kimi_k2 with transformers AutoConfig #14293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
longlee0622
merged 1 commit into
NVIDIA:main
from
longlee0622:fix/transformers-5.5.3-deepseek-v32-autotokenizer
May 19, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,27 @@ | ||
| from tensorrt_llm._torch.configs.deepseek_v3 import DeepseekV3Config | ||
|
|
||
|
|
||
| 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). | ||
| # | ||
| # 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. | ||
| from transformers.models.auto.configuration_auto import CONFIG_MAPPING | ||
|
|
||
| for model_type in ("deepseek_v32", "kimi_k2"): | ||
| if model_type in CONFIG_MAPPING: | ||
| continue | ||
| CONFIG_MAPPING.register(model_type, DeepseekV3Config, exist_ok=True) | ||
|
|
||
|
|
||
| _register_custom_configs_with_transformers() | ||
| del _register_custom_configs_with_transformers | ||
|
|
||
| __all__ = ["DeepseekV3Config"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| """Regression tests for the transformers AutoConfig / AutoTokenizer dispatch | ||
| for TRT-LLM-only model_types (deepseek_v32, kimi_k2). | ||
|
|
||
| Before this registration, transformers >= 5.5 falls back to a bare | ||
| PreTrainedConfig that lacks `max_position_embeddings`, and | ||
| AutoTokenizer.from_pretrained then raises AttributeError on it. The | ||
| broken test that motivated this — perf/test_perf_sanity.py disagg gen_only | ||
| on GB200 — only runs in L0_PostMerge because it needs 12 GB200 GPUs across | ||
| 3 nodes, so a cheap pre-merge unit test is the right place to catch | ||
| regressions. | ||
| """ | ||
|
|
||
| import json | ||
|
|
||
| import pytest | ||
|
|
||
| import tensorrt_llm # noqa: F401 triggers AutoConfig registration | ||
| from tensorrt_llm._torch.configs import DeepseekV3Config | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("model_type", ["deepseek_v32", "kimi_k2"]) | ||
| def test_custom_model_type_registered_with_autoconfig(model_type): | ||
| from transformers.models.auto.configuration_auto import CONFIG_MAPPING | ||
|
|
||
| assert model_type in CONFIG_MAPPING | ||
| assert CONFIG_MAPPING[model_type] is DeepseekV3Config | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("model_type", ["deepseek_v32", "kimi_k2"]) | ||
| def test_autoconfig_from_pretrained_resolves_to_local_config(tmp_path, model_type): | ||
| # Mirrors what the benchmark_serving subprocess does under the hood: | ||
| # AutoTokenizer.from_pretrained -> AutoConfig.from_pretrained. Without | ||
| # the registration this fails through to a bare PreTrainedConfig that | ||
| # lacks `max_position_embeddings`. | ||
| from transformers import AutoConfig | ||
|
|
||
| model_dir = tmp_path / model_type | ||
| model_dir.mkdir() | ||
| (model_dir / "config.json").write_text( | ||
| json.dumps( | ||
| { | ||
| "model_type": model_type, | ||
| "max_position_embeddings": 16384, | ||
| } | ||
| ) | ||
| ) | ||
|
|
||
| cfg = AutoConfig.from_pretrained(str(model_dir)) | ||
| assert isinstance(cfg, DeepseekV3Config) | ||
| assert cfg.max_position_embeddings == 16384 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.