Skip to content

[TRTLLM-14497][feat] Add BF16/FP8 refit for qwen3.5_397b - #16642

Merged
hchings merged 7 commits into
NVIDIA:mainfrom
hchings:qwen_3.5_397b_refit
Jul 31, 2026
Merged

hchings merged 7 commits into
NVIDIA:mainfrom
hchings:qwen_3.5_397b_refit

Conversation

@hchings

@hchings hchings commented Jul 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added support for incremental and partial weight updates for Qwen3.5 models, including vision-language and MoE variants.
    • Supports BF16 and FP8 checkpoint updates, with improved handling of staged projection weights and scaling data.
    • Added safer update-session controls to finalize or discard incomplete updates.
  • Bug Fixes

    • Improved reliability for GPU kernels when tensor memory alignment is unsuitable.
    • Corrected weight loading behavior for supplied model configurations and multimodal checkpoints.
  • Tests

    • Added coverage for partial loading and multi-GPU weight updates.

This change enables incremental BF16 weight refit for the Qwen3.5-397B rollout model.
NeMo-RL transfers a model update through multiple size-bounded buckets, so related Gated
DeltaNet projections_Q/K/V/Z and B/A_may arrive in separate reload() calls. Qwen3.5 must
retain incomplete projection groups across calls, fuse them only when complete, and
validate the complete update before post-load transformations run. The implementation
introduces explicit begin/finalize/abort lifecycle boundaries and preserves in-place
parameter storage required by CUDA Graph replay.

The model-specific behavior is isolated to Qwen3_5MoeHfWeightMapper. The MLPerf 397B
model is currently the only model requiring this cross-bucket staging because of its
Qwen3.5 Gated DeltaNet projection layout and BF16 MoE representation. Other weight
mappers inherit no-op lifecycle methods, so their successful loading and refit behavior
is unchanged. The generic RLHF worker owns the lifecycle calls because only the transport
layer knows the first bucket, finalization boundary, and failure boundary; placing a
397B-specific type check there would couple generic update infrastructure to one model.

The change also fixes a TP8 alignment issue for a small GDN tensor view that can begin on
a 16-byte boundary on odd TP shards, while the CuTe kernel requires 32-byte alignment.
Aligned configurations retain the existing zero-copy path.

Validation covers reduced-depth, production-width Qwen3.5-397B BF16 refit with warm CUDA-
graph execution and post-refit Hugging Face reference-logit comparison:

  • TP4 one-shot refit
  • TP4 incremental/partial refit
  • Two-node TP8 one-shot refit (Not committed due to multi-node)
  • Two-node TP8 incremental/partial refit (Not committed due to multi-node)

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)

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

@hchings hchings self-assigned this Jul 20, 2026
@hchings hchings changed the title bf16 refit for qwen3.5_397b [TRTLLM-14497][feat]Add refit for qwen3.5_397b Jul 20, 2026
@hchings
hchings requested a review from shuyixiong July 21, 2026 04:22
@hchings hchings changed the title [TRTLLM-14497][feat]Add refit for qwen3.5_397b [TRTLLM-14497][feat]Add BF16/FP8 refit for qwen3.5_397b Jul 22, 2026
@hchings
hchings marked this pull request as ready for review July 22, 2026 21:57
@hchings
hchings requested review from a team as code owners July 22, 2026 21:57
@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Changes

Partial weight updates

Layer / File(s) Summary
Update lifecycle orchestration
tensorrt_llm/_torch/models/checkpoints/base_weight_mapper.py, tensorrt_llm/_torch/pyexecutor/model_loader.py, tensorrt_llm/llmapi/rlhf_utils.py
Adds begin, finalize, and abort hooks and invokes them around worker weight reload operations.
Qwen partial-loading implementation
tensorrt_llm/_torch/models/checkpoints/hf/*, tensorrt_llm/_torch/models/modeling_qwen3*
Stages split QKVZ/BA projections, updates expert tensor detection, and propagates partial-loading flags through Qwen model loaders.
Partial-loading validation
tests/unittest/_torch/modeling/test_qwen3_5_partial_loading.py, tests/unittest/_torch/ray_orchestrator/multi_gpu/test_llm_update_weights_multi_gpu.py
Adds unit coverage for FP8/BF16 staging and multi-GPU BF16/FP8 Qwen3.5 refit flows.

Kernel input alignment

Layer / File(s) Summary
FlashInfer alignment guard
tensorrt_llm/_torch/modules/fla/fused_sigmoid_gating_recurrent.py
Clones a_bat when its address is not 32-byte aligned before kernel dispatch.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant WorkerExtension
  participant ModelLoader
  participant Qwen3_5MoeHfWeightMapper
  participant Qwen3_5VLModel
  WorkerExtension->>ModelLoader: begin_update_weights()
  WorkerExtension->>Qwen3_5VLModel: load_weights(..., allow_partial_loading=True)
  Qwen3_5VLModel->>Qwen3_5MoeHfWeightMapper: preprocess_weights(..., allow_partial_loading=True)
  Qwen3_5MoeHfWeightMapper->>Qwen3_5MoeHfWeightMapper: stage split projection tensors
  WorkerExtension->>ModelLoader: finalize_update_weights()
Loading

Suggested labels: api-compatible

Suggested reviewers: shuyixiong

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

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.
✅ 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 is concise and accurately summarizes the main change: BF16/FP8 refit support for Qwen3.5-397B.
Description check ✅ Passed The PR describes the issue, solution, and validation coverage with the required sections present, though the template is only partially filled.
✨ 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 (1)
tests/unittest/_torch/modeling/test_qwen3_5_partial_loading.py (1)

66-113: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Coverage looks solid for the ready/waiting staging paths. Optional follow-up: add a small case asserting finalize_update_weights() raises RuntimeError when a group is left incomplete (e.g., only qkv.weight staged), and one for the duplicate-weight RuntimeError path in _stage_partial_split_projections, to lock in the error contracts.

As per path instructions (act as a QA engineer reviewing test changes and coverage), current coverage is sufficient for the happy paths but the negative/error paths of the new lifecycle are untested.

🤖 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/modeling/test_qwen3_5_partial_loading.py` around lines
66 - 113, Add negative-path tests for the partial projection lifecycle: verify
finalize_update_weights() raises RuntimeError when only qkv.weight is staged,
and verify _stage_partial_split_projections raises RuntimeError when a duplicate
weight is staged. Keep the existing ready/waiting coverage unchanged and assert
the documented error contracts.

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 `@tests/unittest/_torch/modeling/test_qwen3_5_partial_loading.py`:
- Around line 66-113: Add negative-path tests for the partial projection
lifecycle: verify finalize_update_weights() raises RuntimeError when only
qkv.weight is staged, and verify _stage_partial_split_projections raises
RuntimeError when a duplicate weight is staged. Keep the existing ready/waiting
coverage unchanged and assert the documented error contracts.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 16c13fb3-a4f4-4131-b593-5de6af450abe

📥 Commits

Reviewing files that changed from the base of the PR and between 5d790a0 and 983e7ff.

📒 Files selected for processing (11)
  • tensorrt_llm/_torch/models/checkpoints/base_weight_mapper.py
  • tensorrt_llm/_torch/models/checkpoints/hf/qwen3_5_weight_mapper.py
  • tensorrt_llm/_torch/models/checkpoints/hf/qwen3_next_weight_mapper.py
  • tensorrt_llm/_torch/models/modeling_qwen3_5.py
  • tensorrt_llm/_torch/models/modeling_qwen3_next.py
  • tensorrt_llm/_torch/models/modeling_qwen3vl.py
  • tensorrt_llm/_torch/modules/fla/fused_sigmoid_gating_recurrent.py
  • tensorrt_llm/_torch/pyexecutor/model_loader.py
  • tensorrt_llm/llmapi/rlhf_utils.py
  • tests/unittest/_torch/modeling/test_qwen3_5_partial_loading.py
  • tests/unittest/_torch/ray_orchestrator/multi_gpu/test_llm_update_weights_multi_gpu.py

Comment thread tensorrt_llm/llmapi/rlhf_utils.py Resolved
@hchings
hchings force-pushed the qwen_3.5_397b_refit branch from 983e7ff to 328b49b Compare July 25, 2026 21:21
@hchings
hchings requested a review from a team as a code owner July 25, 2026 21:21
@hchings
hchings requested review from BowenFu and schetlur-nv July 25, 2026 21:21
@hchings
hchings force-pushed the qwen_3.5_397b_refit branch from 328b49b to 2364c76 Compare July 27, 2026 22:34
@hchings
hchings requested review from a team as code owners July 28, 2026 22:08
@hchings
hchings requested review from tburt-nv and yuanjingx87 July 28, 2026 22:08
@pcastonguay pcastonguay added the ci: post-merge approved Approved by TRT-LLM CI approvers for broad post-merge CI requests label Jul 28, 2026
@hchings hchings changed the title [TRTLLM-14497][feat]Add BF16/FP8 refit for qwen3.5_397b [TRTLLM-14497][feat] Add BF16/FP8 refit for qwen3.5_397b Jul 28, 2026
@hchings
hchings enabled auto-merge (squash) July 28, 2026 23:00
@hchings

hchings commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62581 [ run ] triggered by Bot. Commit: 0f6ab1e Link to invocation

@hchings

hchings commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

/bot kill

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62587 [ kill ] triggered by Bot. Commit: 0f6ab1e Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github/16642-0f6ab1e #62581 was force-killed by a newer pipeline run.
L0 job information not available (job may not have been triggered yet).

Link to superseding invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62587 [ kill ] completed with state SUCCESS. Commit: 0f6ab1e
Successfully killed previous jobs for commit 0f6ab1e

Link to invocation

@dpitman-nvda dpitman-nvda 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.

Approval for infra

@hchings
hchings requested a review from a team as a code owner July 29, 2026 23:19
@hchings

hchings commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62624 [ run ] triggered by Bot. Commit: a57b321 Link to invocation

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

Reviewed the current head. The incremental refit lifecycle and Qwen3.5 BF16/FP8 checkpoint paths look sound for the targeted MLPerf workflow.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@shuyixiong

Copy link
Copy Markdown
Collaborator

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62778 [ run ] triggered by Bot. Commit: a57b321 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@hchings

hchings commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #63081 [ run ] triggered by Bot. Commit: a57b321 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #63082 [ run ] triggered by Bot. Commit: a57b321 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #63081 [ run ] completed with state ABORTED. Commit: a57b321

Link to invocation

@hchings

hchings commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #63087 [ run ] triggered by Bot. Commit: a57b321 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #63082 [ run ] completed with state ABORTED. Commit: a57b321

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #63087 [ run ] completed with state SUCCESS. Commit: a57b321
/LLM/main/L0_MergeRequest_PR pipeline #51178 completed with status: 'SUCCESS'

CI Report

Link to invocation

@hchings
hchings merged commit 1c797cf into NVIDIA:main Jul 31, 2026
5 of 6 checks passed
yuanjingx87 pushed a commit that referenced this pull request Aug 1, 2026
@hchings
hchings deleted the qwen_3.5_397b_refit branch August 3, 2026 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci: post-merge approved Approved by TRT-LLM CI approvers for broad post-merge CI requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants