Skip to content

Commit 4584403

Browse files
committed
[feat] QAD 5090: Wire the Attn-QAT training attention backend (10/12)
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).
1 parent 633d393 commit 4584403

4 files changed

Lines changed: 15 additions & 1 deletion

File tree

fastvideo/attention/backends/attn_qat_train.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ def _get_attn_qat_train_attention() -> Callable[..., torch.Tensor] | None:
4949
return _attn_qat_train_attention
5050

5151

52+
def is_attn_qat_train_available() -> bool:
53+
return _get_attn_qat_train_attention() is not None
54+
55+
5256
def attn_qat_train(q_BLHD: torch.Tensor,
5357
k_BLHD: torch.Tensor,
5458
v_BLHD: torch.Tensor,

fastvideo/configs/models/dits/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class DiTArchConfig(ArchConfig):
2424
AttentionBackendEnum.TORCH_SDPA,
2525
AttentionBackendEnum.VIDEO_SPARSE_ATTN,
2626
AttentionBackendEnum.VMOBA_ATTN, AttentionBackendEnum.SAGE_ATTN_THREE,
27-
AttentionBackendEnum.SLA_ATTN, AttentionBackendEnum.SAGE_SLA_ATTN)
27+
AttentionBackendEnum.ATTN_QAT_TRAIN, AttentionBackendEnum.SLA_ATTN,
28+
AttentionBackendEnum.SAGE_SLA_ATTN)
2829

2930
hidden_size: int = 0
3031
num_attention_heads: int = 0

fastvideo/platforms/cuda.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ def get_attn_backend_cls(cls, selected_backend: AttentionBackendEnum | None, hea
140140
except ImportError as e:
141141
logger.info(e)
142142
logger.info("Sage Attention 3 backend is not installed. Fall back to Flash Attention.")
143+
elif selected_backend == AttentionBackendEnum.ATTN_QAT_TRAIN:
144+
from fastvideo.attention.backends.attn_qat_train import ( # noqa: F401
145+
AttnQatTrainBackend, is_attn_qat_train_available)
146+
if is_attn_qat_train_available():
147+
logger.info("Using Attn-QAT training (fake-quantized attention) backend.")
148+
return "fastvideo.attention.backends.attn_qat_train.AttnQatTrainBackend"
149+
logger.warning("Attn-QAT training kernel is not built; falling back to Flash Attention "
150+
"(NO fake-quant in the attention path).")
143151
elif selected_backend == AttentionBackendEnum.VIDEO_SPARSE_ATTN:
144152
try:
145153
from fastvideo_kernel import video_sparse_attn # noqa: F401

fastvideo/platforms/interface.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class AttentionBackendEnum(enum.Enum):
1515
TORCH_SDPA = enum.auto()
1616
SAGE_ATTN = enum.auto()
1717
SAGE_ATTN_THREE = enum.auto()
18+
ATTN_QAT_TRAIN = enum.auto()
1819
VIDEO_SPARSE_ATTN = enum.auto()
1920
BSA_ATTN = enum.auto()
2021
VMOBA_ATTN = enum.auto()

0 commit comments

Comments
 (0)