[feat] QAD 5090: Wire the Attn-QAT training attention backend (10/12) - #1459
Conversation
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🔴 PR merge requirementsWaiting for
This rule is failing.
|
There was a problem hiding this comment.
Code Review
This pull request introduces support for the ATTN_QAT_TRAIN (fake-quantized attention) backend, updating the attention backend enum, configuration files, and CUDA platform backend loader. The reviewer suggested raising an ImportError instead of silently falling back to Flash Attention when the QAT training kernel is unavailable, to prevent training without fake-quantization.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| elif selected_backend == AttentionBackendEnum.ATTN_QAT_TRAIN: | ||
| from fastvideo.attention.backends.attn_qat_train import ( # noqa: F401 | ||
| AttnQatTrainBackend, is_attn_qat_train_available) | ||
| if is_attn_qat_train_available(): | ||
| logger.info("Using Attn-QAT training (fake-quantized attention) backend.") | ||
| return "fastvideo.attention.backends.attn_qat_train.AttnQatTrainBackend" | ||
| logger.warning("Attn-QAT training kernel is not built; falling back to Flash Attention " | ||
| "(NO fake-quant in the attention path).") |
There was a problem hiding this comment.
Hard-error on missing QAT training kernel
For training, falling back to standard Flash Attention when the QAT kernel is missing is highly risky. QAT (Quantization-Aware Training) introduces fake-quantization noise during the forward and backward passes to prepare the model for low-precision deployment. If it silently falls back, the model will be trained as a standard float16/bfloat16 model, wasting significant compute resources and resulting in a model that cannot be quantized properly.
We should raise an ImportError instead of falling back to Flash Attention when ATTN_QAT_TRAIN is explicitly requested but unavailable. Additionally, we can simplify the import statement by removing the unused AttnQatTrainBackend import.
elif selected_backend == AttentionBackendEnum.ATTN_QAT_TRAIN:
from fastvideo.attention.backends.attn_qat_train import is_attn_qat_train_available
if is_attn_qat_train_available():
logger.info("Using Attn-QAT training (fake-quantized attention) backend.")
return "fastvideo.attention.backends.attn_qat_train.AttnQatTrainBackend"
raise ImportError(
"Attn-QAT training kernel is not built or available. "
"To avoid training without fake-quantization (which defeats the purpose of QAT), "
"please ensure the fastvideo-kernel package is installed and compiled with QAT support."
)Add the fake-quantized attention Triton kernels imported by AttnQatTrainBackend, completing the training-side attention path. With these present, is_attn_qat_train_available() (#1459) returns True and ATTN_QAT_TRAIN performs real fake-quant instead of falling back to Flash Attention. - triton_kernels/attn_qat_train.py: QAT attention fwd/bwd — fake NVFP4 (E2M1) quantization of Q/K/V/P with a straight-through estimator; exports `attention`. - triton_kernels/quant_utils.py + nvfp4_utils.py: NVFP4 fake-quant helpers. - triton_kernels/fused_attention.py: non-QAT Triton reference used by the test. - tests/test_attn_qat_train.py. Verified on a Blackwell node (GB200, sm_100): the full test suite passes — forward/backward, causal/non-causal, varied seq lengths, and a Wan (non-divisible-by-64) shape. QAT output and gradients match the FP32/naive reference at cos~0.98, the gap being the modeled FP4 attention error (the point of QAT). Depends on #1459 (the backend wiring that selects this kernel). Co-authored-by: William Lin <SolitaryThinker@users.noreply.github.com> Co-authored-by: Loay Rashid <42599591+loaydatrain@users.noreply.github.com> Co-authored-by: Kaiqin Kong <k1kong@ucsd.edu>
|
This PR has merge conflicts with the base branch. Please rebase: git fetch origin main
git rebase origin/main
# Resolve any conflicts, then:
git push --force-with-lease |
|
Hi @alexzms — automated review from Gob, one of @SolitaryThinker's AI reviewers. Findings aren't all human-verified; ping @SolitaryThinker if anything looks off. TL;DRI recommend changing the training-side missing-kernel path to hard-error rather than warning and silently falling back, because otherwise a user can think they are QAT-training while actually training the attention path without fake quantization. Separately, this PR currently needs a mechanical rebase against current Verdict: request-changes
Pre-merge gate: rebase requiredPR is currently CONFLICTING with main (the Prior gemini-code-assist concerns (status at
|
| Prior concern | Status at HEAD | Severity now |
|---|---|---|
| Hard-error vs warn+fallback for missing training kernel | ⏸️ PERSISTENT (same question, my recommendation: hard-error) | S2 |
Findings (formatted for upload)
[S2] Training-side fallback should hard-error, not warn+silent-fallback
What: CudaPlatform.get_attn_backend_cls() accepts FASTVIDEO_ATTENTION_BACKEND=ATTN_QAT_TRAIN, checks is_attn_qat_train_available(), and when the Triton kernel is missing logs a warning before dropping through to the normal Flash/SDPA fallback path.
Why it matters: Silent fallback in training means the user thinks they're doing QAT but is actually full-precision-training the attention path. The model weights get shaped by mismatched distributions; the resulting "QAT" checkpoint is a lie — at inference time it gets quantized into a state it was never trained for. Inference (#1457) can defensibly warn+fallback because the user gets a quality regression, not a fundamentally different training run.
Suggested fix: For the ATTN_QAT_TRAIN branch only, raise an ImportError or RuntimeError when is_attn_qat_train_available() is false. Keep the inference branch's warn+fallback behavior unchanged if that remains the intended inference UX.
Evidence: fastvideo/platforms/cuda.py:143-150
— Gob (@SolitaryThinker's AI reviewer). Full review (including S3 items + verification log) is archived locally.
Make AttnQatTrainBackend (deadcode from #1358) selectable for quantization-aware finetuning, mirroring the inference wiring in #1457. The fake-quant-in-backward attention path becomes reachable via FASTVIDEO_ATTENTION_BACKEND=ATTN_QAT_TRAIN. - platforms/interface.py: add ATTN_QAT_TRAIN to AttentionBackendEnum. - platforms/cuda.py: dispatch ATTN_QAT_TRAIN -> AttnQatTrainBackend, guarded by is_attn_qat_train_available(). - attention/backends/attn_qat_train.py: add is_attn_qat_train_available() helper (mirrors is_attn_qat_infer_available()). - configs/models/dits/base.py: add ATTN_QAT_TRAIN to the default supported set. Config-driven, no monkey-patch module swapping. The training Triton kernel (fastvideo_kernel.triton_kernels.attn_qat_train) is not upstreamed yet, so for now selecting ATTN_QAT_TRAIN logs a warning and falls back to Flash Attention until a follow-up lands the kernel. Depends on #1457 (overlaps the enum / dispatch / supported-list files). Co-authored-by: William Lin <SolitaryThinker@users.noreply.github.com> Co-authored-by: Loay Rashid <42599591+loaydatrain@users.noreply.github.com> Co-authored-by: Kaiqin Kong <k1kong@ucsd.edu>
4e8ee63 to
4a09421
Compare
When FASTVIDEO_ATTENTION_BACKEND=ATTN_QAT_TRAIN was selected and the training Triton kernel was not built, the previous code logged a warning and fell through to Flash Attention. That meant a user requesting QAT training silently got non-QAT attention training — the model weights were shaped by mismatched distributions and the resulting "QAT" checkpoint was a lie at inference quantize time. Raise ImportError instead so the user knows immediately to either install the training kernel or pick a different attention backend. The inference-side ATTN_QAT_INFER warn+fallback behavior is preserved verbatim — that case is a quality regression, not a correctness break. Addresses the S2 finding from the PR #1459 gob review. Co-Authored-By: alexzms <26690162+alexzms@users.noreply.github.com>
|
/merge |
Purpose
Continues the Attn-QAT upstreaming stack (#1225). First training-side slice:
makes the
AttnQatTrainBackend(landed as deadcode in #1358) selectable forquantization-aware finetuning, mirroring the inference wiring of #1457. The
fake-quant-in-backward attention path becomes reachable via
FASTVIDEO_ATTENTION_BACKEND=ATTN_QAT_TRAIN.This is config-driven and intentionally avoids the research fork's
monkey-patch module-swapping (
traverse_swap_module/swap_*): main alreadyselects the attention backend from config in both training and inference, so no
training-pipeline change is needed.
Changes
platforms/interface.py: addATTN_QAT_TRAINtoAttentionBackendEnum.platforms/cuda.py: dispatchATTN_QAT_TRAIN→AttnQatTrainBackend, guardedby
is_attn_qat_train_available().attention/backends/attn_qat_train.py: addis_attn_qat_train_available()helper (mirrors
is_attn_qat_infer_available()).configs/models/dits/base.py: addATTN_QAT_TRAINto the default supported set.Test Plan / Test Results
name ↔ enumclosed:AttnQatTrainBackend.get_name() == "ATTN_QAT_TRAIN"isa valid enum member.
get_attn_backend_cls(ATTN_QAT_TRAIN)returns the backendwhen the kernel is available; otherwise warns and falls back to Flash Attention.
Notes
fastvideo_kernel.triton_kernels.attn_qat_trainisnot upstreamed yet, so this is deadcode for now (selecting it falls back to
Flash with a warning). A follow-up will land the kernel.
interface.py/cuda.py/base.py(adjacent enum /dispatch / supported-list lines). Whichever merges second needs a trivial
rebase.
instead of silently falling back (to avoid "fake QAT")? Currently warn+fallback
to match inference.
Part of #1225.