-
Notifications
You must be signed in to change notification settings - Fork 50
Perf: fuse DSv4-flash indexer score scope, pack SWA output store #831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,3 @@ | ||||||||||||||||||||||||||||||
| # Copyright (c) PyPTO Contributors. | ||||||||||||||||||||||||||||||
| # This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||||||||||||||||||||||||||||||
| # CANN Open Software License Agreement Version 2.0 (the "License"). | ||||||||||||||||||||||||||||||
|
|
@@ -457,8 +457,10 @@ | |||||||||||||||||||||||||||||
| n_hh = n_gh - n_g * HEADS_PER_GROUP | ||||||||||||||||||||||||||||||
| n_pack_row = n_g * T + m_t | ||||||||||||||||||||||||||||||
| n_col = n_hh * HEAD_DIM | ||||||||||||||||||||||||||||||
| o_packed[n_pack_row : n_pack_row + 1, n_col : n_col + NOPE_DIM] = n_bf16[n_hi : n_hi + 1, 0 : NOPE_DIM] | ||||||||||||||||||||||||||||||
| o_packed[n_pack_row : n_pack_row + 1, n_col + NOPE_DIM : n_col + HEAD_DIM] = n_rope_bf16[n_hi : n_hi + 1, 0 : ROPE_DIM] | ||||||||||||||||||||||||||||||
| # one HEAD_DIM-wide store per head row instead of two: concat the nope and | ||||||||||||||||||||||||||||||
| # inverse-RoPE halves on chip so o_packed takes a single contiguous write. | ||||||||||||||||||||||||||||||
| n_full_bf16 = pl.concat(n_bf16[n_hi : n_hi + 1, 0 : NOPE_DIM], n_rope_bf16[n_hi : n_hi + 1, 0 : ROPE_DIM]) | ||||||||||||||||||||||||||||||
| o_packed[n_pack_row : n_pack_row + 1, n_col : n_col + HEAD_DIM] = n_full_bf16 | ||||||||||||||||||||||||||||||
|
Comment on lines
+460
to
+463
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
rg -n -C 3 '\bpl\.concat\s*\(' .
rg -n -C 3 '(^|[[:space:]])(def|class).*concat|concat[[:space:]]*=' .Repository: hw-native-sys/pypto-lib Length of output: 3837 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== files =="
git ls-files | sed -n '1,120p'
echo
echo "== imports/defs around relevant files =="
for f in models/deepseek/v4-flash/decode_sparse_attn.py models/qwen3/14b/decode_layer_a8w8.py models/qwen3/14b/prefill_fwd.py; do
echo "-- $f --"
wc -l "$f"
sed -n '1,80p' "$f"
done
echo
echo "== concat occurrences with dimensions around them =="
python3 - <<'PY'
import pathlib, re
for p in pathlib.Path('.').rglob('*.py'):
if '.git' in p.parts: continue
text=p.read_text(errors='ignore')
for m in re.finditer(r'pl\.concat\s*\(', text):
line=text[:m.start()].count('\n')+1
print(f'{p}:{line}: {text[m.start():m.start()+160].split(chr(10))[0].strip()}')
PYRepository: hw-native-sys/pypto-lib Length of output: 20032 🌐 Web query:
💡 Result: In the PyPTO programming framework, the pypto.concat API is used to concatenate multiple tensors along a specified dimension [1]. The function signature and parameter details are as follows: API Signature: pypto.concat(tensors: List[Tensor], dim: int = 0) -> Tensor [1] Parameters: 1. tensors: A list of input tensors to be concatenated. The framework requires the list to contain at least 2 tensors (and no more than 128) [1]. All input tensors must have the same data type and the same number of dimensions, and must match in all dimensions except for the dimension specified by dim [1]. 2. dim: An integer specifying the dimension along which to concatenate the tensors [1]. The default value is 0 [1]. Important Constraints: - The dim parameter must satisfy the constraint -input.dim <= dim < input.dim [1]. - The API does not automatically deduce the output tensor's shape; the user must ensure the output Tensor's validShape is correct before calling concat [1]. - Input tensors cannot be empty, and the Shape Size must not exceed 2147483647 (INT32_MAX) [1]. For context, PyPTO is a high-performance programming framework for AI accelerators that utilizes a Tile-based programming model [2][3]. It should not be confused with Polars (pl.concat), which is a library for data manipulation and concatenation of DataFrames and Series [4][5]. [1][2][4] Citations:
Pass
Proposed fix- n_full_bf16 = pl.concat(n_bf16[n_hi : n_hi + 1, 0 : NOPE_DIM], n_rope_bf16[n_hi : n_hi + 1, 0 : ROPE_DIM])
+ n_full_bf16 = pl.concat(
+ [
+ n_bf16[n_hi : n_hi + 1, 0 : NOPE_DIM],
+ n_rope_bf16[n_hi : n_hi + 1, 0 : ROPE_DIM],
+ ],
+ dim=1,
+ )📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsSource: MCP tools |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # ======================================================================== | ||||||||||||||||||||||||||||||
| # Back-to-back grouped output projection (manual scope, PER-GROUP INT8 quant). | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Preserve invalid-score initialization.
Pages after
visible_len_tare never written, soscorenow contains uninitialized values there.golden_indexerexplicitly returnsFP32_NEG_INFfor every invalid position (lines 513-546), andindexer_testexposes this tensor. Top-k re-masking protects the current consumer but does not preserve the score output contract. InitializescoretoFP32_NEG_INF, or formally remove/relax this output contract and update all callers and reference validation.🤖 Prompt for AI Agents