Skip to content

Precompile Mamba NAS kernels before functional checks - #2572

Draft
kaix-nv wants to merge 1 commit into
mainfrom
kaix/linear-attention-ci-cleanup
Draft

kaix-nv wants to merge 1 commit into
mainfrom
kaix/linear-attention-ci-cleanup

Conversation

@kaix-nv

@kaix-nv kaix-nv commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: new tests, bug fix

Separate Mamba NAS kernel compilation from the functional test's 120-second budget. A dedicated compilation test runs first in the same module, sharing its distributed worker pool with the functional test. Both paths use the same tiny model and min/max/centroid plus exported-model inference helper; the functional test retains its 13 assertions. Only the compilation test gets the existing extension-test convention of a 240-second timeout.

The Diffusers workflow timeout increase has been dropped. The independent optional-httpx collection fix is retained: streaming-dataset tests skip when that optional package is unavailable.

These CI changes are kept separate from linear-attention PR #2497. This implements the testing structure requested in #2497 (comment) and the revert requested in #2497 (comment). A local cold/warm GPU run verifies that the compilation test warms the functional path. It does not establish the cause of the historical CI timeout.

Usage

Run the full module, or select both the compilation and functional tests:

PYTHONPATH=. python -m pytest -q \
  tests/gpu_megatron/torch/nas/plugins/test_megatron_hybrid_dynamic_modules.py \
  -k 'mamba_kernel_compilation or mamba_search_space' --durations=0

Default pytest source ordering places compilation first. Selecting only test_mamba_search_space does not run the warmup; it still keeps the normal 120-second limit. The CI lane runs the entire module and does not use xdist.

Testing

  • Pre-commit checks: passed.

  • Python syntax, source declaration order, compilation-only timeout marker, retained assertion count, exact workflow restoration, and git diff --check: passed.

  • Current published commit 5ff632784e4f7a10e3eff4d944e3a86136ac14b4: both cold and warm GPU runs passed (2 passed / 2 deselected each) on two RTX A6000 GPUs using PP=2.

    Test call Cold Triton cache Warm Triton cache Timeout
    Mamba compilation 97.05s 16.62s 240s
    Functional search-space test 0.20s 0.21s 120s
  • Local environment: Python 3.12.8, PyTorch 2.9.1+cu128, Triton 3.5.1, Megatron Core 0.19.2, Transformer Engine 2.16.0 (PyTorch extension built locally), Mamba SSM 2.3.2.post1. The cold run used a fresh Triton cache; unchanged ModelOpt C++/CUDA extensions were prebuilt in session setup and reused. The warm repeat used the same caches in a new pytest process.

  • Initial local attempt with Megatron Core 0.18.2 failed before inference because its Mamba mixer lacks the raw convolution parameters expected by this checkout. Upgrading only the isolated Megatron package to 0.19.2 resolved that environment mismatch; no repository source was changed for it. Failed-attempt logs are retained.

  • These local results do not replace the NeMo 26.08 CI image/hardware run. Full CI remains separate.

  • The unchanged optional-httpx edit was previously validated with 18 streaming-dataset tests passing and a clean module skip when httpx was unavailable. Those results predate this amendment; the GPU warmup requires its own runtime validation.

Before your PR is "Ready for review"

  • Backward compatible: yes; test-only changes.
  • Third-party copying/new dependencies: N/A.
  • New necessary tests: yes; dedicated Mamba compilation test; cold/warm local GPU validation passed.
  • Changelog: N/A; test-only changes.
  • Claude approval: pending.

Signed-off-by: Kai Xu <kaix@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Sep 28, 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 28, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

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

@codecov

codecov Bot commented Sep 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.25%. Comparing base (051d6ad) to head (5ff6327).
⚠️ Report is 23 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2572      +/-   ##
==========================================
+ Coverage   71.14%   71.25%   +0.10%     
==========================================
  Files         603      608       +5     
  Lines       66739    70880    +4141     
==========================================
+ Hits        47482    50506    +3024     
- Misses      19257    20374    +1117     
Flag Coverage Δ
unit 58.93% <ø> (+0.72%) ⬆️

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.

kaix-nv added a commit that referenced this pull request Oct 2, 2026
<!-- linear-attention-stack:start -->
**Linear-attention PR stack — 6 PRs**

| Order | PR | Depends on |
| --- | --- | --- |
| 1/6 | [#2497 GDN state/W QAT
foundation](#2497) | main
|
| 2/6 | [#2519 Torch GDN/KDA decode QAT +
INT8](#2519) | #2497 |
| 3/6 | [#2562 Fused Triton GDN/KDA decode
QAT](#2562) | #2519 |
| 4/6 | [#2541 vLLM GDN/KDA state-only fake
quantization](#2541) |
#2562 |
| 5/6 | [#2503 GDN/KDA prefill GEMM
quantization](#2503) |
#2541 |
| 6/6 | [#2507 Experimental GDN/KDA approximate
inverse](#2507) | #2503 |

All six PRs form native GitHub stack #2563 in the order shown above.
#2541 applies TensorQuantizer before native vLLM prefill/decode calls. A
separate vLLM prefill-GEMM PR waits for an optimized fused kernel. #2506
and #2509 are superseded and closed.
<!-- linear-attention-stack:end -->

### What does this PR do?

Type of change: new feature

GatedDeltaNet training keeps recurrent states inside a chunked kernel,
so projection quantizers cannot emulate rounding at state boundaries.
This PR adds dynamic per-tile FP8 E4M3 fake QDQ to the recurrent state
and independent dynamic FP8 fake QDQ to WY-transformed W activations,
with identity straight-through gradients for QAT/QAD.

Both sites use the standard `quant_cfg` interface and start disabled.
State QDQ uses 64-token chunks and recomputes `amax` at each boundary
over each full-key by 64-value-column tile, independently per sequence
and head. Each tile has its own scalar scale (`amax / 448`, with a zero
guard); `fp8_scalar_qdq` applies that supplied scale rather than
choosing tensor-wide grouping. W grouping is applied by
`TensorQuantizer`. Quantizer settings use normal ModelOpt checkpoint
state. There is no `QuantizeConfig.linear_attention` field in this PR;
#2519 introduces execution policies for decode and ReplaySSM, and later
PRs extend them for prefill and approximate inverse. Configurations or
checkpoints from earlier experimental drafts that use those execution
policies require #2519; those selecting Triton decode also require
#2562.

The Megatron adapter supports the direct-forward and older split-forward
call layouts, restores the original kernel when disabled, and removes
temporary quantizer attributes on export. Independent recurrent/chunk
numerical references live under `tests/_test_utils/torch/quantization/`;
shared runtime capability checks live in `linear_attention/utils.py`.

The fused path requires `fla-core==0.5.1` and chunk size 64. State FP8
emulation requires SM89 or newer. The Hopper path has additional
dtype/TileLang restrictions enforced before launch. This PR simulates
numerical error; it does not add compressed state storage or faster
inference.

### Usage

```python
import modelopt.torch.quantization as mtq

model = mtq.quantize(model, {
    "quant_cfg": [
        {"quantizer_name": "*", "enable": False},
        {"quantizer_name": "*gdn_state_quantizer",
         "cfg": {"num_bits": (4, 3), "type": "dynamic", "axis": (0, 1)}},
        {"quantizer_name": "*gdn_w_quantizer",
         "cfg": {"num_bits": (4, 3), "type": "dynamic", "axis": (0, 1, 2)}},
    ],
    "algorithm": None,
})
# Continue with the framework's normal forward/backward/optimizer steps.
```

Dynamic scales require no calibration.

### Testing

The focused GPU suite contains four cases: three BF16 numerical
forward/backward checks (disabled, W QDQ, and state+W QDQ) using one
shared shape, plus one single-rank, one-layer Megatron QAT/checkpoint
test. The Megatron test checks quantizer enable/disable behavior,
checkpoint restore, gradients, and an optimizer update; it enables state
QDQ when the GPU supports native FP8 conversion. Compilation runs in
setup fixtures, and functional calls retain the normal 120-second
timeout. There are no dtype, layout, tile-width, or parallelism sweeps.

The pinned FLA/TileLang/TVM-FFI dependencies live in the `dev-fla`
optional extra, installed by both GPU nox sessions.

Validation of the consolidated changes on RTX A6000 (SM86), Python
3.12.8, Torch 2.9.1+cu128, Triton 3.5.1, fla-core 0.5.1, TileLang 0.1.8,
Megatron Core 0.19.2, and Transformer Engine 2.16.0:

- Cold and warm focused runs: **3 passed, 1 hardware skip** each. The
state+W numerical case requires SM89+; the local Megatron test exercised
W QDQ.
- Fresh Triton/TileLang cache: **363.09s total**, including setup and
teardown. Kernel setup took 66.38s + 44.46s; Megatron setup, including
shared extension setup and worker startup, took 245.26s. Functional
calls totaled about 2.56s.
- Same cache, new pytest process: **38.20s total**, with about **2.41s
in functional calls**.
- Pre-commit checks passed for the four changed files. Dependency-group
wiring and installed pinned versions were checked.

```bash
PYTHONPATH=. python -m pytest -q \
  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 \
  --durations=0
```

These timings describe local test setup and execution, not inference
performance. Native FP8 state QDQ and Hopper still require suitable
GPU/CI runs. This minimal suite does not qualify tensor/context/pipeline
parallelism, checkpoint resharding, or model-quality recovery. Mamba
compilation coverage is tracked separately in #2572.

### Before your PR is "*Ready for review*"

Contributor and security guidance reviewed. Commits are signed and
signed off.

- Is this change backward compatible?: ✅ Disabled-by-default quantizers,
standard-recipe exclusions, and legacy-checkpoint coverage; enabled
experimental configurations have explicit capability restrictions.
- If you copied code from any other sources or added a new PIP
dependency, did you follow guidance in `CONTRIBUTING.md`: ❌ Internal
third-party approval tracking still needs confirmation. Upstream
attribution, MIT/Apache headers, `LICENSE` notice, and license-hook
exclusions are included. FLA/TileLang and TVM-FFI license files were
reviewed.
- Did you write any new necessary tests?: ✅ Numerical, gradient,
conversion/checkpoint, and real framework tests.
- Did you update Changelog?: ✅ Experimental quantization feature entry.
- Did you get Claude approval on this PR?: ❌ Bot feedback addressed or
discussed; renewed approval pending.

### Additional Information

Related: #2455. This is the first integration slice and does not assume
#2455 has merged. Later milestones will extend the numerical boundaries
after choosing their approximation contracts.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added experimental dynamic FP8 fake quantization for GatedDeltaNet
recurrent states and WY activations during training.
* Added PTQ configuration options for state and WY activation
quantization. State quantization requires an SM89-or-newer GPU; the
fused path requires `fla-core==0.5.1` and a chunk size of 64.
* **Bug Fixes**
* Improved quantizer configuration validation and restoration for
linear-attention models.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Kai Xu <kaix@nvidia.com>

This branch has not been deployed

No deployments
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.

1 participant