ops: ssd_update and ple_conv_bias, Mamba-2's scan and convolution

ssd_update is Mamba-2's selective state update, a token at a time, with kda_update's rollback
contract: per_candidate, or the anchor form (one committed state and a scratch of per-token
records). libref, libavx and a libr4d kernel at a 128-wide state (r4d_ssd.hip, r4d_kda.hip's
register layout). ple_conv_bias is ple_conv with a per-channel bias inside the silu, Mamba-2's
conv1d, an op of its own so ple_conv's callers keep their operand list.

ref_test, avx_check_hand and selftest cases; docs/OPS.md.
This commit is contained in:
keptn42 committed 2026-11-04 22:08:52 +01:00
1 parent 3b278dcec3
commit 63416510a0
21 files changed
+1362 -11

No files matched your search

+40
View File
@@ -630,6 +630,46 @@ void shape_cases(std::vector<Hand>& hs) {
.ps("state_form", "anchor");
hs.push_back(std::move(h));
}
/* Nemotron-H's Mamba-2 under the same two-copy state: a scratch holding three records of
* 1 + head_dim + d_state floats (decay, u, B) behind the count. */
for (const char* mode : { "prefill", "verify" })
for (int accepted : { 1, 2, 3 })
for (int cold : { 0, 1 }) {
constexpr int64_t P = 16, N = 32, R = 1 + P + N;
Hand h("SSD anchor accepted-prefix replay", "ssd_update", 0.01);
h.dense(RAD_BF16, { 2, 1, P }, hfill(221, 0.25f))
.dense(RAD_BF16, { 2, 1, N }, hfill(222, 0.25f))
.dense(RAD_BF16, { 2, 1, N }, hfill(223, 0.25f))
.dense(RAD_BF16, { 2, 1 }, hfill(224, 0.25f))
.dense(RAD_F32, { 1 }, [](int64_t) { return 0.0f; })
.dense(RAD_F32, { 1 }, [](int64_t) { return -1.0f; })
.dense(RAD_F32, { 1 }, [](int64_t) { return 0.5f; })
.dense(
RAD_F32, { 2, 1, P, N },
[](int64_t i) {
if (i < P * N) return 0.125f;
i -= P * N;
if (!i) return 3.0f;
if (i > 3 * R) return 0.0f;
const int64_t at = (i - 1) % R;
return at == 0 ? 0.75f : at <= P ? 0.01f : 0.125f;
},
true)
.dense(RAD_I32, { 1, 6 }, [](int64_t i) { return i < 3 ? 0.0f : 1.0f; })
.idx({ 0, 2 })
.idx({ accepted })
.idx({ cold ? 0 : 1 })
.dense(RAD_BF16, { 2, 1, P }, hfill(225), true)
.pi("M", 2)
.pi("heads", 1)
.pi("head_dim", P)
.pi("d_state", N)
.pi("groups", 1)
.ps("mode", mode)
.ps("dtype", "bf16")
.ps("state_form", "anchor");
hs.push_back(std::move(h));
}
for (const char* mode : { "absorb", "expand" }) {
const bool absorb = !std::strcmp(mode, "absorb");
const int64_t in = absorb ? 17 : 31, out = absorb ? 31 : 17;