Skip to content

[https://nvbugs/6624972][fix] Preserve Nemotron-H hybrid_override_pattern with MLP layers - #18042

Merged
pranav-nvidia merged 1 commit into
NVIDIA:release/1.3from
BowenFu:fix/nvbug-6624972-nemotron-h-mlp-pattern
Oct 5, 2026
Merged

pranav-nvidia merged 1 commit into
NVIDIA:release/1.3from
BowenFu:fix/nvbug-6624972-nemotron-h-mlp-pattern

Conversation

@BowenFu

@BowenFu BowenFu commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Dev Engineer Review

  • NemotronHConfig preserves Nemotron-H layer patterns containing -, and delegates patterns supported by Transformers to its native config class.
  • The config is registered for nemotron_h and exported from tensorrt_llm._torch.configs. TransformersTokenizer.from_pretrained imports that module before tokenizer loading so the registration is available.
  • The custom config validates pattern characters and block types. It also sets layer depth from the pattern and preserves config fields such as use_cache. Verify compatibility with checkpoint variants and future Transformers config changes.
  • The waiver removal enables the Nemotron Nano NVFP4 integration case to run. Test execution results are not established by the available evidence.

QA Engineer Review

  • Modified tests/unittest/_torch/test_custom_config_registration.py with Nemotron-H tests for dense-pattern preservation, native-config dispatch, invalid patterns and block types, block-type conversion, MTP behavior, use_cache, tokenizer loading in a clean process, and model-config loading.
  • Added the test file to tests/integration/test_lists/test-db/l0_cpu.yml. Removed the Nemotron Nano NVFP4 waiver from tests/integration/test_lists/waives.txt.
  • Coverage verdict: sufficient for the stated config registration and loading paths. Test results are unavailable.

Per-File QA Perspective

  • tensorrt_llm/_torch/configs/__init__.py: Exports NemotronHConfig and overrides the Transformers mapping for nemotron_h. Verify dense checkpoints use the local config and representable patterns still use the native config.
  • tensorrt_llm/_torch/configs/nemotron_h.py: Adds custom parsing, validation, and pattern/block-type handling. Verify pattern round-tripping and expected config fields across supported checkpoint formats.
  • tensorrt_llm/tokenizer/tokenizer.py: Imports the config package before AutoTokenizer.from_pretrained. Verify tokenizer loading works when config registration has not occurred earlier in the process.
  • tests/unittest/_torch/test_custom_config_registration.py: Adds registration and Nemotron-H regression tests. Listed in tests/integration/test_lists/test-db/l0_cpu.yml; no manual-QA list entry is established.
  • tests/integration/test_lists/test-db/l0_cpu.yml: Adds the config-registration unit test file to the CPU CI list.
  • tests/integration/test_lists/waives.txt: Removes the Nemotron Nano NVFP4 test waiver, allowing that integration case to run.

Description

transformers 5.5.4's NemotronHConfig converts hybrid_override_pattern into layers_block_type with a mapping that only knows M, E and *. Every dense Nemotron-H checkpoint also uses - for MLP layers, so config construction raises KeyError: '-'. AutoTokenizer.from_pretrained calls AutoConfig.from_pretrained, so this fails before any model is built.

Reproduced on nvidia/NVIDIA-Nemotron-Nano-9B-v2-NVFP4 (CPU only, no GPU required):

File ".../transformers/models/nemotron_h/configuration_nemotron_h.py", line 271, in _pattern_to_list
    return [pattern_mapping[char] for char in pattern]
KeyError: '-'

Widening that one mapping is not sufficient — each of these was checked against the installed 5.5.4:

  • NemotronHConfig.validate_layers_block_type restricts entries to {"mamba", "attention", "moe"}.
  • The base validate_layer_type, reached via attribute_map = {"layer_types": "layers_block_type"}, also rejects "mlp".
  • hybrid_override_pattern is a read-only property derived from layers_block_type through a reverse mapping with no -, so the MLP entries cannot be recovered even after the first two are relaxed.

TRT-LLM builds Nemotron-H by iterating hybrid_override_pattern (modeling_nemotron_h.py, ModelConfig.get_num_attention_layers / get_num_mamba_layers, and the mamba/attention masks in config_utils.py), so the literal checkpoint string has to survive config loading intact.

This PR adds a TRT-LLM-local NemotronHConfig that stores the pattern verbatim and registers it for model_type="nemotron_h". Its from_dict delegates straight back to the native transformers class for every pattern transformers can express, so the only checkpoints whose behaviour changes are the ones that cannot be loaded at all today.

Upstream fixed this in transformers v5.6.2; requirements.txt pins transformers==5.5.4. Updating that pin is a substantially larger change than this compatibility shim.

Test Coverage

  • tests/unittest/_torch/test_custom_config_registration.py — four new CPU-only tests: the dense pattern survives AutoConfig with layer counts intact, representable patterns still resolve to the native transformers class, invalid pattern characters raise a clear ValueError, and ModelLoader.load_hf_model_config returns a usable config.
  • test_e2e.py::test_ptp_quickstart_advanced[Nemotron-Nano-9B-v2-nvfp4-NVIDIA-Nemotron-Nano-9B-v2-NVFP4] — the nvbugs/6624972 waiver is removed so this B200 pre_merge case exercises the fix directly.

PR Checklist

  • 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.

@BowenFu

BowenFu commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

Draft pending CI — root-caused and fixed the nvbugs/6624972 Nemotron-H config failure. CC @BowenFu

  • transformers==5.5.4 cannot represent - (MLP) layers in hybrid_override_pattern, so AutoConfig/AutoTokenizer raise KeyError: '-' on every dense Nemotron-H checkpoint.
  • Reproduced CPU-only on nvidia/NVIDIA-Nemotron-Nano-9B-v2-NVFP4; verified the pattern now round-trips unchanged.
  • The shim delegates to the native transformers class for every pattern it can express, so only currently-unloadable checkpoints change behaviour.
  • The nvbugs/6624972 waiver is removed so the B200 pre_merge case covers the fix.

Promoting out of draft once pre-merge CI is green.

@BowenFu

BowenFu commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #68036 [ run ] triggered by Bot. Commit: 7a3f15c Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #68036 [ run ] completed with state SUCCESS. Commit: 7a3f15c
/LLM/main/L0_MergeRequest_PR pipeline #55488 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@BowenFu

BowenFu commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #68235 [ run ] triggered by Bot. Commit: 7a3f15c Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #68235 [ run ] completed with state FAILURE. Commit: 7a3f15c
/LLM/main/L0_MergeRequest_PR pipeline #55676 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@BowenFu

BowenFu commented Aug 23, 2026

Copy link
Copy Markdown
Contributor Author

Re-running CI: the last failure was infrastructure, not this PR.

  • CI Agent Failure Analysis for pipeline #55676 concludes PR likely to blame: No — package sanity died building an ancient uvicorn==0.2.1 sdist, and the Slurm retry hit a Jenkins posix_spawn/nohup failure, both before this PR's Nemotron-H E2E test ran.
  • No code change is indicated; head is unchanged at 7a3f15c.
  • Re-triggering with --disable-fail-fast so a single pipeline gives complete results instead of aborting at the first infra hiccup.

/bot run --disable-fail-fast

@BowenFu

BowenFu commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

Re-triggering: the previous CI command never registered.

  • The /bot run --disable-fail-fast line was appended to the end of the previous comment; blossom-CI only parses a comment that starts with /bot, so it was never acknowledged and no pipeline ran.
  • Head is unchanged at 7a3f15c; the last result is still infra-only pipeline #55676.
  • Re-issuing the same command as a standalone comment below.

@BowenFu

BowenFu commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #68739 [ run ] triggered by Bot. Commit: 7a3f15c Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #68739 [ run ] completed with state FAILURE. Commit: 7a3f15c
/LLM/main/L0_MergeRequest_PR pipeline #56135 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@BowenFu
BowenFu force-pushed the fix/nvbug-6624972-nemotron-h-mlp-pattern branch from 7a3f15c to 1e8ee68 Compare August 25, 2026 02:40
@BowenFu

BowenFu commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

Fixed the current-head AutoDeploy constructor failure.

  • Pipeline #56135 analysis identified a deterministic PR-owned failure: HF forwarded use_cache=False, but NemotronHForCausalLM.__init__ rejected it.
  • Commit 1e8ee684f43 now accepts factory model kwargs, matching the established custom AutoDeploy model contract.
  • Added a CPU-only regression for the exact _from_config(config, use_cache=False) path.
  • Exact pre-commit passed. This host lacks torch and transformers, so runtime validation and the unwaived B200 case remain CI gates; the PR stays draft.

Re-running the current head with fail-fast disabled.

@BowenFu

BowenFu commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #68963 [ run ] triggered by Bot. Commit: 1e8ee68 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #68963 [ run ] completed with state FAILURE. Commit: 1e8ee68
/LLM/main/L0_MergeRequest_PR pipeline #56344 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@BowenFu

BowenFu commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

Pushed a fix for the registration-ordering failure in 122265db.

The failure analysis for pipeline #56344 was right: the local NemotronHConfig was registered, but the failing path is LLM(...) → _try_load_tokenizer() → AutoTokenizer.from_pretrained() → AutoConfig.from_pretrained(), which ran before tensorrt_llm._torch.configs had been imported. Stock transformers resolved the config and rejected the - MLP layers with KeyError: '-'.

The fix imports the module eagerly in TransformersTokenizer.from_pretrained, matching what tokenizer/deepseek_v32 and tokenizer/deepseek_v4 already do for the same reason. One file, seven lines.

The A30 OOMs and the apt-get update timeout in that run were unrelated.

@BowenFu

BowenFu commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

/bot run

@pranav-nvidia
pranav-nvidia force-pushed the fix/nvbug-6624972-nemotron-h-mlp-pattern branch from 122265d to 4f65f5e Compare September 17, 2026 23:42
@pranav-nvidia

Copy link
Copy Markdown
Contributor

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #74239 [ run ] triggered by Bot. Commit: 4f65f5e Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #74239 [ run ] completed with state FAILURE. Commit: 4f65f5e
/LLM/main/L0_MergeRequest_PR pipeline #61063 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@pranav-nvidia
pranav-nvidia marked this pull request as ready for review September 21, 2026 18:32
@pranav-nvidia
pranav-nvidia requested review from a team as code owners September 21, 2026 18:32
@pranav-nvidia
pranav-nvidia requested review from a team as code owners October 1, 2026 19:10
@pranav-nvidia
pranav-nvidia changed the base branch from main to release/1.3 October 1, 2026 19:10
@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Semantic conflict review

The verdict of record is the Semantic conflict with target branch / PR #18042 commit status on the requested head commit. This summary updates on reply events and may lag between a new request and its reply.

Latest recorded state: No semantic conflict found (best effort) for head 2f239ad2848e16b5f15bc600a27fded239810ecd, target 2ec1abb24e0a91f43af8a05bfc65f83b14cf6a84, merge base 8ae24cb730acb4da7358fea51705351e32af2908 (request ea034dfc-ecea-4eeb-8b78-606a86ff1fdb). CodeRabbit analysis.

Best-effort AI judgment for the recorded revisions. PASS, FAIL and INCONCLUSIVE may be incomplete or incorrect. PR authors and reviewers should independently verify the evidence and relevant behavior. This semantic review and its status/workflow are advisory, not required merge checks under current repository rules; other merge requirements still apply. Advisory status does not make a confirmed defect safe to ignore.

Requested (UTC) Head Target Verdict Comment
2026-10-02T16:42:41Z 2f239ad2848e 2ec1abb24e0a PASS reply
2026-10-01T22:38:11Z 2f239ad2848e a5874beb8999 PASS reply
2026-10-01T16:39:43Z 07593c0d333b de1d696889ae INCONCLUSIVE reply
2026-10-01T08:49:25Z 07593c0d333b d6ebc4dc07aa INCONCLUSIVE reply
2026-10-01T02:57:29Z 07593c0d333b 534e1f8ad9d5 INCONCLUSIVE reply
2026-09-30T18:48:00Z 07593c0d333b 14863787ca19 INCONCLUSIVE reply
2026-09-30T12:58:52Z 07593c0d333b 84de36ed03b2 INCONCLUSIVE reply
2026-09-30T04:44:19Z 07593c0d333b a223c73d83ac INCONCLUSIVE reply
2026-09-29T20:41:43Z 07593c0d333b 00bdcb6ed7c5 INCONCLUSIVE reply
2026-09-29T14:44:01Z 07593c0d333b ae3531adf3ed INCONCLUSIVE reply
2026-09-29T06:58:05Z 07593c0d333b ffa868930919 INCONCLUSIVE reply
2026-09-29T01:18:18Z 07593c0d333b 5054e82a6d0b PASS reply
2026-09-28T16:43:00Z 8c42fddc2d9d ca937c95012b INCONCLUSIVE reply
2026-09-28T10:39:55Z 8c42fddc2d9d cc608b774ae9 FAIL reply

Processed request and reply comments are minimized to reduce timeline noise; they remain expandable for audit.

@pranav-nvidia

Copy link
Copy Markdown
Contributor

Retargeted this PR to release/1.3 and rewrote the head cleanly onto current release commit 8ae24cb730 (new head: 2f239ad284).

This was not a direct base switch: the rewritten head contains only the intended six-file NVBug fix (533 additions, 1 deletion), with no unrelated post-branch main history. The release branch still pins transformers==5.5.4, contains the affected Nemotron-Nano NVFP4 test, and carried the NVBug 6624972 waiver, so the fix remains applicable there. The rewritten result explicitly removes that waiver while preserving surrounding release entries, resolving the ambiguity reported by the recent semantic-review scans.

Validation before push:

  • isolated Transformers 5.5.4 behavior checks passed for dense MLP patterns, native-compatible delegation, block-type-only configs, invalid-pattern handling, MTP mapping, and use_cache
  • changed Python files compile
  • full pre-commit suite passed on the signed commit
  • GitHub reports the PR mergeable with all review threads resolved

The previous full CI run on the same six-file implementation passed on main; triggering a fresh run against release/1.3 now.

@pranav-nvidia

Copy link
Copy Markdown
Contributor

/bot run

@pranav-nvidia pranav-nvidia 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.

@dcoapp recheck

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #75996 [ run ] triggered by Bot. Commit: 2f239ad Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #75996 [ run ] completed with state FAILURE. Commit: 2f239ad
/LLM/release-1.3/L0_MergeRequest_PR pipeline #24 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@zhangcl

zhangcl commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

@pranav-nvidia it looks like the changes don't touch the MoE block, so there's no need for review from trt-llm-moe-devs?

@trtllm-agent

This comment has been minimized.

@coderabbitai

This comment has been minimized.

@trtllm-agent

This comment has been minimized.

@coderabbitai

This comment has been minimized.

@pranav-nvidia

Copy link
Copy Markdown
Contributor

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #76106 [ run ] triggered by Bot. Commit: 2f239ad Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #76106 [ run ] completed with state SUCCESS. Commit: 2f239ad
/LLM/release-1.3/L0_MergeRequest_PR pipeline #35 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@pranav-nvidia

Copy link
Copy Markdown
Contributor

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #76129 [ run ] triggered by Bot. Commit: 2f239ad Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #76129 [ run ] completed with state SUCCESS. Commit: 2f239ad
/LLM/release-1.3/L0_MergeRequest_PR pipeline #41 completed with status: 'SUCCESS'

CI Report

Link to invocation

@pranav-nvidia
pranav-nvidia merged commit af8c4a2 into NVIDIA:release/1.3 Oct 5, 2026
5 of 6 checks passed
SimengLiu-nv pushed a commit to SimengLiu-nv/TensorRT-LLM that referenced this pull request Oct 14, 2026
….3: Preserve Nemotron-H hybrid_override_pattern with MLP layers

Forward-port of release/1.3 PR NVIDIA#18042
(release/1.3 commit af8c4a2) to main.

Signed-off-by: Pranav Shrestha <254760092+pranav-nvidia@users.noreply.github.com>
Co-authored-by: Pranav Shrestha <254760092+pranav-nvidia@users.noreply.github.com>
Signed-off-by: Simeng Liu <simengl@nvidia.com>
dominicshanshan added a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Oct 18, 2026
…nt declares it

NemotronHConfig from tensorrt_llm._torch.configs (NVIDIA#18042), registered for
nemotron_h checkpoints whose hybrid_override_pattern has "-" MLP layers,
defaulted mamba_ssm_cache_dtype to "float32". transformers 5.5.4 prefers a
registered non-transformers config class over the checkpoint's remote code
even with trust_remote_code=True, so dense checkpoints such as
NVIDIA-Nemotron-Nano-12B-v2, whose config.json does not declare the field,
switched from a bf16 to an fp32 SSM state cache.

That doubles the recurrent state per sequence (75.5 MB -> 148.9 MB for
Nano-12B-v2). At max_batch_size 512 the V2 Mamba cache then needs
513 x 148,865,024 + 786,432 = 76,368,543,744 bytes, above the ~53 GB H100
quota, and these perf tests fail at executor init with "The V2 Mamba GPU
cache quota is too small for live recurrent states and attention pages":

  perf/test_perf.py::test_perf[nemotron_nano_12b_v2-bench-pytorch-bfloat16-input_output_len:128,128]
  perf/test_perf.py::test_perf[nemotron_nano_12b_v2-bench-pytorch-bfloat16-input_output_len:500,2000-con:250]

Leave mamba_ssm_cache_dtype as None when the checkpoint does not declare
it, so resolve_auto_ssm_cache_dtype falls back to the model dtype, as it
does with the checkpoint's own config and on main (which does not carry
NVIDIA#18042). A declared value is still honored, and patterns transformers can
represent natively still load through its own NemotronHConfig.

Add a regression test for both cases.

Signed-off-by: Wangshanshan <30051912+dominicshanshan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants