Archived
moe_mxfp4: a pin for the small-M form, and --perfmx-tp 4 to time it at the TP4 slices
r4d_moe_mxfp4_pin_small takes the small-M form where the rule does not (any GLM slice up to 384 routed rows, at either tiling) or keeps it off. r4d_selftest --perfmx-tp 4 times GLM's TP4 slices, gate_up 1024 x 4096 and down 4096 x 512, the rule's form beside the pinned ones, and fails if their outputs differ by a byte. The rule itself is unchanged.
This commit is contained in:
1 parent
be623ba1dc
commit
220cb3f12c
2 files changed
+69
-24
No files matched your search
@@ -1071,6 +1071,10 @@ int table(const RadTensor* t, uint32_t dtype, int bits, long experts, long n, lo
|
||||
*row = (int)(t->stride[1] * bits / 8);
|
||||
return RAD_OK;
|
||||
}
|
||||
/* r4d_moe_mxfp4_pin_small: 0 the rule, 1 the small-M form at any GLM slice up to 384 routed rows
|
||||
* (TP4 as well as TP8, past the rule's bounds), 2 never, 3 as 1 with the K256 x4 tiles whatever
|
||||
* K. For r4d_selftest --perfmx to measure the form where the rule does not take it. */
|
||||
int g_mx_small_pin = 0;
|
||||
int body(const RadArgs* a, RadStream stream) {
|
||||
if (!a || a->n_t < 9) return RAD_E_INVAL;
|
||||
const auto *aq = rad_arg_in(a, 0), *as = rad_arg_in(a, 1), *sorted = rad_arg_in(a, 4),
|
||||
@@ -1162,7 +1166,9 @@ int body(const RadArgs* a, RadStream stream) {
|
||||
* slower than the staged form). At those slices on gfx1201 (perfmx, cold) it is 6 to 16 %
|
||||
* faster than the expert-major form for gate_up from 1 to 48 tokens, and 4 to 23 % for down
|
||||
* from 1 to 4. */
|
||||
if (tp8 && m.T <= (m.K <= 256 ? 32 : 384)) {
|
||||
if (g_mx_small_pin == 1 || g_mx_small_pin == 3
|
||||
? glm_prefill && m.T <= 384
|
||||
: g_mx_small_pin != 2 && tp8 && m.T <= (m.K <= 256 ? 32 : 384)) {
|
||||
const long rows = std::min<long>(m.experts, m.T) + 1;
|
||||
#define MX_SMALL(SK, CT) \
|
||||
R4D_EMIT(stream, (moe_mxfp4_small_kernel<SK, CT>), \
|
||||
@@ -1170,7 +1176,7 @@ int body(const RadArgs* a, RadStream stream) {
|
||||
(const uint8_t*)aq->data, (const float*)as->data, w[0]->data, s[0]->data, \
|
||||
w[1]->data, s[1]->data, (const int*)sorted->data, (const int*)off->data, \
|
||||
(uint16_t*)y->data, m)
|
||||
return m.K <= 256 ? MX_SMALL(256, 4) : MX_SMALL(512, 1);
|
||||
return m.K <= 256 || g_mx_small_pin == 3 ? MX_SMALL(256, 4) : MX_SMALL(512, 1);
|
||||
#undef MX_SMALL
|
||||
}
|
||||
/* The expert-major form up to a routed-row bound per projection (token rows: gate_up, sorted
|
||||
@@ -1205,3 +1211,4 @@ int body(const RadArgs* a, RadStream stream) {
|
||||
}
|
||||
}
|
||||
extern "C" int r4d_rad_moe_mxfp4(const RadArgs* a, RadStream stream) { return body(a, stream); }
|
||||
extern "C" void r4d_moe_mxfp4_pin_small(int form) { g_mx_small_pin = form; }
|
||||
Reference in new issue
Block a user