Repository navigation
Conversation
PR sgl-project#40591's v2 operator takes a pre-planned task list instead of per-call lengths, and AscendAttnBackend plans it once per forward from the whole batch. The DSA indexer query shard hands each attention-TP rank 1/tp of the prefill rows. Each is correct alone; together the operator was told to walk sum(extend_lens) rows through a tensor holding ceil(total / tp_size) of them. 0c64af9 fixed that -- plan from the shard's own lengths, cached on the shard -- but shipped it as a merge resolution with no test. Neither feature's CI can reach the bug: the query shard needs no quant pool and the quant indexer needs no shard, so both suites stay green while the combination reads out of bounds. The kernel reports it as an AICore trap with no Python frame naming either feature. The plan is integer arithmetic, so the invariant tests on CPU: cu_seqlens_q[-1] is how many rows of query the kernel reads, and it must never exceed the rows the caller passed. Asserted over all 180 rank/shape combinations, against the real plan_indexer_query_shard. test_the_batch_wide_plan_would_read_past_the_query_tensor is the control: it builds the plan the pre-fix code built and asserts the overrun, so the file still means something if the two ever agree again. This test belongs with the fix. Both move down to dcp_vllm_port once sgl-project#40591 is in main, since that branch merges second and carries the integration. Co-Authored-By: Claude Opus 5 <[email protected]>
…words it No code change: the comment only. The same eight lines are being upstreamed on their own, off origin/main, as "[NPU] Elide index-K for non-indexer DSA layers on every die, not only 950". The code there is byte-identical to the code here, but the comment was not -- this branch carried a NOTE(dcp-port) aimed at readers who already know what the port is, and the standalone one explains the arch gate to a reviewer who does not. Left alone, that difference would have stopped the merge. When the standalone PR lands and this branch next merges main, git would meet two versions of one comment block over identical code and raise a conflict for a change that is semantically nothing -- at a moment when nobody is looking for one. Same shape as the PR sgl-project#40591 trap: a merge that ought to be a no-op and is not. Matched exactly, so the merge resolves to nothing at all. The ~222 GiB-on-A3 figure the old comment carried is not lost. It is in the standalone commit's message with the measurement behind it (a live pool build at 32,768 tokens: 3.365 GiB dense against 2.918 GiB compact, which is exactly 57 layers x 257 pages x 32,768 B), which is where an upstream reviewer will look for it. Note this branch keeps the elision rather than dropping it: A3 needs it to run, and it lives inside merge commit fe37540, so removing it would mean rewriting merge history for eight lines. Co-Authored-By: Claude Opus 5 <[email protected]>
Merge PR sgl-project#40591 (MXFP8 quant_lightning_indexer v2) onto the DCP branch and fix the one place where the two features disagree. The v2 operator takes cu_seqlens_q / seqused_k / a pre-planned metadata task list, and AscendAttnBackend plans them once per forward from the whole batch. Stage A hands each attention-TP rank 1/attn_tp_size of the prefill query rows. The quant branch read the batch-wide plan and dropped the shard's own lengths, so the operator was told to walk the full batch's token count through a query tensor holding attn_tp_size times fewer rows. Nothing catches that on the host: the lengths are device tensors, so quant_lightning_indexer_tiling.cpp cannot check them against the query shape, and the kernel surfaces the out-of-bounds read as an AICore trap ("timeout or trap error, subErrType 0x4") from inside the operator. - plan cu_seqlens_q / seqused_k / metadata from the shard's lengths when a shard is active, cached on the shard so the other 77 layers reuse it - skip the backend's per-batch pre-plan for sharded extend batches, so a plan that cannot be used is not built - keep the shard's top-k all-gather on the quant path; the PR's structure returned before it - drop the per-layer torch.npu.synchronize() debug leftover Co-Authored-By: Claude Opus 5 <[email protected]>
No textual conflicts. Checked first: sgl-project#37787 came in with the previous merge, and sgl-project#40591 is still not in main (dsa_npu_indexer.py calls the v1 npu_quant_lightning_indexer), so the indexer-shard trap is not live. One semantic break, fixed here: sgl-project#41818 replaced --enable-dp-attention with --attn-dp-size. handle_deprecated_dp_attention now runs first and rewrites the old spelling to attn_dp_size with dp_size=1, so our DCP nesting check in handle_decode_context_parallelism, which still read dp_size and enable_dp_attention, saw attn_dp_size=1 and let a DCP group straddle two DP replicas. It now reads attn_dp_size. Its tests use the new flag. Also renamed cache_unfinished_req to checkpoint in two comments; the partial-page behaviour they describe is unchanged. Local CPU tests: the same failures before and after the merge (11 in test/registered/dcp + test_npu_dcp, 5 in test_server_args); none are new. Co-Authored-By: Claude Opus 5.5 <[email protected]>
No textual conflicts. sgl-project#40591 is still not in main (dsa_npu_indexer.py calls the v1 npu_quant_lightning_indexer), so the indexer-shard trap is not live. Checked the eight files both sides touched. sgl-project#42481 drops make_stages and the _stage_* fields from DeepseekV2DecoderLayer; nothing on this branch uses them. sgl-project#42348's handle_deprecated_dp_attention change still leaves attn_dp_size set before our DCP nesting check reads it. sgl-project#42041's ForwardBatch change is gated on upstream CP metadata, not DCP. Local CPU tests (test/registered/dcp, test_npu_dcp, test_server_args): the same 5 failures before and after the merge; none are new. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1bc7e9e to
555e0b9
Compare
Replaced torch_npu.npu_quant_lightning_indexer() kernel with torch.ops.cann_ops_transformer.quant_lightning_indexer ((version 2 kernel) preceded by torch.ops.cann_ops_transformer.quant_lightninf_indexer_metadata()
578d881 to
446a997
Compare
This comment has been minimized.
This comment has been minimized.
|
Required checks failed on 446a997; this PR cannot be merged until they pass. PR title (run)
Lint (run) |
Motivation
On Ascend NPU, the DSA Lightning Indexer (LI) already runs quantized when the KV cache is FP8, but it quantizes per token (one FP32 scale per token) and calls
torch_npu.npu_quant_lightning_indexer(v1).This PR moves the quantized indexer to MXFP8 (microscaling FP8: one E8M0 scale per 32-element block) and to the v2 kernel from CANN ops-transformer. Block scales lose less accuracy than one scale per token, so the quantized indexer gets faster without the accuracy drop (see results below).
The v2 kernel is two ops:
torch.ops.cann_ops_transformer.quant_lightning_indexer_metadataplans the load balance (a task list) from the batch shape only. That plan is the same for every indexer layer, so it runs once per forward, not once per layer.torch.ops.cann_ops_transformer.quant_lightning_indexerdoes the indexer computation using that plan.MXFP8 (
quant_mode=3) in the v2 kernel is supported on Ascend 950 only.Modifications
hardware_backend/npu/attention/ascend_backend.py_plan_quant_indexer_metadata, called frominit_forward_metadata. It buildscu_seqlens_q(int32, 0-prefixed,(b+1,)),seqused_k(int32,(b,)) and the metadata tensor, and stores all three onForwardMetadatafor every indexer layer to reuse.layers/attention/dsa/dsa_npu_indexer.py_quantize_npu_indexer_activationnow usesnpu_dynamic_mx_quantand returns E8M0 block scales shaped(..., d/64, 2), the descale layout the v2 kernel expects.npu_quant_lightning_indexercall is replaced by the v2quant_lightning_indexercall (layout_kPA_BSND→PA_BBND,cu_seqlens_q/seqused_k/metadataarguments,weightscast to fp32)._check_quant_lightning_indexer_constraints:PA_BBNDrequires a page size in[16, 1024]that is a multiple of 16. A wrong page size now fails with a clear message (use--page-size 64) instead of an error inside the kernel.cann_ops_transformeron NPU so thetorch.ops.cann_ops_transformernamespace is registered.hardware_backend/npu/memory_pool_npu.pyuint8storage, per-token shape(k_n, d/64, 2). Each token still takes 4 bytes per indexer layer, so KV pool capacity does not change.get_index_k_scale_bufferreturns afloat8_e8m0fnuview of that storage.set_index_k_scale_bufferwrites whole per-token scale rows and asserts that the scale is 1 byte per element.mem_cache/pool_host/mla.py(HiCache)Tests
test_npu_ascend_backend.py: per-forward metadata planning for plain extend and decode, int64 → int32 cast, and the CP-extend and disabled cases are skipped.test_npu_quant_lightning_indexer.py(new): page-size constraint check, MX quantization shapes, dtypes, empty input and dequant round-trip, and smoke tests for the metadata op and the full kernel.test_npu_dsa_index_k_scale_pool.py(new): scale-cache layout, E8M0 view, set/get round trip across pages, per-layer slot isolation, and that the HiCache host mirror matches the device pool.Accuracy Tests
GSM-8K, FP (baseline)

GSM-8K, KV/LI MXFP8

Speed Tests and Profiling
Len=256K, FP16

Len=256K, KV/LI MXFP8
