Repository navigation
[GDN] Add FlashQLA backend dispatch - #998
Conversation
zhiyuan1i
left a comment
There was a problem hiding this comment.
Thanks for the PR! The backend dispatch looks clean. A few things to confirm (inline):
| if q.shape[-1] != 128: | ||
| return False, f"FlashQLA requires K=128, got {q.shape[-1]}" | ||
| if v.shape[-1] != 128: | ||
| return False, f"FlashQLA requires V=128, got {v.shape[-1]}" |
There was a problem hiding this comment.
The verifier doesn't check dtype. The default Triton path supports fp32, but flash_qla asserts q.dtype != torch.float32, so with flash_qla installed an fp32 call raises AssertionError instead of falling back to Triton. Should the verifier reject fp32 (and any other unsupported dtype)?
There was a problem hiding this comment.
Thanks, fixed. The verifier now rejects unsupported input dtypes and only dispatches FlashQLA for fp16/bf16 q/k/v with matching dtype; fp32 now falls back to the Triton path.
| ): | ||
| import flash_qla | ||
|
|
||
| return flash_qla.chunk_gated_delta_rule( |
There was a problem hiding this comment.
The default Triton path returns final_state in fp32 (chunk_delta_h.py allocates it as torch.float32), but flash_qla returns it in the input dtype (bf16). This silently changes behavior once the backend is enabled. Is this intended, or should final_state be cast to fp32 to match?
There was a problem hiding this comment.
I checked this again and the returned final_state is already fp32 on my side. Could you point me to the exact case or line where you observed it returning bf16? I may be missing a path, but the current output I see matches the Triton fp32 behavior.
| output_final_state=output_final_state, | ||
| use_qk_l2norm_in_kernel=use_qk_l2norm_in_kernel, | ||
| state_v_first=state_v_first, | ||
| cu_seqlens=cu_seqlens, |
There was a problem hiding this comment.
The PR description mentions intra-card CP for better performance, but auto_cp=True is never passed (FlashQLA defaults it to False), so CP isn't actually active through FLA. Should it be enabled, or should the description be updated?
There was a problem hiding this comment.
Fixed. Now we pass auto_cp=True from the FLA wrapper, and we also updated FlashQLA so intra-card auto CP is enabled by default there as well. The PR description now matches the actual dispatch behavior.
| ) | ||
| def test_flashqla_chunk(B, T, H, D, monkeypatch): | ||
| torch.manual_seed(42) | ||
| dtype = torch.bfloat16 |
There was a problem hiding this comment.
All FlashQLA tests use bf16; fp16 isn't covered. If fp16 is supported, could you add a test? If not, the verifier should reject it.
There was a problem hiding this comment.
Fixed. I added fp16 coverage to the FlashQLA dtype test and kept bf16 coverage as well, so both supported input dtypes now run through fwd/bwd correctness checks.
Thanks for the careful review. We addressed the verifier dtype checks, fp16 test coverage, |
- Rename backend modules to flash_qla.py / flash_kda.py; align backend_type with package_name - Verifier: read use_gate_in_kernel from kwargs (arg order matches the op), reject deprecated transpose_state_layout - Make the verifier rejection test hardware-independent via monkeypatch - Fold dtype/GVA cases into a single parametrized test_flash_qla_chunk
Summary
Add FlashQLA as a backend for
chunk_gated_delta_rule. FlashQLA is a TileLang-based fused forward/backward kernel for the Gated Delta Rule, developed by Qwen Team (Alibaba Cloud). It replaces the multi-kernel Triton path on supported hardware (SM90/SM100), providing both forward and backward pass support including varlen, GVA, andstate_v_first. It also introduce intra-card CP to achieve better performance.Changes:
FlashQLABackendin the GDR backend dispatch system (priority=3)use_gate_in_kernel,use_beta_sigmoid_in_kernel,allow_neg_eigval, inter-card CPIS_NVIDIA_SM100fromfla.utilsfor the compute capability checkstate_v_first, GVA) and verifier rejection testsFiles changed:
fla/ops/gated_delta_rule/backends/__init__.pyFlashQLABackendingdr_registryfla/ops/gated_delta_rule/backends/flashqla.pyFlashQLABackendwith verifier + dispatchfla/ops/gated_delta_rule/chunk.py@dispatch('gated_delta_rule')decoratorfla/utils/_device.pyIS_NVIDIA_SM100fla/utils/__init__.pyIS_NVIDIA_SM100tests/ops/test_gdn.pyTest plan
test_flashqla_chunk— dense fwd+bwd, 3 configs (B/T/H vary, D=128), ratio ≤ 0.008test_flashqla_chunk_varlen— variable-length sequences, 3 cu_seqlens configstest_flashqla_chunk_state_v_first—state_v_first=TruevsFalse, bit-exact (ratio=0)test_flashqla_chunk_gva— grouped value attention (H<HV), 2 configstest_flashqla_verifier_rejects— all 6 rejection branches + acceptance pathNote
flash_qlapackage (QwenLM/FlashQLA). Tests skip gracefully when the package is not installed.FLA_FLASH_QLA=0.