[https://nvbugs/6209806][fix] Add an idempotent _relax_llama_validate_architecture() helper that installs a pe - #14707
Conversation
📝 WalkthroughWalkthroughThis PR adds a compatibility patch for HuggingFace Transformers 5.x LlamaConfig validation that allows models with explicit ChangesLlama Architecture Validation Bypass
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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/tokenizer/tokenizer.py`:
- Around line 633-639: The compatibility patch calls
(_ensure_gpt2_bytes_to_unicode_compat and _relax_llama_validate_architecture)
are placed outside the try block in load_hf_tokenizer so import/patch failures
escape instead of being caught; move the two calls (and their import of
_relax_llama_validate_architecture from
tensorrt_llm._torch.pyexecutor.config_utils) inside the existing try: block in
load_hf_tokenizer so any ImportError or runtime error is logged and the function
returns None as intended.
🪄 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: 207680b0-a4cc-4c57-9764-b4cdb1c74c10
📒 Files selected for processing (3)
tensorrt_llm/_torch/pyexecutor/config_utils.pytensorrt_llm/tokenizer/tokenizer.pytests/integration/test_lists/waives.txt
💤 Files with no reviewable changes (1)
- tests/integration/test_lists/waives.txt
| _ensure_gpt2_bytes_to_unicode_compat() | ||
| # AutoTokenizer.from_pretrained internally calls AutoConfig.from_pretrained, | ||
| # which triggers transformers 5.x LlamaConfig.validate_architecture. | ||
| # Relax it so models with explicit `head_dim` (e.g. kanana-1.5-2.1b) load. | ||
| from tensorrt_llm._torch.pyexecutor.config_utils import \ | ||
| _relax_llama_validate_architecture | ||
| _relax_llama_validate_architecture() |
There was a problem hiding this comment.
Move the compatibility patch inside the existing try block.
These new lines run before the try: at Line 641, so any import or patching failure now escapes instead of following load_hf_tokenizer()'s current "log and return None" behavior.
💡 Proposed fix
- _ensure_gpt2_bytes_to_unicode_compat()
- # AutoTokenizer.from_pretrained internally calls AutoConfig.from_pretrained,
- # which triggers transformers 5.x LlamaConfig.validate_architecture.
- # Relax it so models with explicit `head_dim` (e.g. kanana-1.5-2.1b) load.
- from tensorrt_llm._torch.pyexecutor.config_utils import \
- _relax_llama_validate_architecture
- _relax_llama_validate_architecture()
-
try:
+ _ensure_gpt2_bytes_to_unicode_compat()
+ # AutoTokenizer.from_pretrained internally calls AutoConfig.from_pretrained,
+ # which triggers transformers 5.x LlamaConfig.validate_architecture.
+ # Relax it so models with explicit `head_dim` (e.g. kanana-1.5-2.1b) load.
+ from tensorrt_llm._torch.pyexecutor.config_utils import \
+ _relax_llama_validate_architecture
+ _relax_llama_validate_architecture()
tokenizer = TransformersTokenizer.from_pretrained(
model_dir,
legacy=False,🤖 Prompt for 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.
In `@tensorrt_llm/tokenizer/tokenizer.py` around lines 633 - 639, The
compatibility patch calls (_ensure_gpt2_bytes_to_unicode_compat and
_relax_llama_validate_architecture) are placed outside the try block in
load_hf_tokenizer so import/patch failures escape instead of being caught; move
the two calls (and their import of _relax_llama_validate_architecture from
tensorrt_llm._torch.pyexecutor.config_utils) inside the existing try: block in
load_hf_tokenizer so any ImportError or runtime error is logged and the function
returns None as intended.
0d285b8 to
a5a48f3
Compare
| head_dim = getattr(self, "head_dim", None) | ||
| if isinstance(head_dim, int) and head_dim > 0: | ||
| return |
There was a problem hiding this comment.
It seems that LlamaConfig will set head_dim if it is None here. So it might always be int and very likely larger than 0. And this seems might disable the self.hidden_size % self.num_attention_heads != 0 check for all cases.
5320bf6 to
e5cc5e4
Compare
6f26e1c to
2460154
Compare
transformers 5.5.x LlamaConfig.validate_architecture rejects configs where hidden_size % num_attention_heads != 0, ignoring an explicit head_dim that decouples q/k/v projection size from hidden_size (e.g. kanana-1.5-2.1b: hidden_size=1792, num_attention_heads=24, head_dim=128). Replace the validator (and its captured entry in __class_validators__) with a permissive version that allows positive explicit head_dim. Apply the patch at the two TRT-LLM entry points that load HF configs and tokenizers, and remove the now-stale test waiver. Signed-off-by: tensorrt-cicd <90828364+tensorrt-cicd@users.noreply.github.com>
2460154 to
219063f
Compare
Summary
Test plan
Links
Summary by CodeRabbit
Release Notes
head_dimconfiguration settings that previously failed validation checks.