Archived
radiance 1.9.0
New models: - LTX-2.5 (base and distilled): video with a stereo soundtrack from text or from text and a first frame, on one card, with its duration head, tiled VAE decoding, the diffusion decoder and the x2 latent upsampler - Krea 2 Raw and Turbo, and FLUX.3 [klein] and its base: text to image, and for FLUX.3 edits from up to ten reference pictures, on one card - GLM-5.3-Flash from AMD's Quark MXFP4 export, on eight cards (John McDonough, Nunze) - Gemma 3 / TranslateGemma 27B with an optional DFlash2 drafter (mici81) Engine: - --kv-cache-dtype fp8_v4 and k6_v4 for Gemma 3 and Qwen3.8-Flash-Next (mici81) - the rotated int8 trunk (i8a8h) for Qwen3.8-27B (eddie168168) - eight-rank all-reduce bands, weighted shards and pieces (Nunze); --host-headroom-mib (sfjes) - the dashboard shows the single-stream decode floor and its most recent window (Memoria) Fixes: prefix-cache reservations kept until their save lands (baKon), tool calls in Responses namespaces (#119), system messages merged when a template refuses several (#137), a prefill continued with no open step (#127), calibration of a Gram accumulation (#122), JSON Schema patterns read unanchored (davetha), GLM-style tool calls, the KV floor counting every sequence's state. Plugin ABI 24.
This commit is contained in:
1 parent
778cbf315e
commit
685ec5bd85
136 files changed
+18917
-3821
No files matched your search
+129
-229
@@ -1,30 +1,28 @@
|
||||
/* tests/r4d_emu: the MXFP4 expert GEMM (r4d_moe_mxfp4.hip) on the host SIMT emulator. Every form
|
||||
* the RADIANCE_MXFP4_* switches reach must match the arithmetic-decode row-group form bit for bit,
|
||||
* and both a host restatement of the per-element sequence: per 128 of K in order, per 32-wide group
|
||||
* a fresh 32-product sum in k order (the emulated WMMA pair), folded as raw * activation scale *
|
||||
* E8M0 scale with two roundings and an add. Runs of 0, 1, 15, 16, 17, 63, 64, 65 and 130 rows,
|
||||
* dropped slots inside runs and past the routed rows, columns an odd expert does not have, a
|
||||
* shorter K for odd experts, E8M0 codes 0 and 255, parts 2, token and sorted rows, stacked planes
|
||||
* and pointer tables. The P64 forms (RADIANCE_MXFP4_PREFILL_P64) run at every BM, BN, stage and
|
||||
* column-tile count, pinned below their row bound, with jobs cut at 32 and 64 rows, column
|
||||
* blocks past N and the output through LDS at aligned and odd pitches. The table decode is also
|
||||
* held to the arithmetic one over every code. */
|
||||
/* tests/r4d_emu: the MXFP4 expert GEMM (r4d_moe_mxfp4.hip) on the host SIMT emulator. The form the
|
||||
* rule picks at each case (named per case, so a moved bound shows) must match a host restatement
|
||||
* of the per-element sequence bit for bit: per 128 of K in order, per 32-wide group a fresh
|
||||
* 32-product sum in k order (the emulated WMMA pair), folded as raw * activation scale * E8M0
|
||||
* scale with two roundings and an add. Away from GLM's slices the expert-major forms (K 256 and a
|
||||
* longer K) and the row groups; at GLM's TP4 down slice the GLM prefill form, at its TP8 gate_up
|
||||
* slice the P64 form with streamed A. Runs of 0, 1, 15, 16, 17, 63, 64, 65 and 130 rows, dropped
|
||||
* slots inside runs and past the routed rows, columns an odd expert does not have, a shorter K for
|
||||
* odd experts, E8M0 codes 0 and 255, parts 2, token and sorted rows, stacked planes and pointer
|
||||
* tables. The table decode is also held to the arithmetic one over every code. */
|
||||
#include "rad_abi.h"
|
||||
#include "rad_plugin.h"
|
||||
#include "r4d_plugin.h"
|
||||
#include "r4d_mxfp4.h"
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
extern const char* emu_last_kernel;
|
||||
|
||||
/* The arithmetic decode the kernels used before the table (r4d_moe_mxfp4.hip, fp4x4 and its
|
||||
* byte interleave), restated as the reference of r4d_mxfp4_unpack8_exact. */
|
||||
/* The bytewise arithmetic decode, the reference of r4d_mxfp4_unpack8_exact: per byte, magnitudes
|
||||
* from 2 map to (m + 12) * 4, 0 and 1 to 0 and 48, the sign to bit 7; then the low and high
|
||||
* nibbles' bytes interleave in k order. */
|
||||
static uint32_t fp4x4_ref(uint32_t n) {
|
||||
const uint32_t mag = n & 0x07070707u, flag = (mag + 0x06060606u) & 0x08080808u;
|
||||
const uint32_t mask = (flag << 5) - (flag >> 3);
|
||||
@@ -76,6 +74,7 @@ struct Case {
|
||||
bool sorted_a, tables, exceptional;
|
||||
std::vector<int> runs;
|
||||
int tail; // dropped slots past the routed rows
|
||||
const char* kernel; // the form the rule picks
|
||||
};
|
||||
|
||||
/* Byte equality with every bf16 NaN taken as one value. On x86 inf - inf gives the negative
|
||||
@@ -87,9 +86,6 @@ static size_t first_diff(const std::vector<uint16_t>& a, const std::vector<uint1
|
||||
if (a[i] != b[i] && !(nan16(a[i]) && nan16(b[i]))) return i;
|
||||
return a.size() == b.size() ? a.size() : std::min(a.size(), b.size());
|
||||
}
|
||||
static bool same16(const std::vector<uint16_t>& a, const std::vector<uint16_t>& b) {
|
||||
return a.size() == b.size() && first_diff(a, b) == a.size();
|
||||
}
|
||||
|
||||
static RadTensor ten(void* p, uint32_t dt, std::vector<int64_t> shape,
|
||||
std::vector<int64_t> stride) {
|
||||
@@ -104,18 +100,30 @@ static RadTensor ten(void* p, uint32_t dt, std::vector<int64_t> shape,
|
||||
return t;
|
||||
}
|
||||
|
||||
/* GLM's 288 experts: the given runs at experts spread over both classes, every other one empty. */
|
||||
static std::vector<int> glm_runs(std::vector<int> live) {
|
||||
static const int at[] = { 2, 3, 50, 101, 150, 199, 200, 241, 286, 287 };
|
||||
std::vector<int> runs(288, 0);
|
||||
for (size_t i = 0; i < live.size() && i < sizeof at / sizeof at[0]; ++i) runs[at[i]] = live[i];
|
||||
return runs;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int fails = check_decode(), cases = 1;
|
||||
if (fails) std::printf("FAIL table decode: %d mismatches\n", fails);
|
||||
|
||||
const std::vector<int> runs9 = { 0, 1, 15, 16, 17, 63, 64, 65, 130, 141 };
|
||||
const char* const staged = "(moe_mxfp4_expert_staged_kernel<128, 4>)";
|
||||
const char* const expert = "(moe_mxfp4_expert_kernel<4, 256>)";
|
||||
const char* const groups = "moe_mxfp4_fp8_kernel";
|
||||
const Case all[] = {
|
||||
{ "gate_up-like, token rows", 128, 384, 128, 384, 2, 4, false, false, false, runs9, 6 },
|
||||
{ "gate_up-like, token rows", 128, 384, 128, 384, 2, 4, false, false, false, runs9, 6,
|
||||
groups },
|
||||
{ "odd experts narrower and shorter", 128, 384, 64, 256, 2, 4, false, true, false, runs9,
|
||||
2 },
|
||||
{ "down-like, sorted rows", 64, 256, 64, 256, 1, 2, true, true, false, runs9, 4 },
|
||||
{ "exceptional E8M0 codes", 64, 256, 64, 256, 2, 4, false, false, true, runs9, 4 },
|
||||
{ "decode band, row groups of 4",
|
||||
2, groups },
|
||||
{ "down-like, sorted rows", 64, 256, 64, 256, 1, 2, true, true, false, runs9, 4, groups },
|
||||
{ "exceptional E8M0 codes", 64, 256, 64, 256, 2, 4, false, false, true, runs9, 4, groups },
|
||||
{ "expert-major, K 384",
|
||||
64,
|
||||
384,
|
||||
64,
|
||||
@@ -126,8 +134,9 @@ int main() {
|
||||
true,
|
||||
false,
|
||||
{ 0, 1, 15, 16, 17, 30 },
|
||||
3 },
|
||||
{ "decode band, row groups of 1",
|
||||
3,
|
||||
expert },
|
||||
{ "expert-major, K 256, exceptional codes",
|
||||
64,
|
||||
256,
|
||||
32,
|
||||
@@ -138,8 +147,9 @@ int main() {
|
||||
false,
|
||||
true,
|
||||
{ 1, 0, 3, 15, 1 },
|
||||
2 },
|
||||
{ "P64 jobs at 32 and 64 rows, N under a block",
|
||||
2,
|
||||
staged },
|
||||
{ "expert-major, K 512:384, runs past 64 rows, N under a block",
|
||||
96,
|
||||
512,
|
||||
96,
|
||||
@@ -150,8 +160,9 @@ int main() {
|
||||
false,
|
||||
false,
|
||||
{ 32, 33, 31, 96, 128, 129, 0, 2 },
|
||||
9 },
|
||||
{ "P64 resident A, column tiles cut",
|
||||
9,
|
||||
expert },
|
||||
{ "expert-major, K 256:128, column tiles cut",
|
||||
192,
|
||||
256,
|
||||
128,
|
||||
@@ -162,83 +173,47 @@ int main() {
|
||||
true,
|
||||
true,
|
||||
{ 64, 63, 65, 1, 0, 127, 17 },
|
||||
5 },
|
||||
};
|
||||
struct Form {
|
||||
const char* env;
|
||||
int stage, tiles, lut;
|
||||
const char* kernel;
|
||||
bool prefill;
|
||||
bool pipe = false;
|
||||
};
|
||||
/* env: DECODE_EXPERTS, ALIGNED_JOBS, PREFILL_N32, PREFILL_M32, PREFILL_N64, PREFILL_CACHE_ROWS */
|
||||
const Form forms[] = {
|
||||
{ "100000", 256, 1, 0, "moe_mxfp4_expert_kernel<4, 256, false>", false },
|
||||
{ "100000", 256, 1, 1, "moe_mxfp4_expert_kernel<4, 256, true>", false },
|
||||
{ "100000", 256, 4, 0, "moe_mxfp4_expert_staged_kernel<256, 4, false>", false },
|
||||
{ "100000", 256, 4, 1, "moe_mxfp4_expert_staged_kernel<256, 4, true>", false },
|
||||
{ "100000", 128, 1, 0, "moe_mxfp4_expert_staged_kernel<128, 1, false>", false },
|
||||
{ "100000", 128, 1, 1, "moe_mxfp4_expert_staged_kernel<128, 1, true>", false },
|
||||
{ "100000", 128, 4, 0, "moe_mxfp4_expert_staged_kernel<128, 4, false>", false },
|
||||
{ "100000", 128, 4, 1, "moe_mxfp4_expert_staged_kernel<128, 4, true>", false },
|
||||
{ "000000", 0, 0, 1, "moe_mxfp4_fp8_kernel<1, 1, false, true>", false },
|
||||
{ "010000", 0, 0, 1, "moe_mxfp4_fp8_kernel<1, 1, false, true>", true },
|
||||
{ "001000", 0, 0, 1, "moe_mxfp4_fp8_kernel<2, 1, false, true>", true },
|
||||
{ "011000", 0, 0, 1, "moe_mxfp4_fp8_kernel<2, 1, false, true>", true },
|
||||
{ "011100", 0, 0, 1, "moe_mxfp4_fp8_kernel<2, 2, false, true>", true },
|
||||
{ "011110", 0, 0, 1, "moe_mxfp4_fp8_kernel<4, 2, false, true>", true },
|
||||
{ "011111", 0, 0, 0, "moe_mxfp4_fp8_kernel<4, 2, true, false>", true },
|
||||
{ "011111", 0, 0, 1, "moe_mxfp4_fp8_kernel<4, 2, true, true>", true },
|
||||
{ "011111", 0, 0, 0, "moe_mxfp4_prefill_kernel<false>", true, true },
|
||||
{ "011111", 0, 0, 1, "moe_mxfp4_prefill_kernel<true>", true, true },
|
||||
};
|
||||
/* P64 at every raster point, column tiles 4 (the resident form's default) and 1, and the LDS
|
||||
* output at the default; the K of a case picks streamed or resident A. */
|
||||
struct P64 {
|
||||
int bm, bn, sk, ct, out, db = 0;
|
||||
};
|
||||
std::vector<P64> p64s;
|
||||
for (int bm : { 32, 64 })
|
||||
for (int bn : { 64, 128 })
|
||||
for (int sk : { 128, 256 })
|
||||
for (int ct : { 1, 4 }) p64s.push_back({ bm, bn, sk, ct, 0 });
|
||||
p64s.push_back({ 64, 128, 128, 4, 1 });
|
||||
p64s.push_back({ 32, 64, 256, 1, 1 });
|
||||
/* The double buffer at every BM x BN x stage: where two stages do not fit in LDS, and with
|
||||
* resident A, the single-buffer form runs. */
|
||||
for (int bm : { 32, 64 })
|
||||
for (int bn : { 64, 128 })
|
||||
for (int sk : { 128, 256 }) p64s.push_back({ bm, bn, sk, 4, 0, 1 });
|
||||
p64s.push_back({ 64, 128, 128, 4, 1, 1 });
|
||||
static const char* const kP64[] = { "RADIANCE_MXFP4_PREFILL_P64",
|
||||
"RADIANCE_MXFP4_PREFILL_P64_MIN_T_GATE_UP",
|
||||
"RADIANCE_MXFP4_PREFILL_P64_MIN_T_DOWN",
|
||||
"RADIANCE_MXFP4_PREFILL_P64_BM",
|
||||
"RADIANCE_MXFP4_PREFILL_P64_BN",
|
||||
"RADIANCE_MXFP4_PREFILL_P64_STAGE_K",
|
||||
"RADIANCE_MXFP4_PREFILL_P64_COLTILES",
|
||||
"RADIANCE_MXFP4_PREFILL_P64_STAGE_OUT",
|
||||
"RADIANCE_MXFP4_PREFILL_P64_T_BM64",
|
||||
"RADIANCE_MXFP4_PREFILL_P64_T_BN128",
|
||||
"RADIANCE_MXFP4_PREFILL_P64_T_DOWN_WIDE",
|
||||
"RADIANCE_MXFP4_PREFILL_P64_DB" };
|
||||
/* The rule's tile with nothing pinned, by its row bounds (unset: this test's few rows are
|
||||
* under all of them); the widest tiles take the LDS output. */
|
||||
struct Rule {
|
||||
const char* t_bm64;
|
||||
const char* t_bn128;
|
||||
const char* t_down;
|
||||
const char* streamed;
|
||||
const char* resident;
|
||||
};
|
||||
const Rule rules[] = { { nullptr, nullptr, nullptr, "<32, 64, 256, 1, false>",
|
||||
"<32, 64, 128, 4, true>" },
|
||||
{ "0", nullptr, nullptr, "<64, 64, 256, 1, false>", "<32, 64, 128, 4, true>" },
|
||||
{ "0", "0", "0", "<64, 128, 128, 1, false>", "<64, 128, 128, 4, true>" } };
|
||||
static const char* const kEnv[] = {
|
||||
"RADIANCE_MXFP4_DECODE_EXPERTS", "RADIANCE_MXFP4_ALIGNED_JOBS",
|
||||
"RADIANCE_MXFP4_PREFILL_N32", "RADIANCE_MXFP4_PREFILL_M32",
|
||||
"RADIANCE_MXFP4_PREFILL_N64", "RADIANCE_MXFP4_PREFILL_CACHE_ROWS"
|
||||
5,
|
||||
staged },
|
||||
{ "GLM TP4 down, the GLM prefill form",
|
||||
4096,
|
||||
512,
|
||||
4096,
|
||||
512,
|
||||
1,
|
||||
8,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
glm_runs({ 63, 96, 1, 130, 32, 31, 33, 64, 65 }),
|
||||
13,
|
||||
"moe_mxfp4_prefill_kernel" },
|
||||
{ "GLM TP8 gate_up, P64 BM32 BN64 K256",
|
||||
512,
|
||||
4096,
|
||||
512,
|
||||
4096,
|
||||
2,
|
||||
8,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
glm_runs({ 200, 33, 300, 31, 200 }),
|
||||
20,
|
||||
"(moe_mxfp4_p64_kernel<32, 64, 256, 1, false>)" },
|
||||
{ "GLM TP8 down, P64 BM32 BN64 K128 x4, A resident",
|
||||
4096,
|
||||
256,
|
||||
4096,
|
||||
256,
|
||||
1,
|
||||
8,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
glm_runs({ 900, 801, 779, 700, 700, 581, 600, 600, 63, 1 }),
|
||||
40,
|
||||
"(moe_mxfp4_p64_kernel<32, 64, 128, 4, true>)" },
|
||||
};
|
||||
|
||||
for (const Case& c : all) {
|
||||
@@ -264,21 +239,37 @@ int main() {
|
||||
// A dropped slot about every eleventh row, the first rows of some runs included.
|
||||
sorted[r] = (r * 13 + e) % 11 == 0 ? -1 : (int)(rng() % (uint32_t)T);
|
||||
}
|
||||
/* Stacked planes hold every expert; a pointer table names one of at most three slices a
|
||||
* class, so GLM's 288 experts stay small. */
|
||||
const int n[2] = { c.N, c.N_odd }, k[2] = { c.K, c.K_odd },
|
||||
nexp[2] = { (E + 1) / 2, E / 2 };
|
||||
std::vector<uint8_t> w[2], s[2];
|
||||
std::vector<const void*> wt[2], st[2];
|
||||
std::vector<std::vector<float>> wf[2];
|
||||
int slices[2];
|
||||
for (int q = 0; q < 2; ++q) {
|
||||
w[q].resize((size_t)nexp[q] * n[q] * k[q] / 2);
|
||||
s[q].resize((size_t)nexp[q] * n[q] * k[q] / 32);
|
||||
slices[q] = c.tables ? std::min(nexp[q], 3) : nexp[q];
|
||||
w[q].resize((size_t)slices[q] * n[q] * k[q] / 2);
|
||||
s[q].resize((size_t)slices[q] * n[q] * k[q] / 32);
|
||||
for (auto& v : w[q]) v = (uint8_t)rng();
|
||||
static const uint8_t special[] = { 0, 255, 1, 254, 127 };
|
||||
for (size_t i = 0; i < s[q].size(); ++i)
|
||||
s[q][i] = c.exceptional && rng() % 9 == 0 ? special[rng() % 5]
|
||||
: (uint8_t)(118 + rng() % 16);
|
||||
for (int x = 0; x < nexp[q]; ++x) {
|
||||
wt[q].push_back(w[q].data() + (size_t)x * n[q] * k[q] / 2);
|
||||
st[q].push_back(s[q].data() + (size_t)x * n[q] * k[q] / 32);
|
||||
wt[q].push_back(w[q].data() + (size_t)(x % slices[q]) * n[q] * k[q] / 2);
|
||||
st[q].push_back(s[q].data() + (size_t)(x % slices[q]) * n[q] * k[q] / 32);
|
||||
}
|
||||
/* each slice's codes as the E4M3 values the table decode gives */
|
||||
for (int x = 0; x < slices[q]; ++x) {
|
||||
std::vector<float> f((size_t)n[q] * k[q]);
|
||||
const uint8_t* src = w[q].data() + (size_t)x * n[q] * k[q] / 2;
|
||||
for (size_t i = 0; i < f.size(); ++i) {
|
||||
uint32_t lo, hi;
|
||||
r4d_mxfp4_unpack8_exact((src[i / 2] >> (4 * (i & 1))) & 15u, &lo, &hi);
|
||||
f[i] = rad_fp8e4m3_to_f32((uint8_t)(lo & 0xffu));
|
||||
}
|
||||
wf[q].push_back(std::move(f));
|
||||
}
|
||||
}
|
||||
auto plane = [&](int q, bool scale) {
|
||||
@@ -291,6 +282,8 @@ int main() {
|
||||
};
|
||||
|
||||
/* the per-element sequence, on the host */
|
||||
std::vector<float> af(a.size());
|
||||
for (size_t i = 0; i < a.size(); ++i) af[i] = rad_fp8e4m3_to_f32(a[i]);
|
||||
std::vector<uint16_t> ref((size_t)T * yp, 0x7777);
|
||||
for (int r = 0; r < T; ++r)
|
||||
for (int col = 0; col < OUT; ++col) {
|
||||
@@ -301,21 +294,15 @@ int main() {
|
||||
const int pw = OUT / c.parts, cw = n[q] / c.parts, within = col % pw;
|
||||
const bool valid = within < cw;
|
||||
const int wn = (col / pw) * cw + within;
|
||||
const uint8_t* wr =
|
||||
w[q].data() + (size_t)(e / 2) * n[q] * k[q] / 2 + (size_t)wn * k[q] / 2;
|
||||
const uint8_t* sr =
|
||||
s[q].data() + (size_t)(e / 2) * n[q] * k[q] / 32 + (size_t)wn * k[q] / 32;
|
||||
const float* wr = wf[q][(size_t)((e / 2) % slices[q])].data() + (size_t)wn * k[q];
|
||||
const uint8_t* sr = (const uint8_t*)st[q][(size_t)(e / 2)] + (size_t)wn * k[q] / 32;
|
||||
const float* arow = af.data() + (size_t)ar * ap;
|
||||
float total = 0.f;
|
||||
for (int kb = 0; kb < k[q]; kb += 128)
|
||||
for (int g = 0; g < 4; ++g) {
|
||||
float raw = 0.f;
|
||||
for (int kk = kb + g * 32; kk < kb + g * 32 + 32; ++kk) {
|
||||
const uint32_t code = valid ? (wr[kk / 2] >> (4 * (kk & 1))) & 15u : 0u;
|
||||
uint32_t lo, hi;
|
||||
r4d_mxfp4_unpack8_exact(code, &lo, &hi);
|
||||
raw += rad_fp8e4m3_to_f32(a[(size_t)ar * ap + kk]) *
|
||||
rad_fp8e4m3_to_f32((uint8_t)(lo & 0xffu));
|
||||
}
|
||||
for (int kk = kb + g * 32; kk < kb + g * 32 + 32; ++kk)
|
||||
raw += arow[kk] * (valid ? wr[kk] : 0.f);
|
||||
const uint32_t x = valid ? sr[kb / 32 + g] : 127u;
|
||||
uint32_t bits = x == 255 ? 0x7fc00000u : x ? x << 23 : 0x00400000u;
|
||||
float scale;
|
||||
@@ -329,6 +316,12 @@ int main() {
|
||||
out = (uint16_t)((u + 0x7fffu + ((u >> 16) & 1u)) >>
|
||||
16); // f32_to_bf16, r4d_common.h
|
||||
}
|
||||
int live = 0;
|
||||
for (uint16_t v : ref) live += v != 0 && v != 0x7777;
|
||||
if (live < T * OUT / 3) {
|
||||
std::printf("FAIL %s: output mostly zero\n", c.name);
|
||||
++fails;
|
||||
}
|
||||
|
||||
RadTensor t[9] = { ten(a.data(), RAD_F8E4M3, { Arows, NK }, { ap, 1 }),
|
||||
ten(as.data(), RAD_F32, { Arows, NK / 128 }, { asp, 1 }),
|
||||
@@ -365,118 +358,25 @@ int main() {
|
||||
p[8] = pi("group", 128);
|
||||
p[9] = ps("a_order", c.sorted_a ? "sorted" : "token");
|
||||
p[10] = ps("dtype", "mxfp4a8");
|
||||
auto run = [&](const Form& f, std::vector<uint16_t>& y) {
|
||||
y.assign((size_t)T * yp, 0x7777);
|
||||
t[8] = ten(y.data(), RAD_BF16, { T, OUT }, { yp, 1 });
|
||||
for (int i = 0; i < 6; ++i) setenv(kEnv[i], f.env[i] == '1' ? "1" : "0", 1);
|
||||
if (f.stage) {
|
||||
setenv("RADIANCE_MXFP4_EXPERTS_STAGE_K", std::to_string(f.stage).c_str(), 1);
|
||||
setenv("RADIANCE_MXFP4_EXPERTS_COLTILES", std::to_string(f.tiles).c_str(), 1);
|
||||
}
|
||||
setenv("RADIANCE_MXFP4_LUT", f.lut ? "1" : "0", 1);
|
||||
setenv("RADIANCE_MXFP4_PREFILL_PIPE", f.pipe ? "1" : "0", 1);
|
||||
RadArgs ar{};
|
||||
ar.t = t;
|
||||
ar.n_t = 9;
|
||||
ar.p = p;
|
||||
ar.n_p = 11;
|
||||
emu_last_kernel = "";
|
||||
return r4d_rad_moe_mxfp4(&ar, nullptr);
|
||||
};
|
||||
auto run_p64 = [&](const P64& f, std::vector<uint16_t>& y) {
|
||||
const int v[8] = { 1, 0, 0, f.bm, f.bn, f.sk, f.ct, f.out };
|
||||
for (int i = 0; i < 8; ++i) setenv(kP64[i], std::to_string(v[i]).c_str(), 1);
|
||||
setenv(kP64[11], f.db ? "1" : "0", 1);
|
||||
const Form base = { "000000", 0, 0, 1, "", false };
|
||||
const int rc = run(base, y);
|
||||
setenv(kP64[0], "0", 1);
|
||||
return rc;
|
||||
};
|
||||
const Form alt = { "000000", 0, 0, 0, "moe_mxfp4_fp8_kernel<1, 1, false, false>", false };
|
||||
std::vector<uint16_t> legacy, got;
|
||||
std::vector<uint16_t> got((size_t)T * yp, 0x7777);
|
||||
t[8] = ten(got.data(), RAD_BF16, { T, OUT }, { yp, 1 });
|
||||
RadArgs ar{};
|
||||
ar.t = t;
|
||||
ar.n_t = 9;
|
||||
ar.p = p;
|
||||
ar.n_p = 11;
|
||||
emu_last_kernel = "";
|
||||
++cases;
|
||||
int rc = run(alt, legacy);
|
||||
if (rc != RAD_OK || !std::strstr(emu_last_kernel, alt.kernel)) {
|
||||
std::printf("FAIL %s: reference form rc %d kernel %s\n", c.name, rc, emu_last_kernel);
|
||||
const int rc = r4d_rad_moe_mxfp4(&ar, nullptr);
|
||||
const size_t i = first_diff(got, ref);
|
||||
if (rc != RAD_OK || std::strcmp(emu_last_kernel, c.kernel) || i != got.size()) {
|
||||
std::printf("FAIL %s (T %d): ran %s (want %s), rc %d, first word %zu (row %zu col %zu: "
|
||||
"%04x, want %04x)\n",
|
||||
c.name, T, emu_last_kernel, c.kernel, rc, i, i / yp, i % yp,
|
||||
i < got.size() ? got[i] : 0, i < ref.size() ? ref[i] : 0);
|
||||
++fails;
|
||||
continue;
|
||||
}
|
||||
if (!same16(legacy, ref)) {
|
||||
const size_t i = first_diff(legacy, ref);
|
||||
std::printf("FAIL %s: reference form against the host sequence at row %zu col %zu: "
|
||||
"%04x, want %04x\n",
|
||||
c.name, i / yp, i % yp, legacy[i], ref[i]);
|
||||
++fails;
|
||||
}
|
||||
int live = 0;
|
||||
for (uint16_t v : ref) live += v != 0 && v != 0x7777;
|
||||
if (live < T * OUT / 3) {
|
||||
std::printf("FAIL %s: output mostly zero\n", c.name);
|
||||
++fails;
|
||||
}
|
||||
for (const Form& f : forms) {
|
||||
if (f.prefill && T < 512) continue;
|
||||
++cases;
|
||||
rc = run(f, got);
|
||||
const bool reached = std::strstr(emu_last_kernel, f.kernel) != nullptr;
|
||||
if (rc != RAD_OK || !reached || !same16(got, legacy)) {
|
||||
const size_t i = first_diff(got, legacy);
|
||||
std::printf(
|
||||
"FAIL %s: form %s stage %d tiles %d lut %d ran %s (want %s), rc %d, first "
|
||||
"word %zu\n",
|
||||
c.name, f.env, f.stage, f.tiles, f.lut, emu_last_kernel, f.kernel, rc, i);
|
||||
++fails;
|
||||
}
|
||||
}
|
||||
const bool resident = NK <= 256;
|
||||
for (const Rule& u : rules) {
|
||||
++cases;
|
||||
for (const char* v : kP64) unsetenv(v);
|
||||
setenv(kP64[0], "1", 1);
|
||||
setenv(kP64[1], "0", 1);
|
||||
setenv(kP64[2], "0", 1);
|
||||
if (u.t_bm64) setenv(kP64[8], u.t_bm64, 1);
|
||||
if (u.t_bn128) setenv(kP64[9], u.t_bn128, 1);
|
||||
if (u.t_down) setenv(kP64[10], u.t_down, 1);
|
||||
const Form base = { "000000", 0, 0, 1, "", false };
|
||||
rc = run(base, got);
|
||||
for (const char* v : kP64) unsetenv(v);
|
||||
const std::string want =
|
||||
std::string("moe_mxfp4_p64_kernel") + (resident ? u.resident : u.streamed);
|
||||
if (rc != RAD_OK || !std::strstr(emu_last_kernel, want.c_str()) ||
|
||||
!same16(got, legacy)) {
|
||||
std::printf("FAIL %s: P64 rule ran %s (want %s), rc %d, first word %zu\n", c.name,
|
||||
emu_last_kernel, want.c_str(), rc, first_diff(got, legacy));
|
||||
++fails;
|
||||
}
|
||||
}
|
||||
for (const P64& f : p64s) {
|
||||
++cases;
|
||||
rc = run_p64(f, got);
|
||||
const bool db = f.db && !resident && (f.sk == 128 || (f.bm == 32 && f.bn == 64));
|
||||
const std::string want = "moe_mxfp4_p64_kernel<" + std::to_string(f.bm) + ", " +
|
||||
std::to_string(f.bn) + ", " + std::to_string(f.sk) + ", " +
|
||||
(resident ? std::to_string(f.ct) : "1") + ", " +
|
||||
(resident ? "true" : "false") + (db ? ", true>" : ">");
|
||||
const bool reached = std::strstr(emu_last_kernel, want.c_str()) != nullptr;
|
||||
if (rc != RAD_OK || !reached || !same16(got, legacy)) {
|
||||
const size_t i = first_diff(got, legacy);
|
||||
std::printf("FAIL %s: P64 bm %d bn %d stage %d tiles %d out %d db %d ran %s (want "
|
||||
"%s), rc %d, "
|
||||
"first word %zu (row %zu col %zu: %04x, want %04x)\n",
|
||||
c.name, f.bm, f.bn, f.sk, f.ct, f.out, f.db, emu_last_kernel,
|
||||
want.c_str(), rc, i, i / yp, i % yp, i < got.size() ? got[i] : 0,
|
||||
i < legacy.size() ? legacy[i] : 0);
|
||||
++fails;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const char* v : kEnv) unsetenv(v);
|
||||
for (const char* v : kP64) unsetenv(v);
|
||||
unsetenv("RADIANCE_MXFP4_EXPERTS_STAGE_K");
|
||||
unsetenv("RADIANCE_MXFP4_EXPERTS_COLTILES");
|
||||
unsetenv("RADIANCE_MXFP4_LUT");
|
||||
unsetenv("RADIANCE_MXFP4_PREFILL_PIPE");
|
||||
std::printf("%d case(s), %d failure(s)\n", cases, fails);
|
||||
return fails ? 1 : 0;
|
||||
}
|
||||
Reference in new issue
Block a user