[Feat] Add csrc/ascend NPU custom ops for GSA#729
Merged
ygwpz merged 28 commits intoModelEngine-Group:developfrom Feb 6, 2026
Merged
[Feat] Add csrc/ascend NPU custom ops for GSA#729ygwpz merged 28 commits intoModelEngine-Group:developfrom
ygwpz merged 28 commits intoModelEngine-Group:developfrom
Conversation
…s and it can generate csrc/ascend/_ucm_ops_custom/vendors/ucm/op_api/lib/libcust_opapi.so
Infinite666
approved these changes
Feb 6, 2026
ygwpz
approved these changes
Feb 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Merge all new Ascend NPU custom ops in
csrc/ascendinto the develop branch. These ops enable GSA on NPU devices by providing:npu_hamming_dist_top_k— Hamming-distance-based top-K for import KV selection (GQA and MLA variants).npu_reshape_and_cache_bnsd— Reshape-and-cache for BNSD (batch × num_heads × seq × dim) layout on NPU.The implementation follows the vLLM-Ascend build system and integrates with an independent Python package
ucm_custom_ops. The usage is as followsModifications
New updated in
ucm/sparse/gsa_on_device/csrc/ascendandtest/sparse/gsatorch_binding.cpp,torch_binding_meta.cpp— Register both ops forPrivateUse1(NPU) with meta implementations for shape inference and graph capture.hamming_dist_top_k/— Full op_host (tiling, split, proto) and op_kernel implementation.reshape_and_cache_bnsd/— op_host and op_kernel for BNSD reshape-and-cache.reshpae_and_cache_bnsdhamming_dist_top_kin GQA modehamming_dist_top_kin MLA modeNPU OPS APIs (summary)
npu_hamming_dist_top_k(hashq, hashkCache, hashkCacheRope, topN, seqLen, chunk_size?, max_seq_len?, sink?, recent?, support_offload?, key_block_table?, mask?, indices?) -> Tensornpu_reshape_and_cache_bnsd(hashq, hashkCache, slot_mapping, seq_len, hashk_cache_out) -> TensorTest
test/gsa/test_reshape_graph.py—test_reshape_and_cache_bnsd,test_reshape_and_cache_bnsd_graphtest/gsa/test_hamming_gqa.py—test_hamming_dist_top_k_graphand eager pathtest/gsa/test_hamming_mla.py—test_hamming_dist_top_k_mla_eager,test_hamming_dist_top_k_mla_graphbash csrc/ascend/build_aclnn.shbuilds the custom op library;install_python_package.shinstalls the wheel. In addition, you should executesource csrc/ascend/_ucm_ops_custom/vendors/ucm/bin/set_env.bashsoimport ucm_custom_opsandtorch.ops._C_ucm.*work on NPU.The screenshots and logs for testing both ops are also attached here.



test_reshape_graph_successful.log
test_hamming_mla_successful.log
test_hamming_gqa_successful.log
In addition, I have run offline inference with the new NPU ops, which has been succesful.
gsaondevice_02051759.log