Skip to content

Wire Qwen3.5 FP8 linear-attention quant metadata#464

Merged
ingim merged 3 commits into
mainfrom
qwen35-fp8-quantmeta
Jul 6, 2026
Merged

Wire Qwen3.5 FP8 linear-attention quant metadata#464
ingim merged 3 commits into
mainfrom
qwen35-fp8-quantmeta

Conversation

@shsym

@shsym shsym commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Sibling PRs for this ticket:

Summary

  • Carry QuantMeta alongside Qwen3.5 linear-attention projection weights.
  • Pass those weight views into the linear-attention GEMM path so FP8 block scales are available at runtime.
  • Reject TP-sliced FP8 in_proj_qkv for now because slicing the packed tensor without matching scale slices would be unsafe.

Validation

  • python3 driver/cuda/tests/test_qwen35_linear_attn_quantmeta.py

Summary by CodeRabbit

  • New Features

    • Improved support for quantized linear-attention weights in Qwen3.5 CUDA models by propagating quantization metadata through the bind and forward paths.
  • Bug Fixes

    • Prevented unsafe tensor-parallel slicing when FP8 scale metadata would not be preserved.
    • Tightened fusion eligibility to require required quantization metadata to be absent before fusing.
    • Updated linear-attention projection GEMM to use quant-aware weight views, including the output projection.
  • Tests

    • Added CUDA regression tests to verify quantmeta wiring, fusion/slicing behavior, and GEMM weight-view usage.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@shsym, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 27 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6a81b56c-5a83-41ee-9c5a-200a7ac408cb

📥 Commits

Reviewing files that changed from the base of the PR and between ad493de and f274651.

📒 Files selected for processing (1)
  • driver/cuda/tests/test_qwen35_linear_attn_quantmeta.py

Walkthrough

Adds optional FP8 quantization metadata fields for Qwen3.5 linear-attention projection weights, binds that metadata during model loading with fusion and tensor-parallel slicing checks, uses quant-aware weight views in forward GEMM calls, and adds regression tests covering the wiring.

Changes

Qwen3.5 linear-attention quant metadata

Layer / File(s) Summary
QuantMeta fields for linear-attention weights
driver/cuda/src/model/qwen3_5.hpp
Adds five std::optional<QuantMeta> fields to Qwen3_5LayerWeights for the linear-attention projection weights.
Binding quant metadata and fusion/TP guards
driver/cuda/src/model/qwen3_5.cpp
Captures quant_meta for linear-attention projection weights, rejects TP slicing for quantized QKV scales, and only allows fused projection weights when the relevant quant metadata is absent.
Forward GEMM uses quant-aware weight views
driver/cuda/src/model/qwen3_5_forward.cpp
Switches linear-attention GEMM operands to make_weight_view(...) pairs for the in-projection path and out_proj.
Regression tests for quantmeta wiring
driver/cuda/tests/test_qwen35_linear_attn_quantmeta.py
Adds unittest coverage for the new header fields, binder wiring, TP-slicing rejection, and forward weight-view usage.

Related Issues: None referenced.

Related PRs: None referenced.

Suggested labels: cuda, quantization, model-support

Suggested reviewers: None specified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: wiring FP8 quant metadata into Qwen3.5 linear attention.
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
  • Commit unit tests in branch qwen35-fp8-quantmeta

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Comment thread driver/cuda/tests/test_qwen35_linear_attn_quantmeta.py Fixed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
driver/cuda/src/model/qwen3_5.cpp (1)

313-353: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Move the FP8+TP rejection check before the expensive TP slice.

Lw.la_in_proj_qkv_quant and the T > 1 rejection (Lines 345-353) are computed/checked after slice_la_kkv_blocked(*full_qkv, ...) has already allocated a device tensor and issued 3 cudaMemcpys (Lines 323-326). Every TP+FP8 misconfiguration pays for that slice/copy before throwing.

♻️ Proposed reordering
             const int K_dim = cfg.linear_num_key_heads * cfg.linear_key_head_dim;
             const int V_dim = cfg.linear_num_value_heads * cfg.linear_value_head_dim;
+            const auto qkv_quant = engine.quant_meta(la + "in_proj_qkv.weight");
+            if (T > 1 && qkv_quant.has_value()) {
+                throw std::runtime_error(
+                    "qwen3_5: TP-sliced FP8 linear_attn.in_proj_qkv "
+                    "requires matching scale slicing");
+            }
             if (T > 1) {
                 w.owned_bf16_buffers.push_back(
                     slice_la_kkv_blocked(*full_qkv, K_dim, V_dim, rank, T));
                 Lw.la_in_proj_qkv = &w.owned_bf16_buffers.back();
                 ...
             } else {
                 Lw.la_in_proj_qkv = full_qkv;
                 ...
             }
             Lw.la_in_proj_z   = &must(engine, la + "in_proj_z.weight");
             Lw.la_in_proj_b   = &must(engine, la + "in_proj_b.weight");
             Lw.la_in_proj_a   = &must(engine, la + "in_proj_a.weight");
-            Lw.la_in_proj_qkv_quant = engine.quant_meta(la + "in_proj_qkv.weight");
+            Lw.la_in_proj_qkv_quant = qkv_quant;
             Lw.la_in_proj_z_quant   = engine.quant_meta(la + "in_proj_z.weight");
             Lw.la_in_proj_b_quant   = engine.quant_meta(la + "in_proj_b.weight");
             Lw.la_in_proj_a_quant   = engine.quant_meta(la + "in_proj_a.weight");
-            if (T > 1 && Lw.la_in_proj_qkv_quant.has_value()) {
-                throw std::runtime_error(
-                    "qwen3_5: TP-sliced FP8 linear_attn.in_proj_qkv "
-                    "requires matching scale slicing");
-            }
🤖 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 `@driver/cuda/src/model/qwen3_5.cpp` around lines 313 - 353, The FP8+TP
rejection in qwen3_5 model loading is checked too late, after the expensive
tensor-parallel slicing and device copies have already happened. In the
qwen3_5.cpp load path, move the quantization check for Lw.la_in_proj_qkv_quant
and the T > 1 rejection ahead of the slice_la_kkv_blocked calls, so the code
fails fast before allocating buffers or issuing cudaMemcpy work. Keep the logic
near the existing must/maybe tensor lookups and use the same
Lw.la_in_proj_qkv_quant symbol to gate the TP-specific slicing branch.
🤖 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 `@driver/cuda/src/model/qwen3_5.cpp`:
- Around line 313-353: The FP8+TP rejection in qwen3_5 model loading is checked
too late, after the expensive tensor-parallel slicing and device copies have
already happened. In the qwen3_5.cpp load path, move the quantization check for
Lw.la_in_proj_qkv_quant and the T > 1 rejection ahead of the
slice_la_kkv_blocked calls, so the code fails fast before allocating buffers or
issuing cudaMemcpy work. Keep the logic near the existing must/maybe tensor
lookups and use the same Lw.la_in_proj_qkv_quant symbol to gate the TP-specific
slicing branch.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ecca32b5-20e3-41b7-9ab0-3e4f59321dcd

📥 Commits

Reviewing files that changed from the base of the PR and between 317abc1 and d32135b.

📒 Files selected for processing (4)
  • driver/cuda/src/model/qwen3_5.cpp
  • driver/cuda/src/model/qwen3_5.hpp
  • driver/cuda/src/model/qwen3_5_forward.cpp
  • driver/cuda/tests/test_qwen35_linear_attn_quantmeta.py

@ingim ingim merged commit 25ecc03 into main Jul 6, 2026
9 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.

2 participants