Archived
radiance 2.0.0
Radiance becomes a multi-model engine: one process serves several models behind one port, loads each when a request names it, parks it in host memory or restores it from its container, and shares the cards between them (docs/MULTIMODEL.md). The configuration is one YAML file; the command line flags are gone (`radiance --config FILE`, hot reload on SIGHUP). Formats. IQ8R (rotated int8) and IQR-V4 replace FP8 and MXFP4 as whole-model formats, with an int8 KV cache (`kv-cache-dtype: i8`) in place of the fp8 one. Containers whose weights are block FP8, MXFP4, M2XFP4, NVFP4 or ParoQuant are refused at startup by the name of the first such weight. Not served until they have int8 containers: GLM-5.3-Flash, Ornith-1.5, Sage-A1.5, Nemotron-3.5-Bolt-74B, Ling-3.0-flash, drama-3 and Anima's FP8 container; Nemotron-3.5-Bolt-E4B, the Gemma 4 31B DFlash containers and MiniCPM5-2B bf16 serve without their drafter. 1.17.0 serves all of them. Speed. Chained launches for Qwen3.8-27B, Gemma 4, Gemma 3 and the small bf16 models, a new Qwen3.8-Flash-Next container (IQR-V4 experts, int8 trunk) with its decode step and prefill reworked, and a reworked adaptive draft window. Deployment. deploy/compose has two fleet files, tp1.yaml and tp2.yaml, each with its configuration beside it, in place of the per-model files. `host-pool-mib` is a model's host pool in all, split among its ranks. The dashboard is rebuilt: an hour of history kept by the server, each accelerator's memory by model, model states over time. Merged since 1.17.0: Nemotron-3.5-Bolt-74B-A9B by keptn42 (#339); GLM-5.3-Flash on four cards by AnimusNull (#397); chained launches for Flash-Next's decode step (#396) and preempted requests keeping their prefix and place (#405) by mici81; --prefill-interleave auto by Code000 (#410); eight more libr3d kernels and the w4a4 reference by RikshaDriver (#403, #407, #408); libr3d large-BAR and E4M3 decode fixes by neuromanMD (#438, #439); int4/int5 decode tiles by Kezi (#426); attention for Nanbeige 4.3 33B by everplays (#417); expert_stats_report.py by baKon (#431). Fixed: #398, #402, #419, #437 (dschmitz's patch); added the metrics of #392, and multi-model serving as asked for in #367 and #109. Plugin ABI 39: out-of-tree plugins need to be rebuilt. Thanks to @keptn42, @AnimusNull, @mici81, @Code000, @RikshaDriver, @neuromanMD, @Kezi, @everplays, @baKon and @dschmitz.
This commit is contained in:
1 parent
b4c04b6042
commit
ddcb9c69bb
696 files changed
+120770
-56596
No files matched your search
+127
-25
@@ -206,25 +206,39 @@ __global__ __launch_bounds__(R4D_TOPK_WAVE * R4D_TOPK_WPB) void r4dchain_rowtopk
|
||||
// An empty slot is not token `off`. A chunk that ran out of candidates leaves a zero key; OI gets
|
||||
// column 0 for it, without the offset, so a pad cannot look like this rank's first real token. The
|
||||
// pair plane writes -1, the sentinel the merge drops (not -INFINITY, a valid masked logit).
|
||||
// The body; the plain kernel and its chained form (r4d_chain.h) wrap it below.
|
||||
// The body; the plain kernel and its chained form (r4d_chain.h) wrap it below. PT is a lane's
|
||||
// list, at least R (see the header): 32 serves every R, and a launch for R <= 8 or R <= 16 takes
|
||||
// the shorter list, whose insert and whose round's shift are that much shorter. The output is the
|
||||
// same for any PT >= R.
|
||||
template <int PT>
|
||||
__device__ __forceinline__ void r4d_rowtopk_stage2_body(
|
||||
const unsigned long long* __restrict__ P, float* __restrict__ OV, int* __restrict__ OI,
|
||||
float* __restrict__ OP, int off, int R, int n) {
|
||||
const int m = blockIdx.x;
|
||||
const int lane = threadIdx.x;
|
||||
|
||||
unsigned long long t[R4D_TOPK_PT2];
|
||||
unsigned long long t[PT];
|
||||
#pragma unroll
|
||||
for (int q = 0; q < R4D_TOPK_PT2; q++) t[q] = 0ull;
|
||||
for (int q = 0; q < PT; q++) t[q] = 0ull;
|
||||
|
||||
// The key decides, as in stage 1 (see tk_insert). A NaN a chunk handed on displaced a real
|
||||
// candidate, so dropping it here can leave the row short of R; the pad filling the gap is what
|
||||
// the merge reports as id -1. An empty slot's key is 0 and never places.
|
||||
// UNROLL keys are loaded before the first is placed, as in stage 1: one load a pass would put a
|
||||
// memory latency between consecutive inserts. A lane places its keys in the same order.
|
||||
const unsigned long long* p = P + (size_t)m * n;
|
||||
for (int i = lane; i < n; i += R4D_TOPK_WAVE) tk_insert<R4D_TOPK_PT2>(t, p[i]);
|
||||
int i = lane;
|
||||
for (; i + (R4D_TOPK_UNROLL - 1) * R4D_TOPK_WAVE < n; i += R4D_TOPK_UNROLL * R4D_TOPK_WAVE) {
|
||||
unsigned long long k[R4D_TOPK_UNROLL];
|
||||
#pragma unroll
|
||||
for (int u = 0; u < R4D_TOPK_UNROLL; u++) k[u] = p[i + u * R4D_TOPK_WAVE];
|
||||
#pragma unroll
|
||||
for (int u = 0; u < R4D_TOPK_UNROLL; u++) tk_insert<PT>(t, k[u]);
|
||||
}
|
||||
for (; i < n; i += R4D_TOPK_WAVE) tk_insert<PT>(t, p[i]);
|
||||
|
||||
for (int r = 0; r < R; r++) {
|
||||
const unsigned long long w = tk_round<R4D_TOPK_PT2>(t);
|
||||
const unsigned long long w = tk_round<PT>(t);
|
||||
if (lane == 0) {
|
||||
// A zero key is an empty slot, not a real column.
|
||||
const float v = w ? tk_val(w) : -INFINITY;
|
||||
@@ -239,16 +253,18 @@ __device__ __forceinline__ void r4d_rowtopk_stage2_body(
|
||||
}
|
||||
}
|
||||
}
|
||||
template <int PT>
|
||||
__global__ __launch_bounds__(R4D_TOPK_WAVE) void r4d_rowtopk_stage2_kernel(
|
||||
const unsigned long long* __restrict__ P, float* __restrict__ OV, int* __restrict__ OI,
|
||||
float* __restrict__ OP, int off, int R, int n) {
|
||||
r4d_rowtopk_stage2_body(P, OV, OI, OP, off, R, n);
|
||||
r4d_rowtopk_stage2_body<PT>(P, OV, OI, OP, off, R, n);
|
||||
}
|
||||
template <int PT>
|
||||
__global__ __launch_bounds__(R4D_TOPK_WAVE) void r4dchain_rowtopk_stage2(
|
||||
const unsigned long long* __restrict__ P, float* __restrict__ OV, int* __restrict__ OI,
|
||||
float* __restrict__ OP, int off, int R, int n) {
|
||||
r4d_chain_wait();
|
||||
r4d_rowtopk_stage2_body(P, OV, OI, OP, off, R, n);
|
||||
r4d_rowtopk_stage2_body<PT>(P, OV, OI, OP, off, R, n);
|
||||
r4d_chain_done();
|
||||
}
|
||||
|
||||
@@ -293,10 +309,14 @@ static int rowtopk_bf16_sharded_emit(long y, long partial, long outv, long outi,
|
||||
}
|
||||
#undef R4D_TK_S1
|
||||
if (emit_rc != RAD_OK) return emit_rc;
|
||||
return R4D_EMIT(stream, (chain ? r4dchain_rowtopk_stage2 : r4d_rowtopk_stage2_kernel), dim3(M),
|
||||
dim3(R4D_TOPK_WAVE), 0,
|
||||
(const unsigned long long*)partial, (float*)outv, (int*)outi,
|
||||
(float*)outp, off, R, nch * RC);
|
||||
#define R4D_TK_S2(PT) R4D_EMIT(stream, (chain ? r4dchain_rowtopk_stage2<PT> \
|
||||
: r4d_rowtopk_stage2_kernel<PT>), dim3(M), \
|
||||
dim3(R4D_TOPK_WAVE), 0, \
|
||||
(const unsigned long long*)partial, (float*)outv, (int*)outi, \
|
||||
(float*)outp, off, R, nch * RC)
|
||||
const int rc2 = R <= 8 ? R4D_TK_S2(8) : R <= 16 ? R4D_TK_S2(16) : R4D_TK_S2(R4D_TOPK_PT2);
|
||||
#undef R4D_TK_S2
|
||||
return rc2;
|
||||
}
|
||||
|
||||
// ============================================================ the vocab-parallel merge
|
||||
@@ -376,14 +396,16 @@ __global__ __launch_bounds__(R4D_TOPK_WAVE) void r4dchain_rowtopk_merge(
|
||||
// row's bf16 scale per 128 columns in its tail) with int8 codes instead of E4M3. The drafter
|
||||
// rescores against whichever head the trunk's logits GEMM reads, so an int8 head needs this form.
|
||||
#define R4D_RERANK_WPB 8 // waves a block: 256 threads, and R <= 32 so a wave takes <= 4
|
||||
#define R4D_RERANK_U 5 // 512-column steps a lane has in flight: all of K = 2560
|
||||
|
||||
/* TB > 0: an IQR head (r4d_iqr.h's lm form), TB-bit codes then the row's scales, the table of 2^TB
|
||||
* int8 entries after the last row. */
|
||||
#define R4D_LOGIT_RERANK_PARAMS \
|
||||
const unsigned short* __restrict__ X, const int* __restrict__ IN, \
|
||||
const unsigned char* __restrict__ W, int* __restrict__ OI, float* __restrict__ OV, \
|
||||
float* __restrict__ OP, int R, long K, long voff, long nv, long w_ld
|
||||
template <bool I8, uint32_t TB = 0>
|
||||
__global__ __launch_bounds__(R4D_TOPK_WAVE * R4D_RERANK_WPB) void r4d_logit_rerank_kernel(
|
||||
const unsigned short* __restrict__ X, const int* __restrict__ IN,
|
||||
const unsigned char* __restrict__ W, int* __restrict__ OI, float* __restrict__ OV,
|
||||
float* __restrict__ OP, int R, long K, long voff, long nv, long w_ld) {
|
||||
__device__ __forceinline__ void r4d_logit_rerank_body(R4D_LOGIT_RERANK_PARAMS) {
|
||||
__shared__ float s_sc[R4D_TOPK_PT2];
|
||||
__shared__ int s_id[R4D_TOPK_PT2];
|
||||
|
||||
@@ -406,7 +428,76 @@ __global__ __launch_bounds__(R4D_TOPK_WAVE * R4D_RERANK_WPB) void r4d_logit_rera
|
||||
const unsigned short* const sr = (const unsigned short*)(wr + (TB ? K / 8 * TB : K));
|
||||
[[maybe_unused]] const int8_t* const tab =
|
||||
(const int8_t*)(W + ((size_t)nv * w_ld + 255) / 256 * 256);
|
||||
for (long k = lane; k < K; k += R4D_TOPK_WAVE) {
|
||||
/* At K a multiple of 512 a lane takes sixteen consecutive columns of every 512, all in one
|
||||
* scale block: their products sum from zero in column order and the block's scale multiplies
|
||||
* that partial sum, the same arithmetic for every code form (an IQR head's scores are the
|
||||
* int8 head's to the bit). Byte codes on aligned planes load whole: R4D_RERANK_U steps are
|
||||
* in flight before the first is summed, where a column at a time is 80 loads in series at
|
||||
* K = 2560, each waiting for the last. */
|
||||
const bool ord = (K & 511) == 0;
|
||||
bool vec = false;
|
||||
if constexpr (TB == 0) vec = ord && ((size_t)X & 15) == 0 && ((size_t)W & 7) == 0;
|
||||
if constexpr (TB == 0) {
|
||||
for (long k0 = 16 * lane; vec && k0 < K; k0 += 512 * R4D_RERANK_U) {
|
||||
uint2 c[R4D_RERANK_U][2];
|
||||
uint4 xv[R4D_RERANK_U][2];
|
||||
uint32_t sv[R4D_RERANK_U];
|
||||
#pragma unroll
|
||||
for (int u = 0; u < R4D_RERANK_U; u++) {
|
||||
const long k = k0 + 512 * u;
|
||||
if (k < K) {
|
||||
const uint2* const pc = (const uint2*)(wr + k);
|
||||
const uint4* const px = (const uint4*)(xr + k);
|
||||
c[u][0] = pc[0]; c[u][1] = pc[1];
|
||||
xv[u][0] = px[0]; xv[u][1] = px[1];
|
||||
sv[u] = sr[k / 128];
|
||||
}
|
||||
}
|
||||
#pragma unroll
|
||||
for (int u = 0; u < R4D_RERANK_U; u++) {
|
||||
if (k0 + 512 * u < K) {
|
||||
const uint32_t cw[4] = { c[u][0].x, c[u][0].y, c[u][1].x, c[u][1].y };
|
||||
const uint32_t xw[8] = { xv[u][0].x, xv[u][0].y, xv[u][0].z, xv[u][0].w,
|
||||
xv[u][1].x, xv[u][1].y, xv[u][1].z, xv[u][1].w };
|
||||
float part = 0.0f;
|
||||
#pragma unroll
|
||||
for (int d = 0; d < 4; d++) {
|
||||
float f[4];
|
||||
if constexpr (I8) {
|
||||
#pragma unroll
|
||||
for (int q = 0; q < 4; q++) f[q] = (float)((int)(cw[d] << (24 - 8 * q)) >> 24);
|
||||
} else {
|
||||
const v2f lo = r4d_fp8::e4m3_pk<false>(cw[d]), hi = r4d_fp8::e4m3_pk<true>(cw[d]);
|
||||
f[0] = lo.x; f[1] = lo.y; f[2] = hi.x; f[3] = hi.y;
|
||||
}
|
||||
part = fmaf(f[0], __uint_as_float(xw[2 * d] << 16), part);
|
||||
part = fmaf(f[1], __uint_as_float(xw[2 * d] & 0xffff0000u), part);
|
||||
part = fmaf(f[2], __uint_as_float(xw[2 * d + 1] << 16), part);
|
||||
part = fmaf(f[3], __uint_as_float(xw[2 * d + 1] & 0xffff0000u), part);
|
||||
}
|
||||
acc = fmaf(part, r4d_fp8::bscale(sv[u]), acc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (long k0 = 16 * lane; ord && !vec && k0 < K; k0 += 512) {
|
||||
float part = 0.0f;
|
||||
#pragma unroll
|
||||
for (int q = 0; q < 16; q++) {
|
||||
const long k = k0 + q;
|
||||
float c;
|
||||
if constexpr (TB != 0) {
|
||||
const long bit = k * (long)TB;
|
||||
const uint32_t wv = (uint32_t)wr[bit >> 3] | (uint32_t)wr[(bit >> 3) + 1] << 8;
|
||||
c = (float)tab[(wv >> (bit & 7)) & ((1u << TB) - 1u)];
|
||||
} else {
|
||||
c = I8 ? (float)(int8_t)wr[k] : r4d_fp8::e4m3((uint32_t)wr[k]);
|
||||
}
|
||||
part = fmaf(c, bf16_to_f32(xr[k]), part);
|
||||
}
|
||||
acc = fmaf(part, r4d_fp8::bscale(sr[k0 / 128]), acc);
|
||||
}
|
||||
for (long k = ord ? K : lane; k < K; k += R4D_TOPK_WAVE) {
|
||||
float c;
|
||||
if constexpr (TB != 0) {
|
||||
const long bit = k * (long)TB;
|
||||
@@ -446,25 +537,39 @@ __global__ __launch_bounds__(R4D_TOPK_WAVE * R4D_RERANK_WPB) void r4d_logit_rera
|
||||
}
|
||||
}
|
||||
|
||||
// The kernel around the body: CH `r4dchain` is the chained form (r4d_chain.h), taken at decode
|
||||
// heights.
|
||||
template <bool I8, uint32_t TB, class CH>
|
||||
__global__ __launch_bounds__(R4D_TOPK_WAVE * R4D_RERANK_WPB)
|
||||
void r4d_logit_rerank_kernel(R4D_LOGIT_RERANK_PARAMS) {
|
||||
if (CH::on) r4d_chain_wait();
|
||||
r4d_logit_rerank_body<I8, TB>(X, IN, W, OI, OV, OP, R, K, voff, nv, w_ld);
|
||||
if (CH::on) r4d_chain_done();
|
||||
}
|
||||
#undef R4D_LOGIT_RERANK_PARAMS
|
||||
|
||||
static int logit_rerank_emit(long x, long idx_in, long head, long outi, long outv, long outp,
|
||||
int M, int R, long K, long voff, long nv, RadStream stream,
|
||||
bool i8, uint32_t tb = 0) {
|
||||
bool i8, uint32_t tb = 0, bool chain = false) {
|
||||
r4d_iqr::Form tf;
|
||||
tf.bits = tb;
|
||||
const long w_ld = tb ? (long)r4d_iqr::lm_row(tf, K) : r4d_fp8::lm_row_bytes(K);
|
||||
// R <= PT2 makes the re-sort exact for any scores (one lane holds the whole answer), so it is
|
||||
// checked, not clamped.
|
||||
if (M < 1 || R < 1 || K < 1 || nv < 1 || R > R4D_TOPK_PT2) return R4D_NO(RAD_E_SHAPE);
|
||||
#define R4D_RERANK_CH(I8, TB, CH_) \
|
||||
R4D_EMIT(stream, (r4d_logit_rerank_kernel<I8, TB, CH_>), dim3(M), \
|
||||
dim3(R4D_TOPK_WAVE * R4D_RERANK_WPB), 0, (const unsigned short*)x, \
|
||||
(const int*)idx_in, (const unsigned char*)head, (int*)outi, (float*)outv, \
|
||||
(float*)outp, R, K, voff, nv, w_ld)
|
||||
#define R4D_RERANK_EMIT(I8, TB) \
|
||||
R4D_EMIT(stream, (r4d_logit_rerank_kernel<I8, TB>), dim3(M), dim3(R4D_TOPK_WAVE * R4D_RERANK_WPB), \
|
||||
0, (const unsigned short*)x, (const int*)idx_in, (const unsigned char*)head, \
|
||||
(int*)outi, \
|
||||
(float*)outv, (float*)outp, R, K, voff, nv, w_ld)
|
||||
(chain ? R4D_RERANK_CH(I8, TB, r4dchain) : R4D_RERANK_CH(I8, TB, R4dUnchained))
|
||||
const int rc = tb == 2u ? R4D_RERANK_EMIT(true, 2) : tb == 3u ? R4D_RERANK_EMIT(true, 3)
|
||||
: tb == 4u ? R4D_RERANK_EMIT(true, 4) : tb == 5u ? R4D_RERANK_EMIT(true, 5)
|
||||
: tb == 6u ? R4D_RERANK_EMIT(true, 6)
|
||||
: i8 ? R4D_RERANK_EMIT(true, 0) : R4D_RERANK_EMIT(false, 0);
|
||||
#undef R4D_RERANK_EMIT
|
||||
#undef R4D_RERANK_CH
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -632,10 +737,7 @@ static int rad_logit_rerank(const RadArgs* a, RadStream stream, bool i8, bool iq
|
||||
|
||||
return logit_rerank_emit(r4d_addr(x), r4d_addr(in), r4d_addr(w), r4d_addr(idx), r4d_addr(val),
|
||||
pr ? r4d_addr(pr) : 0, (int)M, (int)R, (long)K, (long)voff, (long)NV,
|
||||
stream, i8, tb);
|
||||
}
|
||||
extern "C" int r4d_rad_logit_rerank(const RadArgs* a, RadStream stream) {
|
||||
return rad_logit_rerank(a, stream, false);
|
||||
stream, i8, tb, r4d_geti_or(a, "chain", 0) != 0 && M <= 64);
|
||||
}
|
||||
extern "C" int r4d_rad_logit_rerank_i8(const RadArgs* a, RadStream stream) {
|
||||
return rad_logit_rerank(a, stream, true);
|
||||
|
||||
Reference in new issue
Block a user