Skip to content

[https://nvbugs/6209806][fix] Add an idempotent _relax_llama_validate_architecture() helper that installs a pe - #14707

Closed
tensorrt-cicd wants to merge 1 commit into
NVIDIA:mainfrom
tensorrt-cicd:repair-bot-bug6209806
Closed

tensorrt-cicd wants to merge 1 commit into
NVIDIA:mainfrom
tensorrt-cicd:repair-bot-bug6209806

Conversation

@tensorrt-cicd

@tensorrt-cicd tensorrt-cicd commented May 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Root cause: transformers 5.5.x LlamaConfig.validate_architecture rejects configs where hidden_size % num_attention_heads != 0 even when head_dim is explicitly set, breaking valid models like kanana-1.5-2.1b (hidden_size=1792, num_attention_heads=24, head_dim=128).
  • Fix: Add an idempotent _relax_llama_validate_architecture() helper that installs a permissive validator (passes when head_dim is a positive int) and substitutes it in class_validators; call it at the start of load_pretrained_config and load_hf_tokenizer; remove the stale waives.txt entry.
  • Automated fix generated by repair-bot

Test plan

  • Verify fix on the same GPU type as the original failure
  • Check for regressions in related tests

Links

Dev Engineer Review

  • _relax_llama_validate_architecture() adds an idempotent compatibility patch for Transformers 5.5.x.
  • The patch allows positive integer head_dim values when hidden_size is not divisible by num_attention_heads.
  • load_pretrained_config() and load_hf_tokenizer() apply the patch before Transformers loads Llama configuration data.
  • The change targets valid configurations such as kanana-1.5-2.1b.
  • No public entity declarations changed.
  • No test files were touched.
  • Review should confirm that the validator patch remains compatible with supported Transformers versions and does not weaken validation beyond positive integer head_dim.

QA Engineer Review

No test changes.

@coderabbitai

coderabbitai Bot commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 56435d64-17f1-46bb-a7a8-14feb79e7992

📥 Commits

Reviewing files that changed from the base of the PR and between 3d3d7c9 and 1f543b8.

📒 Files selected for processing (2)
  • tensorrt_llm/_torch/pyexecutor/config_utils.py
  • tensorrt_llm/tokenizer/tokenizer.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • tensorrt_llm/tokenizer/tokenizer.py
  • tensorrt_llm/_torch/pyexecutor/config_utils.py

Walkthrough

The change adds an idempotent Llama architecture validation patch and invokes it before pretrained configuration and Hugging Face tokenizer loading.

Changes

Llama architecture validation

Layer / File(s) Summary
LlamaConfig validation patch and configuration loading
tensorrt_llm/_torch/pyexecutor/config_utils.py
_relax_llama_validate_architecture() allows positive integer head_dim values, preserves the divisibility error for other values, updates captured validators, and runs before configuration retrieval.
Tokenizer loading integration
tensorrt_llm/tokenizer/tokenizer.py
load_hf_tokenizer applies the validation patch before TransformersTokenizer.from_pretrained.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: crazydemo

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the bug fix and the _relax_llama_validate_architecture() helper, but it ends with truncated text.
Description check ✅ Passed The description explains the root cause, fix, test plan, and bug link, but it omits the template's PR Checklist section.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between f6ba936 and f3d2b34.

📒 Files selected for processing (3)
  • tensorrt_llm/_torch/pyexecutor/config_utils.py
  • tensorrt_llm/tokenizer/tokenizer.py
  • tests/integration/test_lists/waives.txt
💤 Files with no reviewable changes (1)
  • tests/integration/test_lists/waives.txt

Comment on lines 633 to +639
_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()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

@tensorrt-cicd
tensorrt-cicd force-pushed the repair-bot-bug6209806 branch 3 times, most recently from 0d285b8 to a5a48f3 Compare June 2, 2026 23:23
Comment on lines +458 to +460
head_dim = getattr(self, "head_dim", None)
if isinstance(head_dim, int) and head_dim > 0:
return

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@tensorrt-cicd
tensorrt-cicd force-pushed the repair-bot-bug6209806 branch 2 times, most recently from 5320bf6 to e5cc5e4 Compare June 8, 2026 11:12
@tensorrt-cicd
tensorrt-cicd force-pushed the repair-bot-bug6209806 branch 2 times, most recently from 6f26e1c to 2460154 Compare June 27, 2026 04:00
@trtllm-agent
trtllm-agent force-pushed the repair-bot-bug6209806 branch from 2460154 to 219063f Compare July 7, 2026 00:50
@trtllm-agent
trtllm-agent force-pushed the repair-bot-bug6209806 branch from 219063f to 78110cc Compare July 29, 2026 07:37
@trtllm-agent
trtllm-agent requested review from a team as code owners July 29, 2026 07:37
@crazydemo

Copy link
Copy Markdown
Collaborator

/bot run --only-qa-verify test accuracy/test_llm_api_pytorch.py::TestKanana_Instruct::test_auto_dtype

Comment thread tests/integration/test_lists/waives.txt Outdated
accuracy/test_llm_api_pytorch.py::TestGPTOSS::test_w4_4gpus[v2_kv_cache-ep4-cutlass-auto] SKIP (https://nvbugs/5596343)
accuracy/test_llm_api_pytorch.py::TestGPTOSS::test_w4_4gpus[v2_kv_cache-tp4-cutlass-auto] SKIP (https://nvbugs/5596343)
accuracy/test_llm_api_pytorch.py::TestGPTOSS::test_w4_chunked_prefill[cutlass-auto] SKIP (https://nvbugs/5596343)
accuracy/test_llm_api_pytorch.py::TestKanana_Instruct::test_auto_dtype SKIP (https://nvbugs/6209806)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@trtllm-agent
trtllm-agent force-pushed the repair-bot-bug6209806 branch from 7f21079 to 1f543b8 Compare August 12, 2026 18:55
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@pranav-nvidia

Copy link
Copy Markdown
Contributor

Closing this PR since model has now been retired.

@trtllm-agent
trtllm-agent deleted the repair-bot-bug6209806 branch October 23, 2026 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants