[HIP] dynamic-tap ShortConv4 kernel (full-attn layers) verified
- k_shortconv4_dyn_decode / vetta_shortconv4_dyn_decode: exact strata
k2_shortconv4 dyn semantics for the full-attention layers — y = x0 +
sw0*h0+sw1*h1+sw2*h2+sw3*x0, then y += dt0*x0+dt1*h2+dt2*h1+dt3*h0, scaled
by 1/3 (vs 1/sqrt(5) for the static SWA variant). dyn_taps [M,n_heads,4],
head = c/(C/n_heads); static_w [C,4]; history ring shifted in place.
- Multi-step parity test: 5-token recurrence vs CPU oracle, per-step match
(<1e-5) AND device history ring == host history ring (exact). The dynamic
short-conv (driven by k/v_sconv.weight_proj taps) evolves correctly.
This is the last shortconv variant needed for the full-attn layers {5,11,17,23}
(3-query mix split + separate q/k/v norms + dyn shortconv + tau + global attn).
Verified: RUSTFLAGS="-D warnings" cargo test --workspace = 97/97 PASS;
lean proofs (5 files incl. inkling_loop) green; GPU 16/16 (--features hip).
This commit is contained in:
1 parent
04aae6db9d
commit
38a983ce80
3 files changed
+97
No files matched your search
@@ -93,6 +93,11 @@ int vetta_shortconv4_decode(const float* cur, const float* static_w, float* hist
|
||||
float* out, const int32_t* slot_ids, int M, int C,
|
||||
vetta_stream_t stream);
|
||||
|
||||
// k_shortconv4_dyn_decode: full-attn ShortConv4 with dynamic taps [M,n_heads,4].
|
||||
int vetta_shortconv4_dyn_decode(const float* cur, const float* static_w, const float* dyn_taps,
|
||||
float* hist, float* out, const int32_t* slot_ids,
|
||||
int M, int C, int n_heads, vetta_stream_t stream);
|
||||
|
||||
// k_attn_res_mix: Inkling AttnRes deep-residual block-mix. blocks [n_blocks,M,D]
|
||||
// snapshots + cur [M,D] -> out [M,n_queries,D] (RMS-normalized depth mix).
|
||||
int vetta_attn_res_mix(const float* blocks, const float* cur, const float* queries,
|
||||
|
||||
@@ -613,6 +613,51 @@ extern "C" int vetta_shortconv4_decode(const float* cur, const float* static_w,
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ---- k_shortconv4_dyn_decode: full-attn ShortConv4 with dynamic taps --------
|
||||
// Exact strata k2_shortconv4 (dyn): y = x0 + sw0*h0+sw1*h1+sw2*h2+sw3*x0;
|
||||
// y += dt0*x0 + dt1*h2 + dt2*h1 + dt3*h0; y *= 1/3.
|
||||
// dyn_taps [M, n_heads, 4]; head = c/(C/n_heads). static_w [C,4]. History shift.
|
||||
|
||||
__global__ void k_shortconv4_dyn_decode(const float* __restrict__ cur,
|
||||
const float* __restrict__ static_w,
|
||||
const float* __restrict__ dyn_taps,
|
||||
float* __restrict__ hist,
|
||||
float* __restrict__ out,
|
||||
const int32_t* __restrict__ slot_ids,
|
||||
int M, int C, int n_heads) {
|
||||
const int c = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
const int m = blockIdx.y;
|
||||
if (c >= C || m >= M) return;
|
||||
const int slot = slot_ids[m];
|
||||
float* h = hist + (size_t)slot * 3 * C;
|
||||
const float h0 = h[0 * C + c];
|
||||
const float h1 = h[1 * C + c];
|
||||
const float h2 = h[2 * C + c];
|
||||
const float x0 = cur[(size_t)m * C + c];
|
||||
const float* sw = static_w + (size_t)c * 4;
|
||||
float y = x0 + sw[0] * h0 + sw[1] * h1 + sw[2] * h2 + sw[3] * x0;
|
||||
const int head = c / (C / n_heads);
|
||||
const float* dt = dyn_taps + ((size_t)m * n_heads + head) * 4;
|
||||
y += dt[0] * x0 + dt[1] * h2 + dt[2] * h1 + dt[3] * h0;
|
||||
y *= (1.0f / 3.0f);
|
||||
h[0 * C + c] = h1;
|
||||
h[1 * C + c] = h2;
|
||||
h[2 * C + c] = x0;
|
||||
out[(size_t)m * C + c] = y;
|
||||
}
|
||||
|
||||
extern "C" int vetta_shortconv4_dyn_decode(const float* cur, const float* static_w,
|
||||
const float* dyn_taps, float* hist, float* out,
|
||||
const int32_t* slot_ids, int M, int C, int n_heads,
|
||||
vetta_stream_t stream) {
|
||||
if (M <= 0 || C <= 0 || n_heads <= 0 || (C % n_heads) != 0) return 1;
|
||||
dim3 grid((C + 255) / 256, M);
|
||||
hipStream_t s = stream ? (hipStream_t)stream : (hipStream_t)0;
|
||||
k_shortconv4_dyn_decode<<<grid, 256, 0, s>>>(cur, static_w, dyn_taps, hist, out, slot_ids, M, C, n_heads);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ---- k_attn_res_mix: Inkling AttnRes deep-residual block-mix (parity) ------
|
||||
// Exact strata k1_attn_res_mix: for each query q and token m, mix n_states =
|
||||
// n_blocks+1 depth states (block snapshots + current). Per state s:
|
||||
|
||||
Reference in new issue
Block a user