Skip to content

[None][fix] AutoDeploy: return fused_weight_dims so fused QKV split sizes are rescaled under TP - #15351

Merged
greg-kwasniewski1 merged 5 commits into
NVIDIA:mainfrom
CodersAcademy006:fix/phi4-tp2-fused-weight-dims
Jul 12, 2026
Merged

[None][fix] AutoDeploy: return fused_weight_dims so fused QKV split sizes are rescaled under TP#15351
greg-kwasniewski1 merged 5 commits into
NVIDIA:mainfrom
CodersAcademy006:fix/phi4-tp2-fused-weight-dims

Conversation

@CodersAcademy006

@CodersAcademy006 CodersAcademy006 commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #11220.

_determine_fused_weight_dims() computes fused projection dimensions for fused QKV layouts but never returns the computed value. As a result, _process_column_sharding() always receives None and skips downstream split-size rescaling during tensor parallel sharding.

Root Cause

The helper populates fused_weight_dims but falls through without a return statement despite callers expecting the value.

Fix

  • Change return type from None to Optional[list]
  • Return computed fused_weight_dims
  • Add regression tests covering fused and non-fused paths

Validation

Added CPU-only regression tests for:

  • fused QKV split detection
  • unfused linear projections
  • multiple linear inputs

The fused QKV test reproduces the regression (the helper returns None before the fix); the other two pin existing behavior.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of fused weight dimension detection so the calculated split sizes are now returned correctly when available.
  • Tests
    • Added regression coverage for fused QKV split detection.
    • Added checks for cases where fused dimensions should not be returned, including unfused linear paths and multiple-linear scenarios.

…izes are rescaled under TP

_determine_fused_weight_dims computed the fused dims into a local variable
but fell off the end of the function with no return statement (and was
annotated -> None), so callers always received None. As a result the
"if fused_weight_dims is not None" branch in _process_column_sharding never
ran, and the downstream split_with_sizes / slice sizes were left at their
pre-sharding values after a column shard.

For Phi-4 at TP=2 the fused QKV output dim is halved by the column shard
(7680 to 3840) while the split sizes stay at [5120, 1280, 1280], so the
wrong shape propagates until a row-parallel projection expects 2560 and the
matmul fails.

Fix: return the computed fused_weight_dims and correct the annotation to
Optional[list]. No other logic changes; the existing rescaling branch now
receives the dims it was always meant to get.

Adds CPU-only regression tests for _determine_fused_weight_dims covering the
fused QKV split case, the unfused (no fusion) case, and the multi-linear case.

Signed-off-by: Srijan Upadhyay <srjnupadhyay@gmail.com>
@CodersAcademy006
CodersAcademy006 marked this pull request as ready for review July 6, 2026 03:47
@CodersAcademy006
CodersAcademy006 requested a review from a team as a code owner July 6, 2026 03:47
@CodersAcademy006
CodersAcademy006 requested a review from MrGeva July 6, 2026 03:47
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

A missing return statement in _determine_fused_weight_dims is fixed so it now returns computed fused weight dimensions instead of implicitly returning None, addressing a regression affecting Phi-4 model sharding. A new test module validates the fix across fused, unfused, and multi-linear graph scenarios.

Changes

Fused Weight Dims Fix and Tests

Layer / File(s) Summary
Fix missing return statement
tensorrt_llm/_torch/auto_deploy/transform/library/sharding.py
_determine_fused_weight_dims return type annotation updated to Optional[list], and an explicit return fused_weight_dims is added so the computed value propagates to callers instead of being silently dropped.
Regression tests for fused weight dims
tests/unittest/auto_deploy/singlegpu/transformations/library/test_determine_fused_weight_dims.py
New CPU-only test module with a _linear_node helper and three tests validating: fused Phi-4 QKV split sizes are returned, unfused linear returns None, and multiple linear nodes return None.

Estimated code review effort: 2 (Simple) | ~10 minutes

Related issues: Fixes #11220 — [Bug]: microsoft/phi-4 models regression, caused by _determine_fused_weight_dims not returning its computed value, leading to a matmul reduction-dim mismatch during sharding.

Suggested labels: bug, auto-deploy, tests

Suggested reviewers: (repository maintainers familiar with auto_deploy sharding transforms)

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The fix matches #11220 by returning fused split sizes and adding regression tests for fused, unfused, and multi-linear paths.
Out of Scope Changes check ✅ Passed The changes stay tightly scoped to the AutoDeploy sharding bug fix and its regression tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title matches the main fix and follows the required [None][fix] pattern.
Description check ✅ Passed The description clearly states the issue, root cause, fix, and validation, covering the required content well.
✨ 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.

🧹 Nitpick comments (2)
tensorrt_llm/_torch/auto_deploy/transform/library/sharding.py (1)

2709-2711: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use list[int] | None instead of Optional[list].

Per repo typing conventions, prefer built-in generics with the | syntax over typing.Optional, and specify the element type rather than a bare list.

♻️ Proposed fix
 def _determine_fused_weight_dims(
     linear_nodes: List[Node],
-) -> Optional[list]:
+) -> list[int] | None:

As per coding guidelines, "Prefer built-in types list, dict, tuple over typing.List, typing.Dict, typing.Tuple; use | syntax instead of typing.Union" and "Always annotate functions with return types... annotate class members and variables when necessary."

🤖 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/_torch/auto_deploy/transform/library/sharding.py` around lines
2709 - 2711, Update the return type annotation on _determine_fused_weight_dims
to use the repo’s preferred built-in generic syntax: replace Optional[list] with
list[int] | None. Keep the change localized to the _determine_fused_weight_dims
function signature in sharding.py, and make sure any related type hints in
nearby code follow the same built-in generics style.

Source: Coding guidelines

tests/unittest/auto_deploy/singlegpu/transformations/library/test_determine_fused_weight_dims.py (1)

45-102: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Good regression coverage for the split path; slice/chunk branches remain untested.

The three tests solidly cover the split_with_sizes regression path and two None-return guards. However, _determine_fused_weight_dims also has elif branches for torch.ops.aten.slice users (fused QKV via slicing, sharding.py lines 2731-2746) and torch.ops.aten.chunk users (sharding.py lines 2748-2754), both of which are also affected by the same missing-return bug and are not exercised here.

Coverage is sufficient for the immediate Phi-4 regression (split-based fusion) but insufficient for the helper as a whole. Consider adding test_fused_qkv_slice_returns_split_sizes and test_fused_qkv_chunk_returns_split_sizes to this same file to close the gap, or track as a fast follow-up if out of scope for this PR.

🤖 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
`@tests/unittest/auto_deploy/singlegpu/transformations/library/test_determine_fused_weight_dims.py`
around lines 45 - 102, Add regression tests for the untested fused paths in
`_determine_fused_weight_dims`: create one test that feeds a linear node into
`torch.ops.aten.slice` and another into `torch.ops.aten.chunk`, then assert the
helper returns the expected fused sizes instead of None. Reuse the existing test
setup pattern in `test_determine_fused_weight_dims.py` and the helper
`_linear_node` so the new coverage matches the current split-based test and
exercises the `slice` and `chunk` branches in `_determine_fused_weight_dims`.

Source: Path instructions

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

Nitpick comments:
In `@tensorrt_llm/_torch/auto_deploy/transform/library/sharding.py`:
- Around line 2709-2711: Update the return type annotation on
_determine_fused_weight_dims to use the repo’s preferred built-in generic
syntax: replace Optional[list] with list[int] | None. Keep the change localized
to the _determine_fused_weight_dims function signature in sharding.py, and make
sure any related type hints in nearby code follow the same built-in generics
style.

In
`@tests/unittest/auto_deploy/singlegpu/transformations/library/test_determine_fused_weight_dims.py`:
- Around line 45-102: Add regression tests for the untested fused paths in
`_determine_fused_weight_dims`: create one test that feeds a linear node into
`torch.ops.aten.slice` and another into `torch.ops.aten.chunk`, then assert the
helper returns the expected fused sizes instead of None. Reuse the existing test
setup pattern in `test_determine_fused_weight_dims.py` and the helper
`_linear_node` so the new coverage matches the current split-based test and
exercises the `slice` and `chunk` branches in `_determine_fused_weight_dims`.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 14b2a658-40df-45e2-8b75-0b889269e4db

📥 Commits

Reviewing files that changed from the base of the PR and between 45fae3e and 6eac3ea.

📒 Files selected for processing (2)
  • tensorrt_llm/_torch/auto_deploy/transform/library/sharding.py
  • tests/unittest/auto_deploy/singlegpu/transformations/library/test_determine_fused_weight_dims.py

@MrGeva
MrGeva requested review from greg-kwasniewski1 and removed request for MrGeva July 6, 2026 09:08

@greg-kwasniewski1 greg-kwasniewski1 left a comment

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.

Good catch!

Satisfies the formatting pre-commit hook, which merges an import
statement onto a single line when it fits within the configured line
length rather than keeping it in parenthesized multi-line form.

Signed-off-by: Srijan Upadhyay <srjnupadhyay@gmail.com>
@CodersAcademy006
CodersAcademy006 force-pushed the fix/phi4-tp2-fused-weight-dims branch from fcf4411 to bbea605 Compare July 7, 2026 18:40
@greg-kwasniewski1

Copy link
Copy Markdown
Collaborator

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58495 [ run ] triggered by Bot. Commit: bbea605 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58495 [ run ] completed with state SUCCESS. Commit: bbea605
/LLM/main/L0_MergeRequest_PR pipeline #47103 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

CI Report

Link to invocation

@greg-kwasniewski1
greg-kwasniewski1 merged commit 5e77882 into NVIDIA:main Jul 12, 2026
7 checks passed
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.

[Bug]: microsoft/phi-4 models regression

3 participants