Archived
- Gemma 4 31B (PRs #74, #75, #81, #86; sfjes, keptn42): sliding and global attention with their own kernels, the assistant head as a drafter that reads the trunk's cache, the vision tower, a fused w4a8 decode step, bf16 and compressed-tensors int4 checkpoints, and window snapshots so a prefix hit on a sliding-window model resumes instead of prefilling again. deploy/compose/gemma4-31b-w4a8.yaml serves keptn42's container on two cards - ParoQuant (PRs #65, #66, #67; malic): Qwen3.8-27B checkpoints with learned Givens rotations, as int4, int5 and MXFP4, imported without re-quantising, the prefill's rotations on the matrix cores. deploy/compose/qwen3.8-27b-paro.yaml serves them on one card. A ParoQuant container made with the PR builds is refused: convert it again with --reuse <old container> - Gemma 4 26B-A4B with z-lab's DFlash drafter (PR #88; Perire): arch/gemma4 serves Google's bf16 checkpoint with the routed experts in block fp8 or bf16 (data/recipes/gemma4-26b-a4b-df*.recipe), and libr4d gains its windowed paged attention, the fused sandwich-norm joins, expert_scale and the sharded draft head's pair_argmax. A prefill chunk runs as two slices with its all-reduces beside the compute, bit-exact with the whole step. The 31B's global layers take the windowed attention too: an 11.5K-token prefill on two R9700s in 3.1 s instead of 4.9 - a startup that logs nothing for two minutes says where it waits (#89): the system call (a KFD request by name), the library that made it, and its stack, which addr2line resolves against the binary - the prefix cache is kept in VRAM and host memory only (#70): the disk tier wrote every block and snapshot a prompt produced, and its copies never outlived the process. --prefix-cache-host-mib is renamed --prefix-cache-mib; --prefix-cache-dir and --prefix-cache-disk-mib are removed, and startup refuses all three with what replaced them. The compose files no longer mount /data, and .env no longer needs RADIANCE_STATE - --prefix-cache-ttl S (default 3600, 0 never): a conversation no request has used for that long leaves the cache, whichever tier holds it; radiance:prefix_cache_expired_total counts them. A full host tier now drops its least recently used conversations - --vision-tower-placement vram|ram (#84): ram keeps an encoder tower in pinned host memory and gives its VRAM to the KV cache, read over the link once an image - timings carry ttft_ms and total_ms (#85): the server's own time from the request body's arrival to the first and the last token, queueing and tokenisation included - a KV-cache recall that found a moved expert with nowhere to go stopped halfway and leaked the slots it had already freed: after it every recall failed, the cache stayed short until a restart, and requests failed with HTTP 500. A recall now waits for the slots it is owed and always finishes - a tool result or tool-call arguments that are not JSON are no longer refused as nesting past 1024 levels for their unmatched brackets (#90): only text that parses as JSON is held to the bound, since nothing else is parsed into a tree - the host-pool refusal names the limit that applies to pinned memory (RAM less 1/64 and 1.5 GiB), not ttm.pages_limit - --embedding-placement auto, removed in 1.3.0, is refused with what replaced it - for out-of-tree kernel libraries: gemm_nt_q gains two operands (pb1, pb2, the part bounds), and the loader requires identical op schemas, so a library built against 1.4.0 must be rebuilt. For architecture plugins, rad_op_declared(b, op) asks whether an op is in the loaded vocabulary without declaring it
106 lines
4.5 KiB
Plaintext
106 lines
4.5 KiB
Plaintext
/* r4d_pair_argmax_f32.hip -- pair_argmax: the global argmax of a row of gathered (id, value) pairs, written as
|
|
* ONE CONTIGUOUS COLUMN of token ids.
|
|
*
|
|
* WHY THIS OP EXISTS. A vocab-sharded draft head finds each rank's best candidates with `row_topk`
|
|
* and moves them with `all_gather`. The gather moves whole 16-byte words a row, and one (int32 id,
|
|
* f32 value) pair is 8 bytes, so a rank contributes at least R = 2 (rad_block_mtp_hc.h states the
|
|
* same bound). `row_topk_merge` then returns R = 2 columns a row, and a BLOCK drafter's proposal
|
|
* is `steps` contiguous ids a sequence -- column 0 of an [S, 2] plane is not that, and nothing in
|
|
* libr4d copies a strided i32 column. This reduces the gathered row to its top-1 and writes it
|
|
* where the proposal reads it.
|
|
*
|
|
* It is row_topk_merge at R = 1 with a strided output, rule for rule: the largest value wins, a tie
|
|
* goes to the LOWER id, and a pair whose id is negative (a slot a shard could not fill) is skipped.
|
|
* A row with no valid pair writes id -1 and value -inf. One wave a row, eight rows a workgroup.
|
|
*/
|
|
#include <hip/hip_runtime.h>
|
|
|
|
#include <cstdint>
|
|
|
|
#include "r4d_plugin.h"
|
|
#include "r4d_launch.h"
|
|
#include "rad_plugin.h"
|
|
|
|
namespace r4d_pick {
|
|
|
|
struct PickArgs {
|
|
const float* pairs; long long p_rs; /* [M, n, 2]: int32 id bits, then f32 value */
|
|
int* tok; long long t_rs;
|
|
float* val; long long v_rs; /* optional */
|
|
long long rows;
|
|
int n;
|
|
};
|
|
|
|
__device__ __forceinline__ int pk_lane() { return (int)(threadIdx.x & 31u); }
|
|
__device__ __forceinline__ int pk_xor_i(int v, int m) {
|
|
return __builtin_amdgcn_ds_bpermute((pk_lane() ^ m) << 2, v);
|
|
}
|
|
__device__ __forceinline__ float pk_xor_f(float v, int m) {
|
|
return __int_as_float(pk_xor_i(__float_as_int(v), m));
|
|
}
|
|
/* (v, id) beats (bv, bid)? Larger value, then lower id; an invalid id (< 0) never wins. */
|
|
__device__ __forceinline__ bool pk_better(float v, int id, float bv, int bid) {
|
|
if (id < 0) return false;
|
|
if (bid < 0) return true;
|
|
return v > bv || (v == bv && id < bid);
|
|
}
|
|
|
|
__global__ __launch_bounds__(256) void pick_kernel(PickArgs A) {
|
|
const long long r = (long long)blockIdx.x * 8 + (threadIdx.x >> 5);
|
|
if (r >= A.rows) return; /* uniform across the wave */
|
|
const int lane = pk_lane();
|
|
const float* row = A.pairs + r * A.p_rs;
|
|
float bv = -__builtin_inff();
|
|
int bid = -1;
|
|
for (int j = lane; j < A.n; j += 32) {
|
|
const int id = __float_as_int(row[2 * j]);
|
|
const float v = row[2 * j + 1];
|
|
if (pk_better(v, id, bv, bid)) { bv = v; bid = id; }
|
|
}
|
|
#pragma unroll
|
|
for (int m = 16; m >= 1; m >>= 1) {
|
|
const float ov = pk_xor_f(bv, m);
|
|
const int oid = pk_xor_i(bid, m);
|
|
if (pk_better(ov, oid, bv, bid)) { bv = ov; bid = oid; }
|
|
}
|
|
if (lane == 0) {
|
|
A.tok[r * A.t_rs] = bid;
|
|
if (A.val) A.val[r * A.v_rs] = bv;
|
|
}
|
|
}
|
|
|
|
} /* namespace r4d_pick */
|
|
|
|
/* pairs as [M, n, 2] (rank 3) or [M, 2n] (rank 2), last axes dense; the outputs one element a row
|
|
* at their own row pitch. */
|
|
extern "C" int r4d_rad_pair_argmax_f32(const RadArgs* a, RadStream stream) {
|
|
if (!a || a->n_t < 3) return RAD_E_INVAL;
|
|
const RadTensor* p = rad_arg_in(a, 0);
|
|
const RadTensor* t = rad_arg_in(a, 1);
|
|
const RadTensor* v = rad_arg_in(a, 2);
|
|
if (!p || !t) return RAD_E_INVAL;
|
|
if (p->dtype != RAD_F32 || t->dtype != RAD_I32 || (v && v->dtype != RAD_F32)) return RAD_E_DTYPE;
|
|
const long long n = rad_args_geti_or(a, "n", 0);
|
|
if (n <= 0 || p->rank < 2) return RAD_E_SHAPE;
|
|
if (p->rank == 3) {
|
|
if (p->shape[1] < n || p->shape[2] != 2 || p->stride[2] != 1 || p->stride[1] != 2) return RAD_E_SHAPE;
|
|
} else if (p->rank == 2) {
|
|
if (p->shape[1] < 2 * n || p->stride[1] != 1) return RAD_E_SHAPE;
|
|
} else {
|
|
return RAD_E_SHAPE;
|
|
}
|
|
const int64_t rows = p->shape[0];
|
|
if (rows == 0) return RAD_OK;
|
|
if (t->rank < 1 || t->shape[0] < rows || (v && (v->rank < 1 || v->shape[0] < rows))) return RAD_E_SHAPE;
|
|
r4d_pick::PickArgs A{};
|
|
A.pairs = (const float*)p->data; A.p_rs = p->stride[0];
|
|
A.tok = (int*)t->data; A.t_rs = t->rank >= 2 ? t->stride[0] : 1;
|
|
A.val = v ? (float*)v->data : nullptr;
|
|
A.v_rs = v ? (v->rank >= 2 ? v->stride[0] : 1) : 0;
|
|
A.rows = rows;
|
|
A.n = (int)n;
|
|
R4D_KLAUNCH(R4D_KNAME(r4d_pick::pick_kernel), dim3((unsigned)((rows + 7) / 8)), dim3(256),
|
|
(hipStream_t)stream, A);
|
|
return hipGetLastError() == hipSuccess ? RAD_OK : RAD_E_DEVICE;
|
|
}
|