Skip to content

feat: add t5_split_qkv_append_cache operator package - #2811

Open
Kingsley-Yoimiya wants to merge 2 commits into
xLLM-AI:mainfrom
Kingsley-Yoimiya:feat/t5-qkv-package
Open

Kingsley-Yoimiya wants to merge 2 commits into
xLLM-AI:mainfrom
Kingsley-Yoimiya:feat/t5-qkv-package

Conversation

@Kingsley-Yoimiya

Copy link
Copy Markdown
Collaborator

What

Add the complete ACLNN operator package for T5SplitQkvAppendCache under xllm/core/kernels/npu/xllm_ops/t5_split_qkv_append_cache/, following the task book §5 target and the same delivery shape as row_col_int8_quant.

The package is self-contained (own build.sh, ACLNN project, samples, Python entry, tests and submission materials); it does not modify the engine build.

Contents

Path Content
aclnn/ ACLNN project: OpDef, shape/dtype inference, tiling, Ascend C kernel, two-phase API
op_host/, op_kernel/, include/ Direct-call (kernel launch) build and api.h
examples/ run_aclnn_example / run_example C++ samples
python/ run() ACLNN entry + run_direct() cross-check + baseline
tests/ 35 public accuracy cases, audit/engineering/benchmark/acceptance scripts
public/ Task-provided case.json, golden, generate_data, verify/benchmark/check_performance
docs/ design.md, 任务书.md, 验收对照.md, original-run notes
task_submission/ seven-piece self-verification reports + JSON/logs
artifacts/ built custom_opp_openEuler_aarch64.run
evidence/ final device logs and environment fingerprints
SOURCE_MANIFEST.json, SHA256SUMS.txt source fingerprints and per-file hashes

Operator

Single-token decode: split qkv[B,1,3*H*D] into contiguous query[B,H,1,D], append the current token's K/V to pastKey/pastValue[B,H,L,D] and return key/value[B,H,L+1,D]. FP16/BF16, bit-exact 16-bit copy (±0/Inf/NaN preserved), inputs untouched, outputs disjoint, workspace = 0.

Verification (Ascend910_9382 / CANN 9.1.0 / driver 25.5.t6.b001)

  • 35/35 public cases bit-exact (bit_mismatches=0), plus 12 extra seed/offset inputs, 28 negative scenarios, two-stream / repeated-append / output-lifetime checks.
  • 10/10 performance cases under the fixed limits; e.g. (16,16,2048,64) FP16 = 74.0 us (limit 75), BF16 = 74.4 us (limit 77); small shapes 19.9-22.0 us.
  • Memory: peak active-tensor growth equals output bytes; explicit workspace = 0.
  • Full logs and reports: task_submission/, evidence/.

Reproduce

cd xllm/core/kernels/npu/xllm_ops/t5_split_qkv_append_cache
source /usr/local/Ascend/cann-9.1.0/set_env.sh
python3 tools/build_aclnn.py && bash build.sh
export ASCEND_CUSTOM_OPP_PATH="$(pwd)/aclnn_install/vendors/community_task3$..."
python3 tests/run_tests.py --task-dir tests/task
python3 tests/check_acceptance.py

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T03:28:34.940298Z 5a62145 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 06d9556d50

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

size_t count=0;
~Metadata(){for(auto* t:tensors)if(t)aclDestroyTensor(t);}
void add(const TensorInfo& t){
auto* result=aclCreateTensor(t.sizes.data(),t.rank,t.dtype,t.strides.data(),0,ACL_FORMAT_ND,t.sizes.data(),t.rank,t.data);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reject packed NPU storage before declaring tensors ND

When internal NPU formats are enabled, a logically contiguous tensor produced by torch_npu.npu_format_cast(..., 29) can pass the contiguity checks while retaining FRACTAL_NZ physical storage; xllm/python/kernels_npu/activation.py:46-51 already handles this distinction. This descriptor instead labels every buffer as ND, causing the kernel to interpret packed or padded bytes as ordinary QKV/cache data and silently produce incorrect outputs rather than reject the unsupported layout. Check the actual NPU storage format at the framework boundary, including the run_direct and prepare entry points.

Useful? React with 👍 / 👎.

assert math.isclose(statistics.median(item['wall_us_rounds']),item['wall_us_median'])
custom=r['results']['custom']['wall_us_median'];base=min(v['wall_us_median'] for k,v in r['results'].items() if k!='custom')
ratio=custom/base
assert ratio<=c['max_custom_over_fastest_valid_baseline'],(c['case_name'],ratio,c['max_custom_over_fastest_valid_baseline'])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Enforce fixed latency limits in the full acceptance gate

When absolute latency exceeds the documented target but remains faster than the remeasured baseline, this comparison still passes. The advertised verify_all.sh workflow runs the internal benchmark and this checker at lines 23-24 without invoking the fixed-target checker. In a CPU-only probe, doubling all recorded timing samples and medians still produced a passing acceptance result even though public/check_performance.py rejected all ten cases—for example, case 007 measured 119.1 µs against its 75 µs limit. Apply public/performance_targets.json here, preferably by reusing the public evaluator, so this workflow cannot certify out-of-spec performance.

Useful? React with 👍 / 👎.

@@ -0,0 +1,136 @@
#include "kernel_operator.h"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add the mandatory copyright headers to the new sources

The new handwritten kernel starts directly with an include, and the new bindings and Python implementation similarly omit copyright headers. AGENTS.md makes the shared code-style guide mandatory for files under xllm/, and that guide's File & Header Rules explicitly require a copyright header on every new file. Add the appropriate headers and creation years across the new handwritten sources while preserving existing vendor notices.

AGENTS.md reference: AGENTS.md:L5-L8

Useful? React with 👍 / 👎.

raise ValueError('head attributes must be integers')
return attrs

def run_aclnn(inputs, attributes=None):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Annotate the Python entry points and their helpers

The formal ACLNN entry point has no parameter or return annotations, as do prepare, Prepared.__call__, and the supporting functions. The mandatory Python guide explicitly requires annotations on every function signature, so this newly added public tensor/attribute interface does not meet the repository's documented contract conventions. Annotate the input tensors, optional attributes, returned tensor tuple, and helper signatures rather than leaving the package untyped.

AGENTS.md reference: AGENTS.md:L5-L8

Useful? React with 👍 / 👎.

Add copyright headers to handwritten sources, reject non-ND NPU storage before building ACLNN descriptors, annotate the Python entry points, and enforce the fixed latency limits in the acceptance gate and verify_all.sh.
@Kingsley-Yoimiya

Copy link
Copy Markdown
Collaborator Author

Thanks for the review — all four findings are addressed in 5a62145:

  1. Copyright headers (P1) — added the xLLM Apache header to all 20 handwritten sources (op_host/op_kernel/aclnn/examples/python/tests/tools). Vendor/task-provided files under public/ and tests/task/ keep their original notices.
  2. Non-ND storage (P1) — op_host/aclnn_binding.cpp now rejects any input whose get_npu_format() is not ACL_FORMAT_ND before building the ACLNN descriptors, so FRACTAL_NZ/packed storage fails loudly instead of being read as row-major.
  3. Python annotations (P1) — python/solution.py now annotates every signature (inputs/outputs/attributes/returns), adds from __future__ import annotations, and prefixes the non-public helpers with _.
  4. Fixed latency gate (P2) — tests/check_acceptance.py now loads public/performance_targets.json and asserts each measured median is ≤ its fixed max_wall_us (in addition to the baseline ratio), and verify_all.sh runs public/check_performance.py before the internal gate.

Re-ran the offline gate against the submitted reports: 35/35 accuracy, 10/10 performance with the fixed limits (007 = 74.0 µs ≤ 75, 017 = 74.4 µs ≤ 77), acceptance status passed.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5a6214533c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +76 to +79
std::vector<uint8_t*> pointers;
for (const auto& tensor : in) pointers.push_back(ptr(tensor));
for (const auto& tensor : out) pointers.push_back(ptr(tensor));
for (const auto& tensor : workspace) pointers.push_back(ptr(tensor));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reserve the fixed-size launch pointer vector

Every run_direct invocation appends exactly six pointers to this initially empty vector, introducing avoidable heap reallocations and frees on the host launch path. The mandatory custom-code-style-cpp.md §9 explicitly requires reserving a vector when its final size is known. Reserve the combined input/output/workspace count before these loops, or use a fixed array as the ACLNN binding does.

AGENTS.md reference: AGENTS.md:L5-L8

Useful? React with 👍 / 👎.

Comment on lines +23 to +24
"op_host/aclnn_binding.cpp": "964f5bd04d250bca0e24c834af1c1a3063b94cc6ccca85e70e049c747843d2b8",
"op_host/torch_binding.cpp": "f73980ebba0493e247e13d2d1c10dec928a9b78780d9a88848967f23a60fa5e6",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Refresh the fingerprints for the revised sources

Checking the manifest with hashlib.sha256 shows that 19 of its 35 source hashes disagree with the committed files, including both bindings, the kernels, and python/solution.py. The manifest therefore cannot validate this checkout or establish its correspondence to the bundled test evidence, despite the README's claim that these sources remain byte-identical to the recorded upstream commit. Update the current-source fingerprints and corresponding checksum inventory, while keeping historical upstream and tested-artifact fingerprints explicitly distinguished from the revised implementation.

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant