Archived
New models and formats: - IQR for Qwen3.8-27B: weights on the int8 grid under GPTQ, a trellis down each GPTQ column (IQR-V2), and IQR-V3, a computed trellis code under one scale a row, kept at its codes' width in VRAM and decoded in the GEMM; 15 IQR-V3 recipes from ~2 to ~7 bits a weight (data/recipes/q38-27b-*-v3.recipe, docs/IQR.md) - libhalo: a kernel library for Strix Halo (gfx1151), preferred there over libr3d - Nemotron 3.5 Embed 1B and 8B (nemotron35_embed): text and image embeddings through a Pixtral tower, on the card and on the CPU - Nemotron 3.5 Rerank 8B - /v1/systemone: Cloudflare's clef and clef-flash, Convai Innovations' Laya and Mica beside LiquidAI d1; scored steps read the candidates' logits from the head table with no lm_head pass - LFM2's 8-bit trunk: block-fp8 or int8 linears with the fused producers, and the d1-3B recipe - DeepSeek-V4.1's reply format with DSML tool calls and typed argument tags Weights on the drive: - The file tier reads only the experts the pass routes rows to; the draft head's weights stay in the host pool - A hot VRAM cache for routed experts read off the drive, reads deposited straight into free host pool slots, and copyless evictions; the file tier's counters are now ssd_* - GLM-5 Next shards its routed experts by expert, not by width, so they can live on the drive - The stall watch counts drive reads as progress, and the DMA lane's room check reads the lane's own completion fence Quantisation tooling: - --calib-corpus, --calib-dir and --calib-layers record each linear's input Hessian; beside --kld-record the reference's own run records them - --kld-top N records a sparse KL reference (the N most likely tokens and the tail's mass) - GPTQ in a third of the time with the same codes, trellis GPTQ on the card, vector codebooks with coordinate descent, and rad-convert --reuse repeated, each container supplying what the earlier ones lack Speculation: - Prompt lookup alone (--spec-ngram K, --spec-ngram-min/-max): each sequence keeps an index of its n-grams, and a proposal is verified only when its measured step cost says it pays; --draft-window adaptive follows it Speed: - IQR decode: the narrow tile splits K for four times the int8 tile's waves and folds each 128-K block once; at 8 tokens down and the output projections run in 0.61-0.82x and 0.70-0.92x FP8's time (2-6 bits); IQ6R-S-V3 with its DFlash2 drafter steps in 26.3 ms at TP2, against 29.4 ms before and FP8's 27.3 - Qwen MXFP4 feed-forward: the gated fold up to 16 rows, not 8 - libr4d: the gated prefill fold, the short-prompt split row, and the rows forms of rmsnorm and rope; KLATE again for the head-256 gqa6 paged prefill; gram_accum on the matrix cores Features: - /health, /v1/health and /ping answer 503 with "status": "stuck" once the device has advanced nothing for a minute or a queue has faulted, so a supervisor can restart a wedged server (#356) - --image-gen-max-pixels and --image-gen-max-refs size an image generator's buffers (#344) - The startup report lists only the options not at their default, with a count; -v lists all (#250) - --preempt-wait-ms bounds how long a preempted prefill waits for its whole-recompute room - --placement layer_offload spills dense layers so one --max-model-len sequence fits - Startup refuses amdgpu with CWSR off and says how to fix it; --proceed-with-incompatible-configuration starts anyway under an UNSUPPORTED banner Fixes: - The n-gram read-ahead hands each row to the reader once and reads only as far ahead as the row cache holds, and pauses while decode reads: about one drive read a row instead of two (#355) - A file-tier window reads each of its runs once, not once a run per run - The decode split law's verify floor is bounded by the batch's workgroups: max_seqs 256 no longer declares 64x the scratch (#342) - A prefetch DMA list's mark stays out of the signal pool until the engine has read it, and a prefill stage copies only the blocks its own tables name (#343) - The split-KV row sum is read with fetch-inactive (#328) - LFM2 on the host backend: libref and libavx serve the row-form ops it declares (#348) - The preempted-prefill gate skips a KV group that holds no blocks (#352) - Every request entry point bounded, gated and sanitised (JSON depth, invalid UTF-8, control bytes in the log, the dashboard's CSP, cross-origin browsers on the loopback-only routes); a prompt id outside the vocabulary refused at admission; --api-key "" refused at startup - The telemetry the HTTP thread reads is atomic - An RMS norm row no longer depends on how many rows its launch carries; prefill attention's rescale is decided by live rows only - A --kld-record prefill chunk that finishes no sequence gets its logits on a tied-head model - A kernel's lazily made counter block is zeroed outside the lock other ranks take (a TP2 first-step hang) Changes: Plugin ABI 32. Every plugin exports a layout fingerprint of the ABI structs and the loader refuses a plugin without it or with another (#302), so out-of-tree plugins must be rebuilt. Appended: RadBuildCtx calib_* and gen_max_*, RadArchProbe gen_max_*, RadBatch score_only and plugin_words, RadDeviceProps::unified, RadChatFormat arg_json_value_prefix.
166 lines
7.8 KiB
C++
166 lines
7.8 KiB
C++
/* Carried over from the strix-halo-vllm project's libhalo, where this layer was
|
|
* established and measured on the part; see libhalo/README.md. */
|
|
// Wave32 WMMA fragment algebra for gfx1151 / RDNA 3.5.
|
|
//
|
|
// This is the gfx11 counterpart of libr4d's gfx12 fragment layer, and it exists
|
|
// because the two architectures do NOT agree on how a wave32 WMMA fragment is
|
|
// spread over the wave:
|
|
//
|
|
// A / B per lane the k a lane's element e holds
|
|
// gfx1201 (RDNA4) 8 bf16 (v[0:3]) k = 8*(e>>2) + 4*(lane>>4) + (e&3)
|
|
// gfx1151 (RDNA3.5) 16 bf16 (v[0:7]) k = e
|
|
//
|
|
// RDNA 3.5 replicates each operand row across both halves of the wave, so a lane
|
|
// holds the WHOLE 16-wide k run; RDNA4 splits it. Every fragment gather ported
|
|
// from libr4d therefore loses its half-wave term -- the port is a simplification
|
|
// at the gather sites, and a change of row mapping at the result.
|
|
//
|
|
// The layout below was established on the part itself by bench/wmma_layout_probe.hip,
|
|
// which tests candidate mappings against a host matmul and finds exactly one with
|
|
// zero error (the others are off by ~350 on the same data). Do not "fix" any of it
|
|
// from a vendor doc -- rerun the probe.
|
|
//
|
|
// A: lane l holds row (l & 15) of A; element e is k = e (lanes 16-31 replicate)
|
|
// B: lane l holds col (l & 15) of B; element e is k = e
|
|
// D: lane l, element e -> D[2*e + (l>>4)][l & 15]
|
|
//
|
|
// Note what the D mapping preserves: the COLUMN is still (lane & 15). libr4d's
|
|
// attention kernels are built around a transposed score matrix S^T = K.Q^T so that
|
|
// a fragment gives each lane exactly one query row and the softmax is lane-private.
|
|
// That property survives here unchanged, which is why those kernels are portable
|
|
// at all.
|
|
#pragma once
|
|
#include <hip/hip_runtime.h>
|
|
#include <cstdint>
|
|
#include "halo_common.h"
|
|
|
|
/* Byte order of stored fp8 weights along k, inside each group of four, and which
|
|
* e4m3 -> bf16 unpack deq16_e4m3 below compiles. In the vLLM libhalo these lived
|
|
* in its halo_common.h; here the stored layout is radiance's own (halo_layout.cpp
|
|
* chooses it at load), so the swizzled order is available when a relayout asks
|
|
* for it. Defaults: natural order, perm-input unpack. */
|
|
#ifndef HALO_FP8_SWIZ
|
|
#define HALO_FP8_SWIZ 0
|
|
#endif
|
|
#ifndef HALO_FP8_DEQ
|
|
#define HALO_FP8_DEQ 1
|
|
#endif
|
|
|
|
typedef __bf16 v16bf __attribute__((ext_vector_type(16)));
|
|
typedef __fp16 v16hf __attribute__((ext_vector_type(16))); // what the f16 WMMA builtin takes
|
|
typedef float v8f __attribute__((ext_vector_type(8)));
|
|
typedef float v2f __attribute__((ext_vector_type(2)));
|
|
|
|
namespace halo {
|
|
|
|
// ---- where a lane's data lives ------------------------------------------------
|
|
__device__ __forceinline__ int a_row(int lane) { return lane & 15; }
|
|
__device__ __forceinline__ int b_col(int lane) { return lane & 15; }
|
|
__device__ __forceinline__ int d_col(int lane) { return lane & 15; }
|
|
__device__ __forceinline__ int d_row(int lane, int e) { return 2 * e + (lane >> 4); }
|
|
// The half a lane sits in. On gfx12 this selects which k it loads; here it selects
|
|
// only which D rows it receives, and the gather does not use it.
|
|
__device__ __forceinline__ int half(int lane) { return lane >> 4; }
|
|
|
|
// ---- the instruction ----------------------------------------------------------
|
|
__device__ __forceinline__ v8f mma(v16bf a, v16bf b, v8f c) {
|
|
return __builtin_amdgcn_wmma_f32_16x16x16_bf16_w32(a, b, c);
|
|
}
|
|
__device__ __forceinline__ v8f mma(v16hf a, v16hf b, v8f c) {
|
|
return __builtin_amdgcn_wmma_f32_16x16x16_f16_w32(a, b, c);
|
|
}
|
|
|
|
// ---- building a fragment ------------------------------------------------------
|
|
// From eight dwords, i.e. a lane's full 16-wide k run already packed as 16-bit
|
|
// pairs. This is the gfx11 replacement for libr4d's DT16::mk(uint2 lo, uint2 hi):
|
|
// twice the payload, and no half-wave selection.
|
|
template <typename FRAG>
|
|
__device__ __forceinline__ FRAG mk(const uint32_t w[8]) {
|
|
union { uint32_t u[8]; FRAG f; } q;
|
|
#pragma unroll
|
|
for (int i = 0; i < 8; ++i) q.u[i] = w[i];
|
|
return q.f;
|
|
}
|
|
|
|
// From a 32-byte-aligned pointer to 16 contiguous 16-bit values -- the common case
|
|
// once the half-wave split is gone, and two dwordx4 loads.
|
|
template <typename FRAG>
|
|
__device__ __forceinline__ FRAG mk_ldg(const void* p) {
|
|
union { uint4 v[2]; FRAG f; } q;
|
|
q.v[0] = *(const uint4*)p;
|
|
q.v[1] = *((const uint4*)p + 1);
|
|
return q.f;
|
|
}
|
|
|
|
// f32 -> bf16, round-to-nearest-even. gfx1151 has no v_cvt_pk_bf16_f32 either, so
|
|
// this stays the software form libr4d uses.
|
|
__device__ __forceinline__ uint16_t f32_to_bf16(float f) {
|
|
uint32_t u = __builtin_bit_cast(uint32_t, f);
|
|
return (uint16_t)((u + 0x7fffu + ((u >> 16) & 1u)) >> 16);
|
|
}
|
|
__device__ __forceinline__ uint32_t pk_bf16(float x, float y) {
|
|
return (uint32_t)f32_to_bf16(x) | ((uint32_t)f32_to_bf16(y) << 16);
|
|
}
|
|
// f16 packs in ONE instruction, which is why libr4d prefers it on the softmax path.
|
|
__device__ __forceinline__ uint32_t pk_f16(float x, float y) {
|
|
typedef __fp16 v2hf __attribute__((ext_vector_type(2))); // what cvt_pkrtz returns
|
|
union { v2hf h; uint32_t u; } q;
|
|
q.h = __builtin_amdgcn_cvt_pkrtz(x, y);
|
|
return q.u;
|
|
}
|
|
|
|
// Exchange a value with the lane 16 away -- the two halves a D fragment splits its
|
|
// rows across. The one cross-lane step the transposed-score formulation needs.
|
|
__device__ __forceinline__ float swap16(float x) { return __shfl_xor(x, 16, 32); }
|
|
__device__ __forceinline__ uint32_t swap16_u(uint32_t x) {
|
|
return __builtin_bit_cast(uint32_t, swap16(__builtin_bit_cast(float, x)));
|
|
}
|
|
|
|
// ---- e4m3 -> bf16, one B fragment (16 bytes) ----------------------------------
|
|
// The single copy. It used to be inlined in halo_moe_fp8_group and again in
|
|
// halo_gemm_fp8_nt, and the two had already drifted; they are the same sixteen
|
|
// bytes becoming the same fragment, so they are the same function.
|
|
//
|
|
// A dword holds four e4m3 and must become two dwords of two bf16. Bytes 0 and 2
|
|
// sit at bit 0 and bit 16, so ONE left shift moves both their payloads and one
|
|
// more moves both their signs; bytes 1 and 3 sit at bit 8 and 24 and one right
|
|
// shift serves both of theirs. Four instructions place all four values -- but
|
|
// that pairs k with k+2, and WMMA wants k with k+1.
|
|
//
|
|
// v_perm_b32 fixes the pairing on the INPUT for one instruction: reorder the
|
|
// dword to (b0, b2, b1, b3) and the natural output of the two shifts IS k
|
|
// order. Eight instructions per dword against the twelve the mask-and-restitch
|
|
// version needs (ten bit ops plus two v_mov_b16 the register allocator adds),
|
|
// and -- unlike doing it in storage -- it needs no change to the stored
|
|
// weights, which is what makes it shippable: the layout belongs to vLLM's
|
|
// Triton fused_experts, which reads the same tensors on every prefill.
|
|
//
|
|
// The exponent is NOT biased. Every value comes out low by exactly 2^-120,
|
|
// which the caller folds into the block scale as HALO_FP8_FIX; see docs/31.
|
|
__device__ __forceinline__ v16bf deq16_e4m3(const uint32_t* __restrict__ w4) {
|
|
union { uint32_t u[8]; v16bf f; } q;
|
|
#pragma unroll
|
|
for (int d = 0; d < 4; ++d) {
|
|
const uint32_t w = w4[d];
|
|
#if !HALO_FP8_DEQ
|
|
// The control: mask each byte in place, then restitch the halves into k
|
|
// order. Ten bit ops, and the allocator adds two v_mov_b16 on top.
|
|
const uint32_t lo = ((w & 0x007F007Fu) << 4) | ((w & 0x00800080u) << 8);
|
|
const uint32_t hi = ((w & 0x7F007F00u) >> 4) | (w & 0x80008000u);
|
|
q.u[d * 2 + 0] = (lo & 0x0000FFFFu) | (hi << 16);
|
|
q.u[d * 2 + 1] = (lo >> 16) | (hi & 0xFFFF0000u);
|
|
#else
|
|
#if HALO_FP8_SWIZ
|
|
const uint32_t x = w; // stored (k0, k2, k1, k3): no perm needed
|
|
#else
|
|
const uint32_t x = __builtin_amdgcn_perm(w, w, 0x03010200u);
|
|
#endif
|
|
q.u[d * 2 + 0] = ((x << 8) & 0x80008000u) | ((x << 4) & 0x07F007F0u);
|
|
q.u[d * 2 + 1] = (x & 0x80008000u) | ((x >> 4) & 0x07F007F0u);
|
|
#endif
|
|
}
|
|
return q.f;
|
|
}
|
|
|
|
} // namespace halo
|