[Fix] fix benchamrk issues and add ub management for npu#1001
Conversation
dad02eb to
5e9673e
Compare
| # copied from https://github.com/linkedin/Liger-Kernel/blob/main/src/liger_kernel/ops/backends/_ascend/ub_manager.py | ||
|
|
|
@zhiyuan1i This pr is ready for review. Thanks! |
zhiyuan1i
left a comment
There was a problem hiding this comment.
LGTM on the NPU changes. Verified the launch chunking math (iter_axis_launch_chunks and the 2D/3D cumsum chunking keep every grid <= 65535 with full coverage) and that the offset/slice patterns are applied correctly across activations / layernorm / rotary / cross_entropy / grpo / cumsum. NPU A2 CI passes.
The red H100 checks (test-models forgetting_transformer TVM tirx.Bind, test-ops test_nsa) are in CUDA code this PR does not touch — test-models is already failing on main (ac6c6483) with the same error, so these are pre-existing / unrelated, not regressions from this PR.
Non-blocking follow-ups for a separate PR: a few unit tests for the new ascend_ub_manager module would be valuable (it's pure Python, easy to test); compute_grid_limited_tile_size has a dead other_grid_product arg worth cleaning up; and the unchunked axes (cross_entropy n_splits, cumsum vector ns) could use a >65535 guard like #997.
Summary
This PR introduces a unified Unified Buffer (UB) management module for the Triton-Ascend backend on Ascend NPUs. It refactors the block size and grid launch strategies of multiple kernels based on this module to resolve launch failures caused by UB overflow and the Ascend hardware grid dimension limit of 65535. In addition, it fixes runtime errors in
benchmark_conv.pyunder the NPU environment, which were triggered by the unavailability of CUDA reference implementations.Key Changes
New File:
fla/utils/ascend_ub_manager.py(+568 lines)UBManager,compute_ub_block_size,compute_vocab_block_size,compute_activation_block_size,compute_row_tile_block_size, etc.ASCEND_MAX_GRID_DIM = 65535,max_grid_axis_chunks, anditer_axis_launch_chunksto enable staged kernel launches on the host side.Triton-Ascend Kernels Integrated with UB Management (8 files modified)
activations.pycompute_activation_block_size; enables backward-pass differentiation via theis_backwardflag; configures a dedicated memory multiplier for PowGLU.layernorm.pyrotary.pyR>=128 → 16; chunks along the NT dimension when grid limits are hit, and adds theNT_OFFSETargument to kernels.fused_cross_entropy.pyROW_OFFSETand chunked kernel launches for both forward and backward passes.fused_linear_cross_entropy.pycompute_elementwise_block_sizefor element-wise multiplication operations.fused_kl_div.pygrpo.pyROW_OFFSETand chunked launches for forward and backward kernels.cumsum.py(BT, BS)block size calculation for scalar/vector local and global cumulative sum operations; supportsNT_OFFSET/BH_OFFSETand multi-dimensional grid chunking.Benchmark Fix (
benchmarks/modules/benchmark_conv.py)causal_conv1d_cuda_*execution providers on NPU devices.line_valsandstylesduring module import.Change Scope
10 files modified, with +1220 new lines and -240 deleted lines.
Motivation
Ascend NPUs have limited UB capacity that varies across different chip models. Previously, all kernels relied on fixed block sizes calculated as
65536 // element_sizeor empirical heuristic values. Such hardcoded configurations frequently caused UB overflow or kernel launch failures when the grid dimension exceeded 65535, especially under large vocabulary sizes, high feature dimensions, or long sequence lengths. This PR consolidates these scattered magic numbers into a centralized UB manager and applies more conservative tiling policies by respecting the peak memory multiplier of forward and backward computation paths.