dsa_score: row_part -- score one run of a step's query rows, and rebase cu for the selection after it

With `row_part` p, `score` holds R rows and row i is query row p * R + i; `q`, `q_scale` and
`gate` stay the whole step's, so a run is the unsplit op's rows bit for bit. A row past the last
sequence scores -inf, so every rank's run can be the same length whatever the step's. The optional
output `cu_part` receives cu - p * R, under which qsa_select runs over the run's own rows (pos
offset by p * R) and finds each row's sequence unchanged; qsa_select itself is untouched.

This is what an indexer split over tensor-parallel ranks by query rows needs from the op: the
scoring is the only per-row work in GLM-5.3's indexer that grows with the context.

libr4d offsets the query operands and compares row0 + r against cu; libref and libavx index the
same way. Without `row_part` nothing changes. Tests: the selftest scores each case's rows in equal
runs and holds every run to the unsplit rows' bytes and cu_part to the rebased bounds; ref_test
checks a run, a run past the step and a short query plane; r4d_emu_dsa (r4d_dsa.hip now runs on
the emulator) splits decode rows beside a prefill chunk at 2, 4 and 8 ranks, selects with the
rebased bounds and joins the runs as the all_gather does, byte for byte against the unsplit
scorer and selection, ties and signed gates included.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
NunzeandClaude Fable 5.1 authored and StillDeadcode committed 2026-10-21 15:24:05 +02:00
1 parent 5e8bae8ae6
commit afe5318259
13 files changed
+451 -47

No files matched your search

+37
View File
@@ -13481,6 +13481,43 @@ static void dsa_score_check(const Plugin& pl, int64_t rows, int64_t blocks, bool
.c_str(),
matches);
ok("DSA scorer guards and pitched output", guards);
if (matches) {
/* The rows split into `parts` equal runs, each scored with `row_part` into its own
* plane: every run must be the unsplit rows' bytes, and cu_part the rebased bounds. */
int64_t parts = rows;
for (int64_t d = 2; d < rows; ++d)
if (rows % d == 0) {
parts = d;
break;
}
const int64_t R = rows / parts, S = host[6].shape[0];
bool same = true;
for (int64_t part = 0; part < parts && same; ++part) {
std::vector<RadTensor> split = device;
split.push_back(T(nullptr, RAD_I32, { S }));
split[8] = T(nullptr, RAD_F32, { R, blocks });
std::vector<RadParam> sp = ps;
sp[0] = PI("M", R);
sp.push_back(PI("row_part", part));
run_case(row, split, sp);
std::vector<float> plane((size_t)(R * blocks));
std::vector<int32_t> cu_part((size_t)S);
st_memcpy(plane.data(), split[8].data, plane.size() * 4, hipMemcpyDeviceToHost);
st_memcpy(cu_part.data(), split[9].data, cu_part.size() * 4, hipMemcpyDeviceToHost);
for (int64_t r = 0; r < R; ++r)
same = same && std::memcmp(&plane[(size_t)(r * blocks)],
got.data() + 128 +
(size_t)((part * R + r) * out.stride[0]) * 4,
(size_t)blocks * 4) == 0;
for (int64_t i = 0; i < S; ++i)
same = same && cu_part[(size_t)i] ==
((int32_t*)host[6].data)[i * host[6].stride[0]] - part * R;
}
ok(fmt("DSA scorer split into %lld row parts: each the unsplit rows' bytes, cu rebased",
(long long)parts)
.c_str(),
same);
}
if (packed) {
std::vector<uint8_t> after(packed_bytes.size());
st_memcpy(after.data(), packed_device, after.size(), hipMemcpyDeviceToHost);