Skip to content

Gdn qad - #2455

Draft
sychen52 wants to merge 3 commits into
NVIDIA:mainfrom
sychen52:gdn_qad
Draft

Gdn qad#2455
sychen52 wants to merge 3 commits into
NVIDIA:mainfrom
sychen52:gdn_qad

Conversation

@sychen52

@sychen52 sychen52 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: ?

Usage

# Add a code snippet demonstrating how to use this

Testing

Before your PR is "Ready for review"

Make sure you read and follow Contributor guidelines and your commits are signed (git commit -s -S).

Make sure you read and follow the Security Best Practices (e.g. avoiding hardcoded trust_remote_code=True, torch.load(..., weights_only=False), pickle, etc.).

  • Is this change backward compatible?: ✅ / ❌ / N/A
  • If you copied code from any other sources or added a new PIP dependency, did you follow guidance in CONTRIBUTING.md: ✅ / ❌ / N/A
  • Did you write any new necessary tests?: ✅ / ❌ / N/A
  • Did you update Changelog?: ✅ / ❌ / N/A
  • Did you get Claude approval on this PR?: ✅ / ❌ / N/A

Additional Information

Summary by CodeRabbit

  • New Features

    • Added FP8 dynamic fake quantization for GatedDeltaNet recurrent state and weight tensors.
    • Added chunked GatedDeltaNet kernels supporting quantized state processing, variable-length sequences, initial/final states, and gradients.
    • Added quantization plugin integration for supported Megatron GatedDeltaNet workflows.
    • Added ready-to-use PTQ configurations for state and weight quantization.
  • Documentation

    • Documented the new quantization configurations and requirements.
  • Tests

    • Added GPU and unit coverage for quantized kernels, plugins, validation, gradients, and configuration behavior.

Copy fla/ops/common/chunk_delta_h.py (state recurrence kernels) and
fla/ops/gated_delta_rule/chunk.py (autograd wrapper) from
fla-org/flash-linear-attention@516143e31fce into
modelopt/torch/kernels/quantization/linear_attention/ as a base for a
fake-quantized recurrent state. Apart from the license headers and ruff
formatting, the only edit is that the wrapper imports the state kernels
from the vendored sibling module instead of fla; the remaining fla
operators are still imported from the installed package.

Add the MIT copyright holder to LICENSE, exclude the copies from the
license-header hook, and exempt them from docstring lint and strict mypy.

Signed-off-by: Shiyang Chen <shiychen@nvidia.com>
…nked kernel

Add STATE_QDQ to the vendored fla state-recurrence kernel: at the end of
every chunk (and on a provided initial state) the carried fp32 state tiles
are quantized to E4M3 and dequantized with one dynamic scale per [K, BV]
tile of a head, so the next chunk, the per-chunk h buffer and the final
state all see the FP8-rounded state. The backward recomputes the same
quantized states and passes the state gradient straight through. BV is an
explicit launch argument (default 64: two scales per 128-wide head; 128
gives one per head but spills where the kernel is limited to two warps),
so the granularity no longer depends on the autotuner; fla's backend
dispatch is bypassed so no other backend can take a quantized call.

Expose it through a default-disabled gdn_state_quantizer on Megatron-Core
GatedDeltaNet modules (recipe unit configs/ptq/units/gdn_state_fp8_dynamic:
e4m3, dynamic, axis [0, 1]); the quantizer only carries the configuration
and the vendored kernel is imported on first use. Requires
flash-linear-attention >= 0.5.1 and Triton.

CPU unit tests pass; GPU kernel and Megatron tests are added but were not
run here. The kernel compiles offline for sm_90a and sm_100a with the same
register and spill footprint as the unquantized fla kernel.

Signed-off-by: Shiyang Chen <shiychen@nvidia.com>
Let chunk_gated_delta_rule take a callable that fake-quantizes the WY tensor
w ([B, T, HV, K]) once per forward, right after it is materialized and
before it multiplies the state, so the recurrence emulates an FP8 x FP8
matmul against the FP8 state. The backward recompute applies the same
quantizer and the gradient passes straight through. Because w lands in
memory between kernels this needs no Triton change; a ModelOpt
TensorQuantizer (e.g. dynamic per-token E4M3) works as the callable, as
the added GPU test shows.

Signed-off-by: Shiyang Chen <shiychen@nvidia.com>
@sychen52
sychen52 requested review from a team as code owners September 17, 2026 05:19
@sychen52 sychen52 self-assigned this Sep 17, 2026
@sychen52
sychen52 marked this pull request as draft September 17, 2026 05:19
@copy-pr-bot

copy-pr-bot Bot commented Sep 17, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: f63d15dc-09b4-452a-b1c0-719efb8f5ac8

📥 Commits

Reviewing files that changed from the base of the PR and between b9cfdce and 13c7e24.

📒 Files selected for processing (15)
  • .pre-commit-config.yaml
  • LICENSE
  • modelopt/torch/kernels/quantization/linear_attention/__init__.py
  • modelopt/torch/kernels/quantization/linear_attention/fla_chunk_delta_h.py
  • modelopt/torch/kernels/quantization/linear_attention/fla_chunk_gated_delta_rule.py
  • modelopt/torch/quantization/plugins/__init__.py
  • modelopt/torch/quantization/plugins/gated_delta_net.py
  • modelopt/torch/quantization/plugins/megatron.py
  • modelopt_recipes/configs/ptq/units/README.md
  • modelopt_recipes/configs/ptq/units/gdn_state_fp8_dynamic.yaml
  • modelopt_recipes/configs/ptq/units/gdn_w_fp8_dynamic.yaml
  • pyproject.toml
  • tests/gpu/torch/kernels/quantization/linear_attention/test_fla_chunk_gated_delta_rule.py
  • tests/gpu_megatron/torch/quantization/plugins/test_megatron_gated_delta_net.py
  • tests/unit/torch/quantization/plugins/test_gated_delta_net.py

Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.


📝 Walkthrough

Walkthrough

The change adds chunked GatedDeltaNet Triton kernels with optional FP8 fake quantization for recurrent state and WY values. It integrates the kernels with ModelOpt and Megatron, adds PTQ recipes and documentation, and introduces unit and GPU tests.

Changes

GatedDeltaNet FP8 quantization

Layer / File(s) Summary
Chunked kernel implementation
modelopt/torch/kernels/quantization/linear_attention/*
Adds forward and backward Triton kernels, dynamic FP8 state quantization, configurable state tiling, WY quantization, autograd integration, input validation, and public wrappers.
Quantization plugin integration
modelopt/torch/quantization/plugins/*
Adds GatedDeltaNetStateQuantMixin and routes supported Megatron GatedDeltaNet execution through the quantized chunked kernel when quantizers are enabled.
Recipes and repository tooling
modelopt_recipes/configs/ptq/units/*, pyproject.toml, .pre-commit-config.yaml, LICENSE
Adds state and WY FP8 PTQ configurations, documents dependencies, updates vendored-kernel checks, and adds license attribution.
Kernel and plugin validation
tests/gpu/torch/kernels/quantization/linear_attention/*, tests/gpu_megatron/torch/quantization/plugins/*, tests/unit/torch/quantization/plugins/*
Adds coverage for parity, state tiling, variable-length inputs, gradients, quantizer validation, Megatron integration, and enable/disable behavior.

Priority: ⬇️ Low

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

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant MegatronGatedDeltaNet
  participant GatedDeltaNetStateQuantMixin
  participant chunk_gated_delta_rule
  participant fla_chunk_delta_h
  MegatronGatedDeltaNet->>GatedDeltaNetStateQuantMixin: route forward execution
  GatedDeltaNetStateQuantMixin->>chunk_gated_delta_rule: pass state and WY quantizers
  chunk_gated_delta_rule->>fla_chunk_delta_h: dispatch quantized forward kernel
  fla_chunk_delta_h-->>chunk_gated_delta_rule: return outputs and final state
  chunk_gated_delta_rule-->>MegatronGatedDeltaNet: return quantized results
Loading

Merge Risk: ⚪ Minimal · up to 13c7e

No concrete current-head issue remains that should block merging after normal checks.

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 34.15% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 41 functions across 9 files. (6 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 refers to GatedDeltaNet and quantization-aware development, which matches the pull request's main changes. It is concise, but the abbreviations reduce clarity.
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.
Security Anti-Patterns ✅ Passed No listed security anti-pattern is introduced. The changed Python files contain no torch.load, weights_only=False, numpy/np.load with allow_pickle=True, trust_remote_code=True, builtin eval/exec, or #…
Full details: Docstring Coverage

Explanation

Docstring coverage is 34.15% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 41 functions across 9 files. (6 skipped: 6 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@sychen52
sychen52 requested a review from kaix-nv September 17, 2026 05:19
@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 6.24187% with 721 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.71%. Comparing base (6a4b3f1) to head (13c7e24).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
...quantization/linear_attention/fla_chunk_delta_h.py 0.00% 587 Missing ⚠️
...ion/linear_attention/fla_chunk_gated_delta_rule.py 4.54% 126 Missing ⚠️
modelopt/torch/quantization/plugins/megatron.py 66.66% 7 Missing ⚠️
...lopt/torch/quantization/plugins/gated_delta_net.py 96.42% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2455      +/-   ##
==========================================
+ Coverage   71.45%   77.71%   +6.26%     
==========================================
  Files         590      593       +3     
  Lines       64754    66456    +1702     
==========================================
+ Hits        46267    51645    +5378     
+ Misses      18487    14811    -3676     
Flag Coverage Δ
examples-diffusers 20.66% <1.95%> (-0.23%) ⬇️
examples-gpt-oss 13.27% <1.95%> (-0.14%) ⬇️
examples-hf_ptq 22.25% <1.95%> (-0.29%) ⬇️
examples-llm_distill 13.33% <1.95%> (-0.15%) ⬇️
examples-llm_eval 17.20% <1.95%> (-0.19%) ⬇️
examples-llm_qat 17.48% <1.95%> (-0.20%) ⬇️
examples-llm_sparsity 15.77% <1.95%> (-0.18%) ⬇️
examples-megatron_bridge 26.01% <3.90%> (-0.39%) ⬇️
examples-specdec_bench 13.03% <1.95%> (-0.14%) ⬇️
examples-speculative_decoding 17.61% <1.95%> (-0.26%) ⬇️
examples-torch_onnx 21.67% <1.95%> (-0.25%) ⬇️
examples-torch_trt 15.07% <1.95%> (-0.17%) ⬇️
gpu 57.73% <4.94%> (+25.33%) ⬆️
regression 15.01% <1.95%> (+0.14%) ⬆️
unit 57.19% <3.51%> (-0.66%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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