Skip to content

[None][feat] VisualGen TP with Attn2D#16677

Open
belgarten-nv wants to merge 3 commits into
NVIDIA:mainfrom
belgarten-nv:dev/tp-attn2d
Open

[None][feat] VisualGen TP with Attn2D#16677
belgarten-nv wants to merge 3 commits into
NVIDIA:mainfrom
belgarten-nv:dev/tp-attn2d

Conversation

@belgarten-nv

@belgarten-nv belgarten-nv commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Dev Engineer Review

  • Updated tensorrt_llm/_torch/visual_gen/mapping.py so the Attention2D code path no longer blocks configurations with tp_size > 1 (removes the prior NotImplementedError behavior). This allows VisualGen tensor parallelism to work when Attention2D is enabled.
  • Ensured cp_size is derived from attn2d_row_size * attn2d_col_size for the Attention2D case, so CP sizing stays consistent for mixed TP + Attention2D topologies.
  • Extended tests/unittest/_torch/visual_gen/multi_gpu/test_wan_transformer_parallel.py to treat tp as a first-class distributed dimension:
    • Updated _make_model_config(..., tp_size=1, ...) to include tp_size in the “use distributed” selection and pass it through to VisualGenMapping.
    • Added _copy_ref_weights_to_tp to map single-GPU reference weights into TP-sharded layouts when tp_size > 1, improving correctness comparisons for TP cases.
    • Added TP + Attention2D variants to the 8-GPU parallel combination matrix (including tp2_attn2d_2x1_ul2 and tp2_attn2d_2x2_ul1).

QA Engineer Review

  • Test configuration / entry updates

    • Updated tests/integration/defs/examples/visual_gen/test_visual_gen_multi_gpu.py by adding the TP variant ("tp2_attn2d_2x1", {"tp_size": 2, "attn2d_size": (2, 1)}) so the existing LPIPS-vs-golden TP test runs an additional distributed case.
    • Updated tests/integration/test_lists/test-db/l0_dgx_b200.yml to add:
      • examples/visual_gen/test_visual_gen_multi_gpu.py::test_wan22_t2v_lpips_against_golden_tp[tp2_attn2d_2x1]
  • Test code changes (added/modified)

    • tests/unittest/_torch/visual_gen/multi_gpu/test_visual_gen_mapping.py
      • Added TestConstruction.test_tp_and_attn2d_constructible to validate TP + Attention2D construction and derived sizing (tp_size, derived cp_size, and configured attn2d_row_size/attn2d_col_size).
      • Added _logic_tp2_attn2d_2x1_groups(rank, world_size) and TestMultiGPU.test_tp2_attn2d_2x1_groups to validate TP/Attention2D process-group setup (including expected group existence/world sizes) and collective correctness for the TP2 + Attention2D(2x1) topology.
    • tests/unittest/_torch/visual_gen/multi_gpu/test_wan_transformer_parallel.py
      • Modified _make_model_config to accept tp_size and propagate it into VisualGenMapping.
      • Added _copy_ref_weights_to_tp and used it in the TP comparison path.
  • Coverage linkage

    • The new integration TP+Attention2D case is linked via l0_dgx_b200 test-db entry for test_wan22_t2v_lpips_against_golden_tp[tp2_attn2d_2x1].
  • Verdict: needs follow-up (CI failures were reported in the provided context; no passing/completion confirmation is included here).

Description

Removes an (unnecessary) conditional blocking TP with Attn2D in VisualGen. Adds LPIPS test config to ensure correctness.

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)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • 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: Brenden Elgarten <belgarten@nvidia.com>
@belgarten-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Attention2D mapping no longer rejects tp_size > 1 configurations. Unit, transformer-topology, and distributed LPIPS tests now cover tp_size=2 with attn2d_size=(2, 1).

Changes

Attention2D Tensor Parallel Support

Layer / File(s) Summary
Enable and validate Attention2D tensor parallelism
tensorrt_llm/_torch/visual_gen/mapping.py, tests/unittest/_torch/visual_gen/multi_gpu/test_visual_gen_mapping.py
Attention2D assigns cp_size directly, while tests validate construction, rank derivation, process groups, and collectives for TP2 with a 2×1 mesh.
Wire TP through transformer topology tests
tests/unittest/_torch/visual_gen/multi_gpu/test_wan_transformer_parallel.py
The 8-GPU topology matrix and model configuration now include and forward tensor-parallel settings, and TP reference weights are copied into partitioned model parameters for comparisons.
Add distributed integration coverage
tests/integration/defs/examples/visual_gen/test_visual_gen_multi_gpu.py, tests/integration/test_lists/test-db/l0_dgx_b200.yml
The TP LPIPS matrix and DGX test list add the tp2_attn2d_2x1 case.

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

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change, but the required Test Coverage section is empty. Add the specific tests run or added for this change and briefly note what each one validates.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, correctly formatted, and reflects the main VisualGen TP+Attn2D change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 `@tests/integration/defs/examples/visual_gen/test_visual_gen_multi_gpu.py`:
- Line 72: Add the tp2_attn2d_2x1 case to the relevant integration test entry in
l0_dgx_b200.yml, alongside the existing tp2, cfg2_tp2, and tp2_ulysses2 cases,
while leaving the test function unchanged.
🪄 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: d0e7665f-3194-431d-99fb-548c42704828

📥 Commits

Reviewing files that changed from the base of the PR and between a75e333 and 0847552.

📒 Files selected for processing (2)
  • tensorrt_llm/_torch/visual_gen/mapping.py
  • tests/integration/defs/examples/visual_gen/test_visual_gen_multi_gpu.py
💤 Files with no reviewable changes (1)
  • tensorrt_llm/_torch/visual_gen/mapping.py

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60742 [ run ] triggered by Bot. Commit: 0847552 Link to invocation

@NVShreyas NVShreyas 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.

LGTM

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60742 [ run ] completed with state FAILURE. Commit: 0847552
/LLM/main/L0_MergeRequest_PR pipeline #49029 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

Signed-off-by: Brenden Elgarten <belgarten@nvidia.com>
@belgarten-nv
belgarten-nv requested a review from a team as a code owner July 21, 2026 21:51
@belgarten-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@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 `@tests/unittest/_torch/visual_gen/multi_gpu/test_visual_gen_mapping.py`:
- Around line 527-570: Update _logic_tp2_attn2d_2x1_groups to reflect the
Attention2D mapping contract: assert attn2d_row_group has world size 1, use
attn2d_col_group for the size-2 collective and corresponding non-None assertion,
and retain the existing size-2 expectation for attn2d_mesh_group. Apply the same
group correction to the related assertions or collectives around the
additionally referenced lines.
🪄 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: 7e5bc640-9544-4b3d-9b84-a009bf62b977

📥 Commits

Reviewing files that changed from the base of the PR and between 0847552 and b1224a0.

📒 Files selected for processing (3)
  • tests/integration/test_lists/test-db/l0_dgx_b200.yml
  • tests/unittest/_torch/visual_gen/multi_gpu/test_visual_gen_mapping.py
  • tests/unittest/_torch/visual_gen/multi_gpu/test_wan_transformer_parallel.py

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60796 [ run ] triggered by Bot. Commit: b1224a0 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60796 [ run ] completed with state FAILURE. Commit: b1224a0
/LLM/main/L0_MergeRequest_PR pipeline #49074 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

Signed-off-by: Brenden Elgarten <belgarten@nvidia.com>
@belgarten-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@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: 2

🧹 Nitpick comments (1)
tests/unittest/_torch/visual_gen/multi_gpu/test_visual_gen_mapping.py (1)

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

Annotate the added functions.

Add -> None to both test methods, and type rank and world_size as int in _logic_tp2_attn2d_2x1_groups.

As per coding guidelines, every function must be annotated and non-returning functions must use None.

Proposed fix
-    def test_tp_and_attn2d_constructible(self):
+    def test_tp_and_attn2d_constructible(self) -> None:

-def _logic_tp2_attn2d_2x1_groups(rank, world_size):
+def _logic_tp2_attn2d_2x1_groups(rank: int, world_size: int) -> None:

-    def test_tp2_attn2d_2x1_groups(self):
+    def test_tp2_attn2d_2x1_groups(self) -> None:

Also applies to: 527-527, 598-598

🤖 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/_torch/visual_gen/multi_gpu/test_visual_gen_mapping.py` at
line 165, Annotate the added test methods, including
test_tp_and_attn2d_constructible and the other methods identified in the review,
with -> None. Update _logic_tp2_attn2d_2x1_groups to annotate both rank and
world_size as int, while preserving the existing test behavior.

Source: Coding guidelines

🤖 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 `@tests/unittest/_torch/visual_gen/multi_gpu/test_visual_gen_mapping.py`:
- Line 532: Update the row-major layout description near cp_rank to replace the
ambiguous multiplication sign with ASCII “x” or the wording “by”, preserving the
existing meaning.

In `@tests/unittest/_torch/visual_gen/multi_gpu/test_wan_transformer_parallel.py`:
- Around line 269-270: Update _copy_ref_weights_to_tp by adding concrete
annotations for ref_model and tp_model using their model types, and annotate
pretrained_config with an appropriate mapping type. Preserve the existing return
annotation and implementation behavior.

---

Nitpick comments:
In `@tests/unittest/_torch/visual_gen/multi_gpu/test_visual_gen_mapping.py`:
- Line 165: Annotate the added test methods, including
test_tp_and_attn2d_constructible and the other methods identified in the review,
with -> None. Update _logic_tp2_attn2d_2x1_groups to annotate both rank and
world_size as int, while preserving the existing test behavior.
🪄 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: 070b13de-bc70-4c92-93e4-6d654849f393

📥 Commits

Reviewing files that changed from the base of the PR and between b1224a0 and 6ea48e5.

📒 Files selected for processing (2)
  • tests/unittest/_torch/visual_gen/multi_gpu/test_visual_gen_mapping.py
  • tests/unittest/_torch/visual_gen/multi_gpu/test_wan_transformer_parallel.py


Mesh cfg-tp-cp_row-cp_col-ulysses with tp=2, attn2d_row=2, attn2d_col=1:
tp_rank = (rank // 2) % 2
cp_rank = rank % 2 (row-major over cp_row × cp_col)

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use ASCII x in the docstring.

Ruff reports RUF002 for the ambiguous multiplication sign on Line 532; write cp_row x cp_col or cp_row by cp_col instead.

🧰 Tools
🪛 Ruff (0.15.21)

[warning] 532-532: Docstring contains ambiguous × (MULTIPLICATION SIGN). Did you mean x (LATIN SMALL LETTER X)?

(RUF002)

🤖 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/_torch/visual_gen/multi_gpu/test_visual_gen_mapping.py` at
line 532, Update the row-major layout description near cp_rank to replace the
ambiguous multiplication sign with ASCII “x” or the wording “by”, preserving the
existing meaning.

Source: Linters/SAST tools

Comment on lines +269 to +270
def _copy_ref_weights_to_tp(ref_model, tp_model, pretrained_config) -> None:
"""Copy reference weights into a TP model using its local parameter layouts."""

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

file="tests/unittest/_torch/visual_gen/multi_gpu/test_wan_transformer_parallel.py"

# Map the file and inspect the relevant section with line numbers.
wc -l "$file"
sed -n '1,340p' "$file" | nl -ba | sed -n '240,300p'

# Look for imports and type aliases used by the helper.
sed -n '1,120p' "$file" | nl -ba | sed -n '1,120p'

Repository: NVIDIA/TensorRT-LLM

Length of output: 277


🏁 Script executed:

#!/bin/bash
set -euo pipefail

file="tests/unittest/_torch/visual_gen/multi_gpu/test_wan_transformer_parallel.py"

# Search for the helper and any relevant model/config types.
rg -n "def _copy_ref_weights_to_tp|pretrained_config|ref_model|tp_model|Wan|Transformer|Config|Model" "$file"

# Show nearby imports and type hints around the helper definition.
python3 - <<'PY'
from pathlib import Path
p = Path("tests/unittest/_torch/visual_gen/multi_gpu/test_wan_transformer_parallel.py")
text = p.read_text()
start = text.find("def _copy_ref_weights_to_tp")
print(text[max(0, start-1200):start+1200])
PY

Repository: NVIDIA/TensorRT-LLM

Length of output: 4354


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Look for how the helper is used, which can reveal the concrete model/config classes.
rg -n "_copy_ref_weights_to_tp\(" tests/unittest/_torch/visual_gen/multi_gpu/test_wan_transformer_parallel.py
rg -n "wan|transformer" tests/unittest/_torch/visual_gen/multi_gpu/test_wan_transformer_parallel.py

# Inspect the file header imports.
sed -n '1,80p' tests/unittest/_torch/visual_gen/multi_gpu/test_wan_transformer_parallel.py | nl -ba

Repository: NVIDIA/TensorRT-LLM

Length of output: 1413


🏁 Script executed:

#!/bin/bash
set -euo pipefail

file="tests/unittest/_torch/visual_gen/multi_gpu/test_wan_transformer_parallel.py"

# Show the setup around the config creation and the call site.
sed -n '210,235p' "$file"
printf '\n---\n'
sed -n '300,330p' "$file"

# Inspect whether pretrained_cfg/pretrained_config is a dict, namespace, or model object.
python3 - <<'PY'
from pathlib import Path
import re

text = Path("tests/unittest/_torch/visual_gen/multi_gpu/test_wan_transformer_parallel.py").read_text()

for name in ["pretrained_cfg", "pretrained_config", "ref_model", "dist_model", "tp_model"]:
    hits = [m.start() for m in re.finditer(rf"\b{name}\b", text)]
    print(name, len(hits), hits[:10])
PY

Repository: NVIDIA/TensorRT-LLM

Length of output: 2762


🏁 Script executed:

#!/bin/bash
set -euo pipefail

file="tests/unittest/_torch/visual_gen/multi_gpu/test_wan_transformer_parallel.py"

# Read the file header and the WAN test config definition.
sed -n '1,120p' "$file"
printf '\n---\n'
sed -n '120,210p' "$file"

# Look for the imported model class and whether SimpleNamespace is used elsewhere.
rg -n "SimpleNamespace|WanTransformer3DModel|pretrained_dict|_WAN_TEST_CONFIG|Mapping|dict\[" "$file"

Repository: NVIDIA/TensorRT-LLM

Length of output: 8138


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Get a compact AST-style outline if available, otherwise fall back to text inspection.
ast-grep outline tests/unittest/_torch/visual_gen/multi_gpu/test_wan_transformer_parallel.py --view expanded || true

Repository: NVIDIA/TensorRT-LLM

Length of output: 1866


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
from pathlib import Path
import re

text = Path("tests/unittest/_torch/visual_gen/multi_gpu/test_wan_transformer_parallel.py").read_text()

# Extract the helper definition and nearby imports/assignments for type inference.
for pat in [
    r"from tensorrt_llm\._torch\.visual_gen\.models\.wan\.transformer_wan import WanTransformer3DModel",
    r"from types import SimpleNamespace",
    r"_WAN_TEST_CONFIG\s*=\s*(\{.*?\n\})",
]:
    m = re.search(pat, text, re.S)
    print("MATCH", bool(m), pat)

# Print the imported names block and the config creation block.
for label, start_pat in [("header", "from types import SimpleNamespace"), ("config", "_WAN_TEST_CONFIG")]:
    idx = text.find(start_pat)
    print(f"\n### {label} @ {idx}\n")
    if idx != -1:
        print(text[max(0, idx-400):idx+1200])
PY

Repository: NVIDIA/TensorRT-LLM

Length of output: 3599


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Use sed with line numbers, avoiding nl if unavailable.
file="tests/unittest/_torch/visual_gen/multi_gpu/test_wan_transformer_parallel.py"
awk 'NR>=1 && NR<=120 {printf "%4d  %s\n", NR, $0}' "$file"
printf '\n---\n'
awk 'NR>=120 && NR<=210 {printf "%4d  %s\n", NR, $0}' "$file"

Repository: NVIDIA/TensorRT-LLM

Length of output: 8440


Annotate _copy_ref_weights_to_tp’s parameters. The helper still leaves ref_model, tp_model, and pretrained_config untyped; add concrete model annotations and use a mapping type for pretrained_config instead of relying on implicit Any.

🤖 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/_torch/visual_gen/multi_gpu/test_wan_transformer_parallel.py`
around lines 269 - 270, Update _copy_ref_weights_to_tp by adding concrete
annotations for ref_model and tp_model using their model types, and annotate
pretrained_config with an appropriate mapping type. Preserve the existing return
annotation and implementation behavior.

Source: Coding guidelines

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61368 [ run ] triggered by Bot. Commit: 6ea48e5 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61368 [ run ] completed with state SUCCESS. Commit: 6ea48e5
/LLM/main/L0_MergeRequest_PR pipeline #49595 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

@belgarten-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61445 [ run ] triggered by Bot. Commit: 6ea48e5 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61445 [ run ] completed with state SUCCESS. Commit: 6ea48e5
/LLM/main/L0_MergeRequest_PR pipeline #49669 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants