[Core] batched full-attn layer (M=B) bit-exact + l2_clip per-token tau
layer_forward_full_batched mirrors layer_forward_full at M=B: 3-query mix [B*3,h] split strided via gather_channel(nq=3) into in0/in1/in2 with separate q/k/v norms; DYNAMIC ShortConv K/V via shortconv4_prefill_par(dyn_taps[B,n_kv,4]) (already supported dyn path, no new kernel); Q/R l2_clip with per-token tau; global flash window=0; MoE sublayer identical to batched SWA. k_l2_clip gains pos_arr (device [M]): tau uses pos_arr[r/scale_rows] per token (full-attn) else scalar pos. l2_clip passes null (M=1 unchanged); l2_clip_batched takes Option<&DeviceBuf> pos_arr. layer_full_batched_parity (real weights ip=5, B=8, f16 KV + device MoE): cur[B,h] BIT-EXACT (0.0) AND KV byte-identical vs 8 sequential M=1 calls. Both layer types (SWA + full-attn) now batched and verified.
This commit is contained in:
1 parent
3dbb6bb1b4
commit
1aaf7f12c2
4 files changed
+170
-13
No files matched your search
@@ -149,7 +149,7 @@ int vetta_attn_res_mix(const float* blocks, const float* cur, const float* queri
|
||||
|
||||
// k_l2_clip: per-head L2 clip + optional per-dim scale + optional tau (in place).
|
||||
int vetta_l2_clip(float* x, const float* scale, int rows, int hd, float clip,
|
||||
int apply_tau, int pos, int scale_rows, vetta_stream_t stream);
|
||||
int apply_tau, int pos, int scale_rows, const int32_t* pos_arr, vetta_stream_t stream);
|
||||
|
||||
// k_relpos_bias: rel_bias[h,dist] = sum_rc R[h,rc]*rel_proj[rc,dist], dist<lim.
|
||||
int vetta_relpos_bias(const float* r, const float* rel_proj, float* rel_bias,
|
||||
|
||||
@@ -1627,7 +1627,8 @@ extern "C" int vetta_attn_res_mix(const float* blocks, const float* cur, const f
|
||||
// (pos+1)/8192)); x = v*fac. One block per row (head), in place.
|
||||
|
||||
__global__ void k_l2_clip(float* __restrict__ x, const float* __restrict__ scale,
|
||||
int rows, int hd, float clip, int apply_tau, int pos, int scale_rows) {
|
||||
int rows, int hd, float clip, int apply_tau, int pos, int scale_rows,
|
||||
const int32_t* __restrict__ pos_arr) {
|
||||
const int r = blockIdx.x;
|
||||
if (r >= rows) return;
|
||||
const int tid = threadIdx.x;
|
||||
@@ -1644,7 +1645,9 @@ __global__ void k_l2_clip(float* __restrict__ x, const float* __restrict__ scale
|
||||
if (tid == 0) {
|
||||
float fac = fminf(1.f, clip / (sqrtf(red[0]) + 1e-6f));
|
||||
if (apply_tau) {
|
||||
const float rr = (float)(pos + 1) / 8192.f;
|
||||
// Batched tau uses the per-token position pos_arr[r / scale_rows].
|
||||
const int p = pos_arr ? pos_arr[r / scale_rows] : pos;
|
||||
const float rr = (float)(p + 1) / 8192.f;
|
||||
fac *= 1.f + 0.1f * logf(fmaxf(1.f, rr));
|
||||
}
|
||||
fac_s = fac;
|
||||
@@ -1654,10 +1657,11 @@ __global__ void k_l2_clip(float* __restrict__ x, const float* __restrict__ scale
|
||||
}
|
||||
|
||||
extern "C" int vetta_l2_clip(float* x, const float* scale, int rows, int hd,
|
||||
float clip, int apply_tau, int pos, int scale_rows, vetta_stream_t stream) {
|
||||
float clip, int apply_tau, int pos, int scale_rows,
|
||||
const int32_t* pos_arr, vetta_stream_t stream) {
|
||||
if (rows <= 0 || hd <= 0 || hd > 256 || scale_rows <= 0) return 1;
|
||||
hipStream_t s = stream ? (hipStream_t)stream : (hipStream_t)0;
|
||||
k_l2_clip<<<rows, 256, 0, s>>>(x, scale, rows, hd, clip, apply_tau, pos, scale_rows);
|
||||
k_l2_clip<<<rows, 256, 0, s>>>(x, scale, rows, hd, clip, apply_tau, pos, scale_rows, pos_arr);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user