Skip to content

[None][feat] AutoDeploy: Qwen3.5: Apply whielist based sharding and apply lm_head sharding - #15185

Merged
taylor-yb-lee merged 7 commits into
NVIDIA:mainfrom
nv-auto-deploy:taylor/fix_qwen3.5_acc_new_0607
Jun 13, 2026
Merged

[None][feat] AutoDeploy: Qwen3.5: Apply whielist based sharding and apply lm_head sharding#15185
taylor-yb-lee merged 7 commits into
NVIDIA:mainfrom
nv-auto-deploy:taylor/fix_qwen3.5_acc_new_0607

Conversation

@taylor-yb-lee

@taylor-yb-lee taylor-yb-lee commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

Release Notes

  • Chores

    • Updated Qwen3.5 MoE model registry configuration with expanded sharding control options and explicit transform settings.
  • Refactor

    • Simplified pattern matching for model transformations by streamlining layer-type handling.
    • Enhanced model sharding pipeline with improved scale tensor support for MoE architectures and keyword-based filtering for customized deployment strategies.

Description

History

Test Coverage

  • mmlu: 87.378, gsm8k : 96.209
  • isl 15k/ osl 500/ conc 10 perf restored to 740 tps on B200 x 8 w/ 300 requests

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.

@taylor-yb-lee taylor-yb-lee added the AutoDeploy <NV> AutoDeploy Backend label Jun 10, 2026
@taylor-yb-lee
taylor-yb-lee force-pushed the taylor/fix_qwen3.5_acc_new_0607 branch from 18285ce to 897fa1a Compare June 10, 2026 00:07
@taylor-yb-lee
taylor-yb-lee marked this pull request as ready for review June 10, 2026 00:08
@taylor-yb-lee
taylor-yb-lee requested a review from a team as a code owner June 10, 2026 00:08
@taylor-yb-lee taylor-yb-lee changed the title [None][fix] AutoDeploy: Qwen3.5: Apply whielist based sharding and apply lm_head sharding [None][fix] AutoDeploy: Qwen3.5: Apply whielist based sharding and apply lm_head sharding Jun 10, 2026
@taylor-yb-lee taylor-yb-lee changed the title [None][fix] AutoDeploy: Qwen3.5: Apply whielist based sharding and apply lm_head sharding [None][feat] AutoDeploy: Qwen3.5: Apply whielist based sharding and apply lm_head sharding Jun 10, 2026
@taylor-yb-lee taylor-yb-lee changed the title [None][feat] AutoDeploy: Qwen3.5: Apply whielist based sharding and apply lm_head sharding [None][feat] AutoDeploy: Qwen3.5: Apply whielist based sharding and apply lm_head sharding Jun 10, 2026
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR extends TensorRT-LLM's tensor-parallel sharding system for Qwen 3.5 MoE by introducing a keyword-based simple-shard filter, adding NVFP4 expert weight-scale sharding, simplifying SwiGLU pattern matching, and updating shared-expert layer-type handling in the model.

Changes

Qwen 3.5 MoE IR Sharding & Config

Layer / File(s) Summary
Simple Shard Filter Configuration & Application
tensorrt_llm/_torch/auto_deploy/transform/library/sharding_ir.py, examples/auto_deploy/model_registry/configs/qwen3.5_moe_400b.yaml
IRShardingConfig gained simple_shard_filter field for comma-separated weight-name keywords. YAML config now exposes the option. ApplyShardingHints parses the filter and matches linear nodes during iteration to selectively apply gather-shard logic, independent of shard_layers.
Simple Shard Node Implementation
tensorrt_llm/_torch/auto_deploy/transform/library/sharding_ir.py
_apply_simple_shard refactored to delegate per-node work into _simple_shard_node helper, which column-splits weights/biases, invokes LinearShardableNode._shard_scales for format-aware scale handling, and inserts torch_dist_all_gather to gather-shard the node.
NVFP4 MoE Expert Weight-Scale Sharding
tensorrt_llm/_torch/auto_deploy/transform/library/sharding_ir.py
Imported _tp_shard_moe_scale and extended MoEShardableNode.apply to capture pre-shard W1/W2/W3 shapes when tp_size > 1, partition per-expert *_weight_scale lists by expert-parallel rank, and apply legacy split-dim rules (COLUMN/ROW per weight group).
SwiGLU Fusion Pattern Simplification
tensorrt_llm/_torch/auto_deploy/transform/library/fuse_swiglu.py
Removed preserve_layer_types context manager, _weight_key helper, and contextmanager import. Updated MatchSwiGLUPattern, MatchNVFP4SwiGLUPattern, and MatchFineGrainedFP8SwiGLUPattern to call patterns.apply directly without wrapping.
Shared Expert Layer Type in Qwen Model
tensorrt_llm/_torch/auto_deploy/models/custom/modeling_qwen3_5_moe.py
Qwen3_5MoeMLP.forward removes explicit layer_type="shared_expert" from gate, up, and down projection linear calls to rely on default "unknown" type for replication instead of sharding.

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • NVIDIA/TensorRT-LLM#14793: Modifies sharding_ir.py to fix IR simple_shard path and FP8 scale-sharding behavior in the same module.
  • NVIDIA/TensorRT-LLM#14835: Adds layer_type propagation mechanisms across SwiGLU pattern rewrites; this PR reverses that direction by removing layer-type preservation from fusion.
  • NVIDIA/TensorRT-LLM#14667: Modifies Qwen 3.5 MoE sharding setup (YAML and sharding_ir.py) for TP sharding and NVFP4 scale handling.

Suggested reviewers

  • greg-kwasniewski1
  • galagam
  • suyoggupta
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.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
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.
Title check ✅ Passed The title accurately reflects the main changes: applying whitelist-based sharding and enabling lm_head sharding for Qwen3.5 in AutoDeploy.
Description check ✅ Passed The PR description includes relevant technical context explaining the changes, history, and test coverage metrics, though the format doesn't strictly follow the template structure.

✏️ 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.

@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 (1)
tensorrt_llm/_torch/auto_deploy/transform/library/sharding_ir.py (1)

734-745: ⚡ Quick win

Add strict=True to zip() for defensive programming.

The zip() calls pair EP-partitioned scale nodes with their original weight shapes. While both lists should have identical lengths (both derived from the same EP partition via get_partition), adding strict=True provides fail-fast behavior if a future change introduces a mismatch—rather than silently truncating and producing incorrect sharding.

♻️ Proposed fix
-                for sn, osh in zip(w1_ws_local, w1_orig):
+                for sn, osh in zip(w1_ws_local, w1_orig, strict=True):
                     _tp_shard_moe_scale(
                         gm, sn, "weight_scale", SplitDimension.COLUMN, tp_rank, tp_size, osh
                     )
-                for sn, osh in zip(w3_ws_local, w3_orig):
+                for sn, osh in zip(w3_ws_local, w3_orig, strict=True):
                     _tp_shard_moe_scale(
                         gm, sn, "weight_scale", SplitDimension.COLUMN, tp_rank, tp_size, osh
                     )
-                for sn, osh in zip(w2_ws_local, w2_orig):
+                for sn, osh in zip(w2_ws_local, w2_orig, strict=True):
                     _tp_shard_moe_scale(
                         gm, sn, "weight_scale", SplitDimension.ROW, tp_rank, tp_size, osh
                     )
🤖 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_ir.py` around
lines 734 - 745, The three zip iterations pairing EP-partitioned scale nodes
with original weight shapes (the loops using w1_ws_local/w1_orig,
w3_ws_local/w3_orig, and w2_ws_local/w2_orig that call _tp_shard_moe_scale)
should use zip(..., strict=True) to fail fast on length mismatches; update each
zip invocation to pass strict=True so any future mismatch between the
partitioned lists and original shapes raises an immediate error rather than
silently truncating.

Source: Linters/SAST tools

🤖 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_ir.py`:
- Around line 734-745: The three zip iterations pairing EP-partitioned scale
nodes with original weight shapes (the loops using w1_ws_local/w1_orig,
w3_ws_local/w3_orig, and w2_ws_local/w2_orig that call _tp_shard_moe_scale)
should use zip(..., strict=True) to fail fast on length mismatches; update each
zip invocation to pass strict=True so any future mismatch between the
partitioned lists and original shapes raises an immediate error rather than
silently truncating.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: d642dbe1-4a65-406a-a93e-534b028d8c34

📥 Commits

Reviewing files that changed from the base of the PR and between 9a7f76f and 897fa1a.

📒 Files selected for processing (4)
  • examples/auto_deploy/model_registry/configs/qwen3.5_moe_400b.yaml
  • tensorrt_llm/_torch/auto_deploy/models/custom/modeling_qwen3_5_moe.py
  • tensorrt_llm/_torch/auto_deploy/transform/library/fuse_swiglu.py
  • tensorrt_llm/_torch/auto_deploy/transform/library/sharding_ir.py

@taylor-yb-lee
taylor-yb-lee force-pushed the taylor/fix_qwen3.5_acc_new_0607 branch from 897fa1a to d93311e Compare June 10, 2026 00:19
@taylor-yb-lee

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53228 [ run ] triggered by Bot. Commit: d93311e Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53228 [ run ] completed with state SUCCESS. Commit: d93311e
/LLM/main/L0_MergeRequest_PR pipeline #42423 completed with status: 'SUCCESS'

CI Report

Link to invocation

@taylor-yb-lee

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast --stage-list "DGX_B200-8_GPUs-AutoDeploy-Post-Merge-1"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53401 [ run ] triggered by Bot. Commit: d93311e Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53401 [ run ] completed with state FAILURE. Commit: d93311e
/LLM/main/L0_MergeRequest_PR pipeline #42574 (Partly Tested) 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

@taylor-yb-lee

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast --stage-list "DGX_B200-8_GPUs-AutoDeploy-Post-Merge-1"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53476 [ run ] triggered by Bot. Commit: d93311e Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53476 [ run ] completed with state SUCCESS. Commit: d93311e
/LLM/main/L0_MergeRequest_PR pipeline #42639 (Partly Tested) completed with status: 'SUCCESS'

CI Report

Link to invocation

@taylor-yb-lee

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53621 [ run ] triggered by Bot. Commit: d93311e Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@taylor-yb-lee

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53661 [ run ] triggered by Bot. Commit: d93311e Link to invocation

@taylor-yb-lee
taylor-yb-lee force-pushed the taylor/fix_qwen3.5_acc_new_0607 branch from d93311e to bc2698a Compare June 11, 2026 20:22
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53661 [ run ] completed with state SUCCESS. Commit: d93311e
/LLM/main/L0_MergeRequest_PR pipeline #42802 completed with status: 'SUCCESS'

CI Report

Link to invocation

@taylor-yb-lee

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53681 [ run ] triggered by Bot. Commit: bc2698a Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53681 [ run ] completed with state SUCCESS. Commit: bc2698a
/LLM/main/L0_MergeRequest_PR pipeline #42819 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

- Upstream pattern-matcher now auto-stamps layer_type, so the explicit hooks are dead.
- Drop modeling's layer_type="shared_expert" tag + fuse_swiglu's preserve_layer_types.
- No functional change: shared expert stays replicated (untagged -> excluded by shard_layers).

  shared-expert linear: layer_type="shared_expert"  -->  untagged ("unknown")
       excluded by shard_layers=["moe","delta","mha"] either way -> replicated
  preserve_layer_types ctx-manager (3 sites)         -->  removed (hint auto-stamped)

Signed-off-by: Taylor Yeonbok Lee <249374542+taylor-yb-lee@users.noreply.github.com>
- simple_shard_filter + _simple_shard_node gather-shard lm_head (column split +
  all_gather) instead of replicating the 248320-vocab projection (~3% tput loss).
- yaml: enable the hint-driven IR sharder + simple_shard_filter: "lm_head".

  lm_head:  replicated (V x H per rank)  -->  V/tp x H + all_gather

Signed-off-by: Taylor Yeonbok Lee <249374542+taylor-yb-lee@users.noreply.github.com>
- MoEShardableNode TP-splits NVFP4 per-expert weight_scale (via _tp_shard_moe_scale)
  to follow the weight split (w1/w3 COLUMN, w2 ROW), so moe_tp>1 works for NVFP4
  (was crashing on gemm2_weights_scale dim).

  moe (TP): weight /tp, scale full (crash)  -->  weight AND scale both /tp

Signed-off-by: Taylor Yeonbok Lee <249374542+taylor-yb-lee@users.noreply.github.com>
MoE TP is not used for this deployment (EP-only); revert to keep the PR to a
single concern. The reverted commit stays in history for later cherry-pick.

Signed-off-by: Taylor Yeonbok Lee <249374542+taylor-yb-lee@users.noreply.github.com>
- New AttentionSinksShardableNode splits torch_attention's per-head `sinks`
  param (dim 0, /tp) to follow the q-head column split; the IR sharder
  previously left it full, so rank>0 used the wrong per-head sinks.
- Gating reuses the apply loop: attention-DP skips it (attention replicated),
  shard_layers gates via the node's layer_type="mha". No-op when no sinks.
- Result: gpt-oss-120b TP2 GSM8K 88.48 -> 90.14 (full 1319, ref 90.30).
  Reference torch_attention crashed before; the trtllm kernel tolerated full
  sinks but silently mis-applied them on rank>0.

q/k/v heads: /tp (LinearShardableNode) + head-shrink (ViewShardableNode)  -- already sharded
sinks[num_heads]:  full on every rank  -->  sinks[num_heads/tp]  (head-aligned, this commit)

Signed-off-by: Taylor Yeonbok Lee <249374542+taylor-yb-lee@users.noreply.github.com>
@taylor-yb-lee
taylor-yb-lee force-pushed the taylor/fix_qwen3.5_acc_new_0607 branch from bc2698a to 05cffdd Compare June 12, 2026 08:14
- A row-parallel linear's bias was left full on every rank, so the trailing
  all_reduce summed it world_size times. Keep it on rank 0 (zero elsewhere) so
  the all_reduce contributes it exactly once.
- Needs a dedicated always-apply load hook: the shape-gated _load_hook only
  transforms when the shape changes, so it skips a same-shape zeroing.
- Surfaced by gpt-oss attention bias; fp32 sharding-IR equivalence 0.29 -> 0.000.

row-parallel out + full bias (every rank) --all_reduce--> out + bias*world_size  (was wrong)
row-parallel out + bias on rank 0 only    --all_reduce--> out + bias             (this fix)

Signed-off-by: Taylor Yeonbok Lee <249374542+taylor-yb-lee@users.noreply.github.com>
- _has_ir_markers matched the OpOverloadPacket, but torch.export emits the
  .default overload -> sharding was skipped for every IR family, so the test was
  a silent no-op (compared unsharded vs unsharded). Match both forms.
- Compare in fp32: sharding is dtype-independent math, and bf16 noise (~0.05 on
  attention-heavy models) overlapped the sabotage band.
- Per-family shard_layers (qwen3_5_moe, gpt_oss): default None shards replicate-only
  weights (shared expert / lm_head) and corrupts the output.
- Result: 26 passed / 12 skipped / 0 failed (previously validated nothing).

Signed-off-by: Taylor Yeonbok Lee <249374542+taylor-yb-lee@users.noreply.github.com>
@taylor-yb-lee
taylor-yb-lee force-pushed the taylor/fix_qwen3.5_acc_new_0607 branch from 05cffdd to fe6df82 Compare June 12, 2026 08:28
@taylor-yb-lee

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast --stage-list "DGX_B200-8_GPUs-AutoDeploy-Post-Merge-1"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53946 [ run ] triggered by Bot. Commit: fe6df82 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53946 [ run ] completed with state SUCCESS. Commit: fe6df82
/LLM/main/L0_MergeRequest_PR pipeline #43036 (Partly Tested) completed with status: 'SUCCESS'

CI Report

Link to invocation

@taylor-yb-lee

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53963 [ run ] triggered by Bot. Commit: fe6df82 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

CI Report

Link to invocation

@taylor-yb-lee
taylor-yb-lee merged commit bb32597 into NVIDIA:main Jun 13, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AutoDeploy <NV> AutoDeploy Backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants