Files
ds4/tests/test_qwen4_mtp_policy.c
T
antirez cd1c5507b6 Preserve resident Qwen prefill speed with speculative decoding
Prepare predictor history by default for SSD streaming. When weights fit in RAM, initialize historical draft rows to zero and keep target verification enabled. Full prompt history remains available with DS4_QWEN4_MTP_PREFILL=on.

With 7,809 prompt tokens and 64 generated tokens on an M5 Max, the resident default took 6.47 s versus 7.53 s with eager history. Generated text matched previous main in both modes. The same policy recovered prefill throughput on the DGX Spark.
2026-11-03 16:50:59 +01:00

52 lines
1.7 KiB
C

#define DS4_NO_GPU
#include "../ds4.c"
/* Exercise all policy choices without model weights or an accelerator. */
int main(void) {
const struct {
const char *value;
int resident;
int streaming;
} cases[] = {
{NULL, 0, 1},
{"", 0, 1},
{"on", 1, 1},
{"1", 1, 1},
{"off", 0, 0},
{"0", 0, 0},
{"auto", 0, 1},
{"invalid", -1, -1},
{"2", -1, -1},
{"-1", -1, -1},
{"ON", -1, -1},
{"OFF", -1, -1},
{"AUTO", -1, -1},
{" on", -1, -1},
{"off ", -1, -1},
{"auto-extra", -1, -1},
};
unsigned checks = 0;
for (size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) {
for (int enabled = 0; enabled <= 1; enabled++) {
for (int streaming = 0; streaming <= 1; streaming++) {
/* With MTP disabled this setting has no effect, including
* malformed values: it must not enable or reject MTP. */
const int expected = enabled ?
(streaming ? cases[i].streaming : cases[i].resident) : 0;
const int actual = qwen4_mtp_prefill_resolve(enabled != 0,
streaming != 0, cases[i].value);
if (actual != expected) {
fprintf(stderr,
"MTP prefill policy value=%s enabled=%d streaming=%d: got %d, expected %d\n",
cases[i].value ? cases[i].value : "<unset>",
enabled, streaming, actual, expected);
return 1;
}
checks++;
}
}
}
printf("PASS Qwen MTP prefill policy: %u cases, no model or GPU required\n", checks);
return 0;
}