[TRTLLM-12338][feat] Lift TOKENIZER_ALIASES to module level in llmapi.llm_args - #13568
Conversation
|
@lfr-0531 Just wondering would rebase take care of this issue or we need to merge this PR to feat/deepseek_v4? |
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>
bbcc8d9 to
bf89349
Compare
|
Pre-commit Check is failing on a pre-existing branch issue, not on this PR's diff. The 5 errors are Bandit 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 Suggested branch fix (separate PR, out of scope here): add |
|
/bot run --disable-fail-fast |
|
PR_Github #45979 [ run ] triggered by Bot. Commit: |
|
PR_Github #45979 [ run ] completed with state
|
….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>
….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>
….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>
….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>
….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>
….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>
….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>
….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>
….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>
….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>
….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>
….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>
….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>
Summary
Hoist
TOKENIZER_ALIASESfrom a method-local variable insideBaseLlmArgs.validate_and_init_tokenizerto a module-level constant intensorrt_llm/llmapi/llm_args.py. Mirrors the equivalent change made onmainin #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 onmainyet.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:
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).
mainalready has the dict module-level (#12990, 2026-04-19), so once this branch rebases ontomain, 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