[https://nvbugs/6163690][fix] Use PreTrainedTokenizerFast in trtllm-bench prepare_dataset to avoid NemotronH config parsing error#16820
Conversation
Signed-off-by: Pamela <179191831+pamelap-nvidia@users.noreply.github.com>
📝 WalkthroughWalkthroughChangesTokenizer loading
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tensorrt_llm/bench/dataset/prepare_dataset.py`:
- Around line 42-49: Narrow the exception handler around
PreTrainedTokenizerFast.from_pretrained in the tokenizer-loading flow to catch
only OSError and ValueError, allowing unrelated loader errors to propagate while
preserving the AutoTokenizer fallback for intended fast-tokenizer load failures.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 0c84cc16-35ca-4270-b613-43b16afd8685
📒 Files selected for processing (1)
tensorrt_llm/bench/dataset/prepare_dataset.py
Signed-off-by: Pamela <179191831+pamelap-nvidia@users.noreply.github.com>
|
/bot run |
|
PR_Github #61461 [ run ] triggered by Bot. Commit: |
|
PR_Github #61461 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #61480 [ run ] triggered by Bot. Commit: |
|
PR_Github #61480 [ run ] completed with state
|
|
/bot run |
|
PR_Github #61584 [ run ] triggered by Bot. Commit: |
|
PR_Github #61584 [ run ] completed with state
|
@coderabbitai summary
Description
Problem
trtllm-bench prepare-dataset (and the legacy
benchmarks/cpp/prepare_dataset.py) fails with KeyError: '-' when the model is NVIDIA-Nemotron-Nano-9B-v2-NVFP4:Root cause
AutoTokenizer.from_pretrainedcallsAutoConfig.from_pretrainedinternally to resolve the tokenizer class. This instantiates the built-inNemotronHConfig(added in transformers 5.5.3), whose_pattern_to_listmaps M→mamba, E→moe, *→attention but is missing '-': 'mlp'. The NVFP4 model'sconfig.jsonhashybrid_override_pattern: M-M-M-MM-M-M-M*-...where - encodes MLP layers, causing the KeyError.This was not hit before because:
nemotron_hwas not yet a built-in typeThe upstream fix is in huggingface/transformers PR #44763 (merged 2026-04-22, first in transformers v5.10.1). TRTLLM currently ships transformers 5.5.4 and cannot upgrade to 5.10.1 without accuracy regressions in GPT-OSS tests (chat template changes,
torch_dtypedeprecation).Fix
prepare_dataset.pyonly uses the tokenizer to encode text for synthetic dataset generation — it never needs model config.PreTrainedTokenizerFast.from_pretrainedloads directly from tokenizer.json without invoking AutoConfig, bypassing the broken config parsing entirely.The NVFP4 model ships a complete
tokenizer.json, so the fast tokenizer loads correctly (131072-vocab, verified on rc19). An AutoTokenizer fallback is kept for models that do not provide a fast tokenizer.Testing
PreTrainedTokenizerFast.from_pretrainedsucceeds on rc19 with NVIDIA-Nemotron-Nano-9B-v2-NVFP4 (131072-vocab, tokenizes correctly)AutoTokenizerfallback path is exercised by any model without tokenizer.jsonPR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.