Skip to content

[TRTLLM-12338][feat] Lift TOKENIZER_ALIASES to module level in llmapi.llm_args - #13568

Merged
lfr-0531 merged 1 commit into
NVIDIA:feat/deepseek_v4from
nv-yna:yna/feat-lift-tokenizer-aliases
Apr 29, 2026
Merged

[TRTLLM-12338][feat] Lift TOKENIZER_ALIASES to module level in llmapi.llm_args#13568
lfr-0531 merged 1 commit into
NVIDIA:feat/deepseek_v4from
nv-yna:yna/feat-lift-tokenizer-aliases

Conversation

@nv-yna

@nv-yna nv-yna commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

Hoist TOKENIZER_ALIASES from a method-local variable inside BaseLlmArgs.validate_and_init_tokenizer to a module-level constant in tensorrt_llm/llmapi/llm_args.py. Mirrors the equivalent change made on main in #12990 ("Support custom_tokenizer in KvCacheAwareRouter for disagg serving"); difference here is that this branch's dict also includes 'deepseek_v4'DeepseekV4Tokenizer, since DeepSeek-V4 lives on this branch and isn't on main yet.

Why

External code outside TRT-LLM legitimately needs to resolve the same short aliases TRT-LLM uses internally. Concretely, the Dynamo TRT-LLM worker (dynamo.trtllm.workers.llm_worker, added in ai-dynamo/dynamo#8079) does:

```python
from tensorrt_llm.llmapi.llm_args import TOKENIZER_ALIASES
```

so it can build the V4 tokenizer before instantiating `LLM(...)`. Dynamo needs the tokenizer object early to:

  • populate `SamplingParams` defaults from model-specific special tokens, and
  • wire up its health-check logits processor (it then passes `skip_tokenizer_init=True` to the engine).

On this branch, `TOKENIZER_ALIASES` is defined as a method-local variable, so the import fails at module load time with:

```
ImportError: cannot import name 'TOKENIZER_ALIASES' from 'tensorrt_llm.llmapi.llm_args'
```

…and the Dynamo worker crashes before any runtime work begins (CrashLoopBackOff in K8s deployments).

main already has the dict module-level (#12990, 2026-04-19), so once this branch rebases onto main, the import will work for the V32/GLM aliases. This PR adds the V4 entry now (so DeepSeek-V4 deployments via Dynamo work today on this branch) and trims one local copy of the dict — making the eventual rebase a no-op merge for this surface.

Behavior

No semantic change for existing callers. `validate_and_init_tokenizer` now references the module-level constant instead of redefining its own copy.

Test plan

  • Smoke: `python3 -c 'from tensorrt_llm.llmapi.llm_args import TOKENIZER_ALIASES; print(sorted(TOKENIZER_ALIASES))'` prints `['deepseek_v32', 'deepseek_v4', 'glm_moe_dsa']`
  • Smoke: `trtllm-serve --custom_tokenizer deepseek_v4 ...` continues to load the V4 tokenizer (validates the local function body still works)
  • Verified locally on a Dynamo+TRT-LLM K8s deployment of DeepSeek-V4-Flash on B200×4: `from ... import TOKENIZER_ALIASES` succeeds, worker boots, and `/v1/chat/completions` returns coherent answers.

@nv-yna
nv-yna requested a review from a team as a code owner April 28, 2026 17:44
@nv-yna
nv-yna requested review from zhenhuaw-me and removed request for a team April 28, 2026 17:44
@nv-yna
nv-yna requested a review from Tabrizian April 28, 2026 17:46
@Tabrizian

Copy link
Copy Markdown
Member

@lfr-0531 Just wondering would rebase take care of this issue or we need to merge this PR to feat/deepseek_v4?

@nv-yna nv-yna changed the title [None][feat] Lift TOKENIZER_ALIASES to module level in llmapi.llm_args [TRTLLM-12338][feat] Lift TOKENIZER_ALIASES to module level in llmapi.llm_args Apr 28, 2026
Mirror the change made on `main` in PR NVIDIA#12990 ("Support custom_tokenizer in
KvCacheAwareRouter for disagg serving"), which moved TOKENIZER_ALIASES from
a method-local variable inside `validate_and_init_tokenizer` to a top-level
module constant. This makes the dict importable by external code that
needs to resolve the same short aliases — for example, the Dynamo TRT-LLM
worker (`dynamo.trtllm.workers.llm_worker`, github.com/ai-dynamo/dynamo
PR NVIDIA#8079) does:

    from tensorrt_llm.llmapi.llm_args import TOKENIZER_ALIASES

so it can construct the V4 tokenizer ahead of LLM() init (Dynamo needs the
tokenizer object early to populate SamplingParams defaults and build its
logits processor). Without the lift, that import fails at module load time
with `ImportError: cannot import name 'TOKENIZER_ALIASES'` and the worker
crash-loops.

Difference vs PR NVIDIA#12990 on main: the dict here also includes
'deepseek_v4' → DeepseekV4Tokenizer, since DeepSeek-V4 lives on this
branch and isn't on main yet.

The function body stays behavior-equivalent — `validate_and_init_tokenizer`
now references the module-level constant instead of redefining its own
copy. No semantic change for existing callers.

Signed-off-by: Yuewei Na <nv-yna@users.noreply.github.com>
@nv-yna
nv-yna force-pushed the yna/feat-lift-tokenizer-aliases branch from bbcc8d9 to bf89349 Compare April 28, 2026 19:09
@nv-yna

nv-yna commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-commit Check is failing on a pre-existing branch issue, not on this PR's diff.

The 5 errors are Bandit B105 ("possible hardcoded password") false positives flagging tokenizer special tokens in tensorrt_llm/tokenizer/deepseek_v4/tokenizer.py:23-27:

BOS_TOKEN = "<|begin▁of▁sentence|>"
EOS_TOKEN = "<|end▁of▁sentence|>"
USER_TOKEN = "<|User|>"
ASSISTANT_TOKEN = "<|Assistant|>"
THINKING_END_TOKEN = "</think>"

These lines are already on feat/deepseek_v4 HEAD; this PR doesn't touch that file (git diff is single-file, only tensorrt_llm/llmapi/llm_args.py). Other PRs on this branch are hitting the same wall — e.g. #13563 ("[None][feat] Required changes for DeepSeek‑V4 Disaggregated") also has Pre-commit Check = FAILURE.

Suggested branch fix (separate PR, out of scope here): add # nosec B105 to each of those five lines, or add B105 to the bandit allowlist for that file. Happy to file that as a follow-up if it would help unblock the branch.

cc @lfr-0531 @Tabrizian

@Tabrizian

Copy link
Copy Markdown
Member

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #45979 [ run ] triggered by Bot. Commit: bf89349 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #45979 [ run ] completed with state FAILURE. Commit: bf89349
/LLM/main/L0_MergeRequest_PR pipeline #36131 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

@lfr-0531
lfr-0531 merged commit bef1b8d into NVIDIA:feat/deepseek_v4 Apr 29, 2026
5 of 7 checks passed
lfr-0531 pushed a commit that referenced this pull request May 7, 2026
….llm_args (#13568)

Signed-off-by: Yuewei Na <nv-yna@users.noreply.github.com>
Co-authored-by: Yuewei Na <nv-yna@users.noreply.github.com>
lfr-0531 pushed a commit that referenced this pull request May 14, 2026
….llm_args (#13568)

Signed-off-by: Yuewei Na <nv-yna@users.noreply.github.com>
Co-authored-by: Yuewei Na <nv-yna@users.noreply.github.com>
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request May 29, 2026
….llm_args (NVIDIA#13568)

Signed-off-by: Yuewei Na <nv-yna@users.noreply.github.com>
Co-authored-by: Yuewei Na <nv-yna@users.noreply.github.com>
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
(cherry picked from commit 085e2e1)
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 1, 2026
….llm_args (NVIDIA#13568)

Signed-off-by: Yuewei Na <nv-yna@users.noreply.github.com>
Co-authored-by: Yuewei Na <nv-yna@users.noreply.github.com>
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
(cherry picked from commit 085e2e1)
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 3, 2026
….llm_args (NVIDIA#13568)

Signed-off-by: Yuewei Na <nv-yna@users.noreply.github.com>
Co-authored-by: Yuewei Na <nv-yna@users.noreply.github.com>
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
(cherry picked from commit 085e2e1)
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 7, 2026
….llm_args (NVIDIA#13568)

Signed-off-by: Yuewei Na <nv-yna@users.noreply.github.com>
Co-authored-by: Yuewei Na <nv-yna@users.noreply.github.com>
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
(cherry picked from commit 085e2e1)
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 10, 2026
….llm_args (NVIDIA#13568)

Signed-off-by: Yuewei Na <nv-yna@users.noreply.github.com>
Co-authored-by: Yuewei Na <nv-yna@users.noreply.github.com>
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 11, 2026
….llm_args (NVIDIA#13568)

Signed-off-by: Yuewei Na <nv-yna@users.noreply.github.com>
Co-authored-by: Yuewei Na <nv-yna@users.noreply.github.com>
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 12, 2026
….llm_args (NVIDIA#13568)

Signed-off-by: Yuewei Na <nv-yna@users.noreply.github.com>
Co-authored-by: Yuewei Na <nv-yna@users.noreply.github.com>
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 12, 2026
….llm_args (NVIDIA#13568)

Signed-off-by: Yuewei Na <nv-yna@users.noreply.github.com>
Co-authored-by: Yuewei Na <nv-yna@users.noreply.github.com>
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
(cherry picked from commit 085e2e1)
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 13, 2026
….llm_args (NVIDIA#13568)

Signed-off-by: Yuewei Na <nv-yna@users.noreply.github.com>
Co-authored-by: Yuewei Na <nv-yna@users.noreply.github.com>
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
(cherry picked from commit 085e2e1)
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 16, 2026
….llm_args (NVIDIA#13568)

Signed-off-by: Yuewei Na <nv-yna@users.noreply.github.com>
Co-authored-by: Yuewei Na <nv-yna@users.noreply.github.com>
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
(cherry picked from commit 085e2e1)
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 17, 2026
….llm_args (NVIDIA#13568)

Signed-off-by: Yuewei Na <nv-yna@users.noreply.github.com>
Co-authored-by: Yuewei Na <nv-yna@users.noreply.github.com>
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
(cherry picked from commit 085e2e1)
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants