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
@@ -47,10 +47,15 @@ constexpr uint32_t kGroup = 128;
|
||||
//
|
||||
// CHAIN brackets the body with the chained launch's wait and add (r4d_chain.h); no block returns
|
||||
// early. quant_act_fp8_kernel and r4dchain_quant_act_fp8 below are the plain and chained forms.
|
||||
template <bool ROT, bool I8 = false, bool CHAIN = false>
|
||||
//
|
||||
// SUB is the 128-column blocks one scale covers: 1, or 2 for IQ8R's 256-wide group (int8 only),
|
||||
// where a wave owns both blocks of a group, rotates each on its own (the rotation stays 128 wide)
|
||||
// and takes the amax over the pair. `nkb` counts scale groups.
|
||||
template <bool ROT, bool I8 = false, bool CHAIN = false, uint32_t SUB = 1>
|
||||
__device__ __forceinline__ void quant_act_fp8_body(
|
||||
const uint16_t* __restrict__ x, uint8_t* __restrict__ q, float* __restrict__ s,
|
||||
uint32_t K, uint32_t nkb, uint32_t x_ld, uint32_t q_ld, uint32_t s_ld) {
|
||||
static_assert(SUB == 1 || (SUB == 2 && I8), "a 256 group is the int8 quantiser's");
|
||||
if (CHAIN) r4d_chain_wait();
|
||||
const uint32_t row = blockIdx.x;
|
||||
const uint32_t lane = threadIdx.x & (kWave - 1), wave = threadIdx.x / kWave;
|
||||
@@ -58,57 +63,64 @@ __device__ __forceinline__ void quant_act_fp8_body(
|
||||
const size_t qrow = (size_t)row * q_ld;
|
||||
|
||||
for (uint32_t kb = wave; kb < nkb; kb += kWaves) {
|
||||
const uint32_t c0 = kb * kGroup + lane * 4u;
|
||||
float v[4];
|
||||
float v[SUB][4];
|
||||
float m = 0.0f;
|
||||
#pragma unroll
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
const uint32_t c = c0 + (uint32_t)j;
|
||||
v[j] = c < K ? __uint_as_float((uint32_t)x[xrow + c] << 16) : 0.0f;
|
||||
}
|
||||
// The rotated launcher requires K % 128 == 0: a partial block would rotate real values
|
||||
// with padding zeros, and the weight has no matching block.
|
||||
if constexpr (ROT) r4d_fwht_wave<(int)kGroup>(v, (int)lane);
|
||||
for (uint32_t h = 0; h < SUB; ++h) {
|
||||
const uint32_t c0 = (kb * SUB + h) * kGroup + lane * 4u;
|
||||
#pragma unroll
|
||||
for (int j = 0; j < 4; ++j) m = fmaxf(m, fabsf(v[j]));
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
const uint32_t c = c0 + (uint32_t)j;
|
||||
v[h][j] = c < K ? __uint_as_float((uint32_t)x[xrow + c] << 16) : 0.0f;
|
||||
}
|
||||
// The rotated launcher requires K % 128 == 0: a partial block would rotate real values
|
||||
// with padding zeros, and the weight has no matching block.
|
||||
if constexpr (ROT) r4d_fwht_wave<(int)kGroup>(v[h], (int)lane);
|
||||
#pragma unroll
|
||||
for (int j = 0; j < 4; ++j) m = fmaxf(m, fabsf(v[h][j]));
|
||||
}
|
||||
m = r4d_wave_max(m);
|
||||
constexpr float kTop = I8 ? 127.0f : 448.0f;
|
||||
const float sc = m > 0.0f ? m * (1.0f / kTop) : 1.0f;
|
||||
if (lane == 0) s[(size_t)row * s_ld + kb] = sc;
|
||||
const float inv = 1.0f / sc;
|
||||
int pk = 0;
|
||||
if constexpr (I8) {
|
||||
uint32_t b = 0;
|
||||
#pragma unroll
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
const int c = (int)rintf(fminf(fmaxf(v[j] * inv, -127.0f), 127.0f));
|
||||
b |= ((uint32_t)c & 0xFFu) << (8 * j);
|
||||
for (uint32_t h = 0; h < SUB; ++h) {
|
||||
const uint32_t c0 = (kb * SUB + h) * kGroup + lane * 4u;
|
||||
int pk = 0;
|
||||
if constexpr (I8) {
|
||||
uint32_t b = 0;
|
||||
#pragma unroll
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
const int c = (int)rintf(fminf(fmaxf(v[h][j] * inv, -127.0f), 127.0f));
|
||||
b |= ((uint32_t)c & 0xFFu) << (8 * j);
|
||||
}
|
||||
pk = (int)b;
|
||||
} else {
|
||||
pk = __builtin_amdgcn_cvt_pk_fp8_f32(fminf(fmaxf(v[h][0] * inv, -448.0f), 448.0f),
|
||||
fminf(fmaxf(v[h][1] * inv, -448.0f), 448.0f),
|
||||
pk, false);
|
||||
pk = __builtin_amdgcn_cvt_pk_fp8_f32(fminf(fmaxf(v[h][2] * inv, -448.0f), 448.0f),
|
||||
fminf(fmaxf(v[h][3] * inv, -448.0f), 448.0f),
|
||||
pk, true);
|
||||
}
|
||||
pk = (int)b;
|
||||
} else {
|
||||
pk = __builtin_amdgcn_cvt_pk_fp8_f32(fminf(fmaxf(v[0] * inv, -448.0f), 448.0f),
|
||||
fminf(fmaxf(v[1] * inv, -448.0f), 448.0f), pk,
|
||||
false);
|
||||
pk = __builtin_amdgcn_cvt_pk_fp8_f32(fminf(fmaxf(v[2] * inv, -448.0f), 448.0f),
|
||||
fminf(fmaxf(v[3] * inv, -448.0f), 448.0f), pk,
|
||||
true);
|
||||
// A ragged last group is written zero-padded; the GEMM's bounds guard keeps the
|
||||
// padding out of the accumulators. The caller must own K rounded up to 4 bytes of `q`.
|
||||
if (c0 < K) *(uint32_t*)(q + qrow + c0) = (uint32_t)pk;
|
||||
}
|
||||
// A ragged last group is written zero-padded; the GEMM's bounds guard keeps the padding out
|
||||
// of the accumulators. The caller must own K rounded up to 4 bytes of `q`.
|
||||
if (c0 < K) *(uint32_t*)(q + qrow + c0) = (uint32_t)pk;
|
||||
}
|
||||
if (CHAIN) r4d_chain_done();
|
||||
}
|
||||
|
||||
#define R4D_QAF_PARAMS const uint16_t* __restrict__ x, uint8_t* __restrict__ q, \
|
||||
float* __restrict__ s, uint32_t K, uint32_t nkb, uint32_t x_ld, uint32_t q_ld, uint32_t s_ld
|
||||
template <bool ROT, bool I8 = false>
|
||||
template <bool ROT, bool I8 = false, uint32_t SUB = 1>
|
||||
__global__ __launch_bounds__(kThreads) void quant_act_fp8_kernel(R4D_QAF_PARAMS) {
|
||||
quant_act_fp8_body<ROT, I8, false>(x, q, s, K, nkb, x_ld, q_ld, s_ld);
|
||||
quant_act_fp8_body<ROT, I8, false, SUB>(x, q, s, K, nkb, x_ld, q_ld, s_ld);
|
||||
}
|
||||
template <bool ROT, bool I8 = false>
|
||||
template <bool ROT, bool I8 = false, uint32_t SUB = 1>
|
||||
__global__ __launch_bounds__(kThreads) void r4dchain_quant_act_fp8(R4D_QAF_PARAMS) {
|
||||
quant_act_fp8_body<ROT, I8, true>(x, q, s, K, nkb, x_ld, q_ld, s_ld);
|
||||
quant_act_fp8_body<ROT, I8, true, SUB>(x, q, s, K, nkb, x_ld, q_ld, s_ld);
|
||||
}
|
||||
#undef R4D_QAF_PARAMS
|
||||
|
||||
@@ -121,29 +133,33 @@ extern "C" int r4d_quant_act_fp8_group(void) { return (int)kGroup; }
|
||||
// s [M][ceil(K/128)] f32, `s_ld` elements a row (0 = ceil(K/128))
|
||||
//
|
||||
// `rot` runs the 128-wide Hadamard first and additionally requires K % 128 == 0 (see the kernel).
|
||||
// `wide` (int8 only): one scale per 256 columns (IQ8R), K a multiple of 256, `s` [M][K/256].
|
||||
static int quant_act_fp8_launch(long a, long q, long s, int M, int K,
|
||||
int x_ld, int q_ld, int s_ld, RadStream stream, bool rot,
|
||||
bool i8 = false, bool chain = false) {
|
||||
bool i8 = false, bool chain = false, bool wide = false) {
|
||||
int emit_rc = RAD_OK;
|
||||
if (!a || !q || !s) return -1;
|
||||
if (M <= 0 || K <= 0) return -2;
|
||||
if (K % 4) return -3; // a lane owns four columns; see the kernel
|
||||
if (rot && (K % (int)kGroup)) return -5;
|
||||
if (wide && (!i8 || K % (2 * (int)kGroup))) return -5;
|
||||
if (!x_ld) x_ld = K;
|
||||
if (!q_ld) q_ld = K;
|
||||
const int nkb = (K + (int)kGroup - 1) / (int)kGroup;
|
||||
const int grp = wide ? 2 * (int)kGroup : (int)kGroup;
|
||||
const int nkb = (K + grp - 1) / grp;
|
||||
if (!s_ld) s_ld = nkb;
|
||||
/* The chained form at decode heights, where the row resolved with `chain`. */
|
||||
const bool ch = chain && M <= 64;
|
||||
#define R4D_QA(ROT_, I8_) \
|
||||
(ch ? R4D_EMIT(stream, (r4dchain_quant_act_fp8<ROT_, I8_>), dim3((uint32_t)M), \
|
||||
#define R4D_QA(ROT_, I8_, SUB_) \
|
||||
(ch ? R4D_EMIT(stream, (r4dchain_quant_act_fp8<ROT_, I8_, SUB_>), dim3((uint32_t)M), \
|
||||
dim3(kThreads), 0, (const uint16_t*)a, (uint8_t*)q, (float*)s, (uint32_t)K, \
|
||||
(uint32_t)nkb, (uint32_t)x_ld, (uint32_t)q_ld, (uint32_t)s_ld) \
|
||||
: R4D_EMIT(stream, (quant_act_fp8_kernel<ROT_, I8_>), dim3((uint32_t)M), \
|
||||
: R4D_EMIT(stream, (quant_act_fp8_kernel<ROT_, I8_, SUB_>), dim3((uint32_t)M), \
|
||||
dim3(kThreads), 0, (const uint16_t*)a, (uint8_t*)q, (float*)s, (uint32_t)K, \
|
||||
(uint32_t)nkb, (uint32_t)x_ld, (uint32_t)q_ld, (uint32_t)s_ld))
|
||||
if (i8) emit_rc = rot ? R4D_QA(true, true) : R4D_QA(false, true);
|
||||
else emit_rc = rot ? R4D_QA(true, false) : R4D_QA(false, false);
|
||||
if (wide) emit_rc = rot ? R4D_QA(true, true, 2u) : R4D_QA(false, true, 2u);
|
||||
else if (i8) emit_rc = rot ? R4D_QA(true, true, 1u) : R4D_QA(false, true, 1u);
|
||||
else emit_rc = rot ? R4D_QA(true, false, 1u) : R4D_QA(false, false, 1u);
|
||||
#undef R4D_QA
|
||||
if (emit_rc != RAD_OK) return -4;
|
||||
return (hipGetLastError() != hipSuccess) ? -4 : 0;
|
||||
@@ -155,12 +171,6 @@ extern "C" int r4d_quant_act_fp8(long a, long q, long s, int M, int K,
|
||||
(RadStream)(uintptr_t)stream, false);
|
||||
}
|
||||
|
||||
extern "C" int r4d_had_quant_act_fp8(long a, long q, long s, int M, int K,
|
||||
int x_ld, int q_ld, int s_ld, long stream) {
|
||||
return quant_act_fp8_launch(a, q, s, M, K, x_ld, q_ld, s_ld,
|
||||
(RadStream)(uintptr_t)stream, true);
|
||||
}
|
||||
|
||||
// ============================================================== the plugin ABI entry points
|
||||
//
|
||||
// The shared operand reader is r4d_fp8_args.h; see libr4d/r4d_args.h.
|
||||
@@ -177,17 +187,20 @@ static int rad_quant_act_fp8(const RadArgs* a, RadStream stream, bool rot, bool
|
||||
* `q` and `sc` are written for the GEMM and stay rank 2. */
|
||||
if (x->rank < 2 || q->rank != 2 || sc->rank != 2) return R4D_NO(RAD_E_SHAPE);
|
||||
const long long M = x->shape[0], K = r4d_numel(x) / (x->shape[0] > 0 ? x->shape[0] : 1);
|
||||
const long long grp = r4d_quant_act_fp8_group();
|
||||
/* The group is fixed by the weight's scale grid: 128, or 256 for the int8 quantisers (IQ8R).
|
||||
* Any other declared group is refused. */
|
||||
const long long g0 = r4d_quant_act_fp8_group();
|
||||
const long long grp = r4d_geti_or(a, "group", g0);
|
||||
const bool wide = i8 && grp == R4D_I8_GROUP_WIDE;
|
||||
if (grp != g0 && !wide) return R4D_NO(RAD_E_SHAPE);
|
||||
const long long nkb = (K + grp - 1) / grp;
|
||||
/* The group is fixed by the checkpoint's scale grid; a different declared group is refused. */
|
||||
if (r4d_geti_or(a, "group", grp) != grp) return R4D_NO(RAD_E_SHAPE);
|
||||
if (q->shape[0] != M || q->shape[1] != K) return R4D_NO(RAD_E_SHAPE);
|
||||
if (sc->shape[0] != M || sc->shape[1] != nkb) return R4D_NO(RAD_E_SHAPE);
|
||||
const long long xp = r4d_row_pitch(x), qp = r4d_row_pitch(q), sp = r4d_row_pitch(sc);
|
||||
if (xp < 0 || qp < 0 || sp < 0) return R4D_NO(RAD_E_STRIDE);
|
||||
const int e = quant_act_fp8_launch(r4d_addr(x), r4d_addr(q), r4d_addr(sc), (int)M, (int)K,
|
||||
(int)xp, (int)qp, (int)sp, stream, rot, i8,
|
||||
r4d_geti_or(a, "chain", 0) != 0);
|
||||
r4d_geti_or(a, "chain", 0) != 0, wide);
|
||||
return e == 0 ? RAD_OK : RAD_E_SHAPE;
|
||||
}
|
||||
|
||||
@@ -195,14 +208,6 @@ extern "C" int r4d_rad_quant_act_fp8(const RadArgs* a, RadStream stream) {
|
||||
return rad_quant_act_fp8(a, stream, false);
|
||||
}
|
||||
|
||||
/* The rotated form is a separate op, not a parameter: it writes different numbers, so a swapped
|
||||
* graph would still run as a different model. The op name pairs with the weight's layout tag in
|
||||
* arch/common/rad_block_moe_fp8.h. It pairs only with the `w4a8h` expert plane; any consumer not
|
||||
* rotated at convert reads it as noise. */
|
||||
extern "C" int r4d_rad_had_quant_act_fp8(const RadArgs* a, RadStream stream) {
|
||||
return rad_quant_act_fp8(a, stream, true);
|
||||
}
|
||||
|
||||
/* The int8 pair, for the int8 trunk GEMMs (gemm_i8a8_*). Separate ops for the same reason as the
|
||||
* rotated form: different numbers in a buffer of the same shape. */
|
||||
extern "C" int r4d_rad_quant_act_i8g(const RadArgs* a, RadStream stream) {
|
||||
|
||||
Reference in new issue
Block a user