[Bug]: TransformersTokenizer vocabulary queries raise NotImplementedError

Open
#23,252 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@JunkaiWang-TheoPhy is already working on this.

Since Dec 2, 2026.

  • #23254 by @JunkaiWang-TheoPhy — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
backend

Research direction

Find the TransformersTokenizer implementation and its tests in the TensorRT-LLM repository; the issue does not name their paths. Read how the wrapper delegates encoding and get_added_vocab(), then compare its vocabulary methods with the underlying Transformers tokenizer. Done when the three reproduction assertions pass; linked pull request #23254 is already open.

Written by the indexing model from the issue text.

Description

Frontend
System Info

TensorRT-LLM main ef375f87565b89a5818e705c735ec59a182efb86. Reproduced on Python 3.12/macOS ARM64 with Hugging Face Transformers and an in-memory Rust-backed WordLevel tokenizer. No GPU, model weights, or network is needed for the example. Native TensorRT startup was bypassed in the local CPU harness.

Reproduction
from tokenizers import Tokenizer
from tokenizers.models import WordLevel
from transformers import PreTrainedTokenizerFast

from tensorrt_llm.tokenizer import TransformersTokenizer

raw = PreTrainedTokenizerFast(
    tokenizer_object=Tokenizer(WordLevel({"<unk>": 0, "fox": 1}, unk_token="<unk>")),
    unk_token="<unk>",
)
raw.add_tokens(["whale"])
wrapped = TransformersTokenizer(raw)

assert wrapped.get_vocab() == raw.get_vocab()
assert len(wrapped) == len(raw) == 3
assert wrapped.vocab_size == raw.vocab_size == 2
Expected behavior

The wrapper should expose the underlying tokenizer's vocabulary map and distinguish the full length including added tokens from its base vocabulary size.

Actual behavior

All three wrapper operations raise NotImplementedError from PreTrainedTokenizerBase. The underlying tokenizer supports all three operations.

Additional notes

The wrapper already delegates encoding, decoding, token conversion, and get_added_vocab(); vocabulary introspection uses inherited base stubs instead. See the Transformers tokenizer interface. Searches for TransformersTokenizer get_vocab, TokenizerBase get_vocab, and vocabulary-related NotImplementedError did not identify an equivalent fix.

OpenAI Codex assisted with the reproduction.

Dominant language
Python
Stars
15.2k
Forks
3k
Avg merge
2d 21h
Merged PRs (30d)
477

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NVIDIA/TensorRT-LLM

All issues in NVIDIA/TensorRT-LLM

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.