[Ops] Add Triton-Ascend compatibility for GDN-2 - #1213
Conversation
| reason="CUDA/ROCm or Ascend NPU required", | ||
| ) | ||
|
|
||
| _LONG_SEQUENCE = os.environ.get("FLA_GDN2_LONG_SEQUENCE") == "1" |
There was a problem hiding this comment.
Just wondering — is the experimental code in test_gdn2 still not cleaned up? I wouldn't expect the test file to require this many changes.
There was a problem hiding this comment.
Thanks for pointing this out. Initial diff mixed temporary NPU validation code into the canonical GDN2 UT and was broader than necessary. The current change in tests/ops/test_gdn2.py only replaces the CUDA-only skip condition with the repository-level accelerator guard covering NVIDIA, AMD, and Ascend NPU.
|
nit: UT only tests small shapes. It is recommended to add the benchmark to ascend‑a2‑benchmark‑ci.yml to guard functionality and performance under large‑shape scenarios. |
zhiyuan1i
left a comment
There was a problem hiding this comment.
Style issues:
-
P1:
chunk_intra.py:394,398—b_Ai22_c = b_Ai22 + 0.0andb_Ai33_care dead code (never used). -
P1:
chunk_bwd.py:163-165,291andchunk_intra.py:392-402— multiplex_c = x + 0.0copies with no comment. If these are CANN compiler workarounds, each needs a one-line comment saying what it avoids._c/_c2/_c3naming is also uninformative. -
P1:
chunk_bwd.py:54—_launch_dA_finalizeis called only once (line 523). Inline the 25-line launch branch intochunk_gdn2_bwd_wy_dqkg_fused_npu.
Summary
This PR enables the GDN-2 chunk training/prefill path on Ascend NPU through a dedicated Triton-Ascend backend while preserving the existing implementation for non-NPU platforms.
The change:
chunk_gdn2_fwd_intraandchunk_gdn2_bwd_wy_dqkg_fused;chunk_size=64;tests/ops/test_gdn2.pyfile;chunk_gdn2in the unified operator benchmark runner; andtests/ops/test_gdn2.pyto the Ascend A2 CI workflow.Design and implementation
The backend is registered under
fla.ops.gdn2.backendsand is imported lazily by@dispatch('gdn2'). On Ascend, the verifier checks the device, dtype, and fixed 64-token chunk contract before selecting the specialized implementation. On CUDA, ROCm, and other platforms, the Ascend backend is unavailable and dispatch executes the original function body as the semantic fallback.For the forward intra-chunk stage, each 64-token chunk is decomposed into four 16-token sub-blocks. The Ascend kernels build the causal
Aqkand lower-triangularAkkterms, solve the diagonal blocks, and combine the inter-block terms while keeping the live working set within Ascend UB constraints. Host launch helpers split large grids and preserve packed-sequence boundaries for long and variable-length inputs. The backward path separates value/write gradients, the shared key/state gradient structure, GDN-2 erase/gate gradients, and the finaldAtransformation. It reuses the existing Triton-Ascend KDA key-side kernel where the mathematics is shared, while retaining dedicated GDN-2 kernels for its channel-wise gate terms. Hot time-strided inputs use a contiguous time layout where needed, and long-sequence/task offsets use 64-bit address arithmetic.The small changes in the Triton-Ascend KDA gate/backward and shared cumsum launchers only remove CUDA-style
num_warpsarguments that are not valid NPU tuning parameters. They do not change those kernels' public interfaces, mathematics, tiling, or output contracts.Test plan
The 35 nodes include native-reference checks, forward and backward gradients, dense and packed varlen execution, initial/final states, gate-in-kernel modes, GVA, non-power-of-two key dimensions, short-convolution layer coverage, and explicit assertions that the NPU forward and backward calls route through the Triton-Ascend backend.
Benchmark / NCU (kernel changes only)
chunk_gdn2is registered inbenchmarks/ops/registry.pyfor forward and forward+backward timing.A current-code smoke benchmark was run on one
Ascend910_9382device with the runner'sbfloat16inputs,chunk_size=64, anduse_qk_l2norm_in_kernel=True:Median latency:
B1 T64 H1 K32 V32 bf16B8 T1024 H8 K64 V64 bf16There is no numeric upstream-before result because this PR establishes the supported Ascend backend rather than optimizing an existing supported NPU implementation. These short-window measurements verify input generation, warmup, forward, backward, synchronization, and result reporting; they are not a speedup claim. No NCU or formal Ascend profiler comparison is included, and 32K throughput and peak-memory benchmarking remain follow-up performance work. Conclusion: neutral for performance claims; functional Ascend enablement.
Breaking changes
None. There are no public API, checkpoint, tolerance, or intended numerical-behavior changes. The specialized Ascend chunk path requires the existing GDN-2
chunk_size=64contract, andfused_recurrent_gdn2continues to use its existing implementation.Checklist