Skip to content

[None][feat] Eagle: Norm before FC#12561

Open
IzzyPutterman wants to merge 1 commit intoNVIDIA:mainfrom
IzzyPutterman:iputterman/eagle-norm-fc
Open

[None][feat] Eagle: Norm before FC#12561
IzzyPutterman wants to merge 1 commit intoNVIDIA:mainfrom
IzzyPutterman:iputterman/eagle-norm-fc

Conversation

@IzzyPutterman
Copy link
Copy Markdown
Collaborator

@IzzyPutterman IzzyPutterman commented Mar 27, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced Eagle3DraftModel to conditionally apply input normalization before fully-connected projection when input dimensions don't match the model's hidden size, improving correctness in shape-mismatch scenarios.

Description

Test Coverage

PR 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)

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

Signed-off-by: Izzy Putterman <iputterman@nvidia.com>
@IzzyPutterman IzzyPutterman requested a review from a team as a code owner March 27, 2026 15:25
@IzzyPutterman IzzyPutterman requested a review from 2ez4bz March 27, 2026 15:25
@IzzyPutterman
Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 27, 2026

📝 Walkthrough

Walkthrough

The Eagle3DraftModel now conditionally creates an input_norm (RMSNorm) module based on configuration and applies optional normalization to hidden states in the apply_eagle3_fc() method when input dimensions mismatch the model's hidden size, prior to existing FC projection.

Changes

Cohort / File(s) Summary
Eagle3DraftModel Normalization Enhancement
tensorrt_llm/_torch/models/modeling_speculative.py
Added conditional input_norm (RMSNorm) module creation when eagle_config["norm_before_fc"] is enabled. Modified apply_eagle3_fc() to apply input normalization before FC projection when dimension mismatch occurs and normalization is configured.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

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.
Description check ⚠️ Warning The PR description is incomplete and lacks required details. While the template is present, all key sections (Description, Test Coverage) are empty with only placeholder comments. Fill in the Description section explaining what changes were made and why. Add Test Coverage section listing relevant tests for the norm_before_fc feature. Complete the PR checklist items appropriately.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding norm before FC in Eagle model, which aligns with the raw summary showing conditional RMSNorm creation and pre-FC normalization.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tensorrt_llm/_torch/models/modeling_speculative.py (1)

1-1: ⚠️ Potential issue | 🟠 Major

Add/refresh the NVIDIA copyright header for this modified source file.

This file was modified but has no copyright header at the top.

As per coding guidelines: “All TensorRT-LLM source files (.cpp, .h, .cu, .py) should contain an NVIDIA copyright header with the year of its latest meaningful modification.”

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tensorrt_llm/_torch/models/modeling_speculative.py` at line 1, This file
(modeling_speculative.py) is missing the required NVIDIA copyright header; add
the standard NVIDIA copyright header (with the latest modification year) at the
very top of the file above the first import (above the existing "import
inspect") so the header appears in the module-level comment block; ensure it
follows the project's header template and includes the correct year and
ownership text.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tensorrt_llm/_torch/models/modeling_speculative.py`:
- Around line 564-567: The mismatch-path unconditionally calls self.model.fc
causing an AttributeError when fc is not created; update apply_eagle3_fc to
first check for the presence of the projection before invoking it (e.g., use
hasattr/getattr on self.model for "fc"), apply input_norm only if
self.model._norm_before_fc is true, and if fc is missing handle
gracefully—either skip projection (and document behavior) or raise a clear,
descriptive error mentioning missing fc—so the code does not crash in configs
where Eagle3DraftModel omits fc.

---

Outside diff comments:
In `@tensorrt_llm/_torch/models/modeling_speculative.py`:
- Line 1: This file (modeling_speculative.py) is missing the required NVIDIA
copyright header; add the standard NVIDIA copyright header (with the latest
modification year) at the very top of the file above the first import (above the
existing "import inspect") so the header appears in the module-level comment
block; ensure it follows the project's header template and includes the correct
year and ownership text.
🪄 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: Pro

Run ID: 2357c4a6-2969-40dc-8e0a-ed9536ddfa4e

📥 Commits

Reviewing files that changed from the base of the PR and between 74a27e8 and a386594.

📒 Files selected for processing (1)
  • tensorrt_llm/_torch/models/modeling_speculative.py

Comment on lines 564 to 567
if hidden_states.shape[-1] != expected_hidden_size:
if self.model._norm_before_fc:
hidden_states = self.model.input_norm(hidden_states)
hidden_states = self.model.fc(hidden_states)
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

Harden apply_eagle3_fc against missing fc in the mismatch path.

At Line 567, projection is unconditional once a hidden-size mismatch is detected. Since fc is created conditionally in Eagle3DraftModel.__init__, this can fail with an AttributeError in unsupported/edge configs.

Proposed hardening diff
         expected_hidden_size = self.model.hidden_size
+        fc = getattr(self.model, "fc", None)
         if hidden_states.shape[-1] != expected_hidden_size:
+            if fc is None:
+                raise RuntimeError(
+                    "Hidden size mismatch requires Eagle3 FC projection, but `fc` is not initialized."
+                )
             if self.model._norm_before_fc:
                 hidden_states = self.model.input_norm(hidden_states)
-            hidden_states = self.model.fc(hidden_states)
+            hidden_states = fc(hidden_states)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tensorrt_llm/_torch/models/modeling_speculative.py` around lines 564 - 567,
The mismatch-path unconditionally calls self.model.fc causing an AttributeError
when fc is not created; update apply_eagle3_fc to first check for the presence
of the projection before invoking it (e.g., use hasattr/getattr on self.model
for "fc"), apply input_norm only if self.model._norm_before_fc is true, and if
fc is missing handle gracefully—either skip projection (and document behavior)
or raise a clear, descriptive error mentioning missing fc—so the code does not
crash in configs where Eagle3DraftModel omits fc.

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #40507 [ run ] triggered by Bot. Commit: a386594 Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #40507 [ run ] completed with state SUCCESS. Commit: a386594
/LLM/main/L0_MergeRequest_PR pipeline #31595 completed with status: 'SUCCESS'

CI Report

Link to invocation

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.

2 participants