Archived
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:
1 parent
3b278dcec3
commit
63416510a0
21 files changed
+1362
-11
No files matched your search
+15
-2
@@ -157,11 +157,12 @@ AVX_KERNEL(ple_gate) {
|
||||
struct ConvOps {
|
||||
const RadTensor *x, *w, *cs, *cu, *resid, *sidx, *hini, *nacc, *y;
|
||||
bool silu;
|
||||
const RadTensor* b; /* per-channel bias inside the activation (Mamba-2's conv1d), or null */
|
||||
};
|
||||
|
||||
static int depthwise_causal_conv(const RadArgs* a, const ConvOps& o) {
|
||||
const RadTensor *x = o.x, *w = o.w, *cs = o.cs, *cu = o.cu, *resid = o.resid;
|
||||
const RadTensor *sidx = o.sidx, *hini = o.hini, *nacc = o.nacc, *y = o.y;
|
||||
const RadTensor *sidx = o.sidx, *hini = o.hini, *nacc = o.nacc, *y = o.y, *b = o.b;
|
||||
if (!x || !w || !cs || !cu || !y) return RAD_E_INVAL;
|
||||
|
||||
const int64_t n = p_int(a, "n", 0);
|
||||
@@ -180,6 +181,7 @@ static int depthwise_causal_conv(const RadArgs* a, const ConvOps& o) {
|
||||
if (N <= 0) return RAD_E_SHAPE;
|
||||
if (numel(x) < M * n || numel(y) < M * n || numel(w) < n * wid) return RAD_E_SHAPE;
|
||||
if (resid && numel(resid) < M * n) return RAD_E_SHAPE;
|
||||
if (b && numel(b) != n) return RAD_E_SHAPE;
|
||||
|
||||
const int64_t state_len = cs->rank >= 3 ? cs->shape[cs->rank - 1] : hist_len;
|
||||
if (cs->data && state_len < hist_len) return RAD_E_SHAPE;
|
||||
@@ -222,9 +224,10 @@ static int depthwise_causal_conv(const RadArgs* a, const ConvOps& o) {
|
||||
* on the stack, so `width` needs no bound of its own. */
|
||||
float* tap = scratch_f32((size_t)wid);
|
||||
for (int64_t j = 0; j < wid; ++j) tap[j] = ldt(w, c * wrow + j * wcol);
|
||||
const float bias = b ? ldt(b, c * laststride(b)) : 0.0f;
|
||||
|
||||
for (int64_t t = 0; t < slen; ++t) {
|
||||
float acc = 0.0f;
|
||||
float acc = bias;
|
||||
for (int64_t j = 0; j < wid; ++j) {
|
||||
const int64_t src = t - hist_len + j * dil;
|
||||
const float vv = src >= 0 ? ldt(x, (bos + src) * xrow + c * xcol)
|
||||
@@ -277,6 +280,16 @@ AVX_KERNEL(ple_conv) {
|
||||
rad_arg_in(a, 6), rad_arg_in(a, 7), rad_arg_in(a, 8), true });
|
||||
}
|
||||
|
||||
/* ple_conv's operands with `b`, a per-channel bias inside the silu, before `y`: Mamba-2's
|
||||
* conv1d at dilation one. */
|
||||
AVX_KERNEL(ple_conv_bias) {
|
||||
if (a->n_t < 10 || !rad_arg_in(a, 8)) return RAD_E_INVAL;
|
||||
return depthwise_causal_conv(a, { rad_arg_in(a, 0), rad_arg_in(a, 1), rad_arg_in(a, 2),
|
||||
rad_arg_in(a, 3), rad_arg_in(a, 4), rad_arg_in(a, 5),
|
||||
rad_arg_in(a, 6), rad_arg_in(a, 7), rad_arg_in(a, 9), true,
|
||||
rad_arg_in(a, 8) });
|
||||
}
|
||||
|
||||
/* ple_conv's operands without `resid`, dilation 1, no activation. */
|
||||
AVX_KERNEL(causal_conv1d) {
|
||||
if (a->n_t < 8) return RAD_E_INVAL;
|
||||
|
||||
Reference in new issue
Block a user