mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
prefill: STRATA_PF_FUSED_Q8D=1 on gfx12 - the Q8_0 down behind an i-quant gate/up on the fused kernels (HIP, opt-in)
The pinned UD-IQ4_XS's five Q8_0-down layers (IQ3_S / Q8_0 4, IQ4_XS / Q8_0 1) left the fused path for MMQ on gfx12
unless STRATA_PF_FUSED_KQ=1, whose meaning is the K-quant experts. STRATA_PF_FUSED_Q8D, CUDA's switch for the same
layers, now means the same on gfx1200 / gfx1201: d_covered_on takes a Q8_0 down there, and native_supported keeps the
Q2_0 gate/up + Q8_0 down pair on MMQ unless STRATA_PF_FUSED_KQ=1 (as on CUDA; the K-quant route's wider rule is
unchanged). Host code only: the gfx12 int8 Q8_0 down instances of native_w11_kernel already exist. Off by default;
gfx11's rules (STRATA_PF_F16, q8d_f16_default) unchanged.
Test: hip_prefill_fused_iq_q8d (the i-quant / Q8_0 pairs, --edge, STRATA_PF_FUSED_Q8D=1) with the new --no-kq flag
(the test leaves STRATA_PF_FUSED_KQ unset; without the switch, or off gfx12, it skips with 77).
Settings register: STRATA_PF_FUSED_Q8D lists the HIP read (status research, not on the users' page).
R9700 (p620, gfx1201), base 6b32d91c5 vs this tree, same folders and flags:
- device code: engine 3,929 / 3,929 functions, moe_fused_iq.cu.o 84 / 84, hip_prefill_fused_iq 1,342 / 1,342,
hip_prefill_decode_golden 15 / 15: 0 differing, 0 new, code objects identical; build commands and warnings
(4,454) identical; host bytes of moe_fused_iq.cu.o and strata differ, prefill.cpp.o identical
- the Q8D entry: both pairs, all 6 shapes, fused vs the int8 model <= 8.2e-5 rel RMS, fused vs MMQ <= 9.1e-4
(limit 1e-3), fused and MMQ the same distance from FP32; without the switch: skipped (77)
- the same kernels as STRATA_PF_FUSED_KQ=1 takes: one-layer output hashes equal for both pairs at 2,048 / 3,584 /
8,192 tokens (6 of 6)
- default run: all 12 output hashes equal the base's; decode digests 112 / 112
- one layer, fused / MMQ path: IQ3_S / Q8_0 3.74x / 3.03x / 2.54x, IQ4_XS / Q8_0 4.00x / 3.24x / 2.78x at
2,048 / 3,584 / 8,192 tokens (the layer leaves MMQ entirely)
This commit is contained in:
1 parent
6b32d91c5c
commit
c5c26171ea
4 files changed
+44
-6
No files matched your search
@@ -103,6 +103,10 @@ macro(strata_hip_mmq)
|
||||
add_test(NAME hip_prefill_fused_iq_f16 COMMAND hip_prefill_fused_iq)
|
||||
set_tests_properties(hip_prefill_fused_iq_f16 PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 600 ENVIRONMENT "STRATA_PF_F16=1;STRATA_PF_F16_KQ=1")
|
||||
list(APPEND _strata_hip_tests hip_prefill_fused_iq)
|
||||
# STRATA_PF_FUSED_Q8D=1 (gfx12, opt-in): the pinned UD-IQ4_XS's i-quant / Q8_0 pairs on the fused kernels without the K-quant switch (--no-kq);
|
||||
# off gfx12 the pairs are not covered without STRATA_PF_FUSED_KQ and the test skips (77, as without a card)
|
||||
add_test(NAME hip_prefill_fused_iq_q8d COMMAND hip_prefill_fused_iq "--only=S / Q8_0" --edge --no-timing --no-kq)
|
||||
set_tests_properties(hip_prefill_fused_iq_q8d PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 600 ENVIRONMENT "STRATA_PF_FUSED_Q8D=1")
|
||||
# the fused prompt kernels' weight decode against the digests CUDA wrote (tests/cuda/prefill_decode_golden.cu): the same file on every vendor
|
||||
# (moe_fused_iq.cu's decode compiled as strata_mmq compiles it: its include directories, definitions and options; exit 77 without a card)
|
||||
set_source_files_properties(tests/cuda/prefill_decode_golden.cu PROPERTIES LANGUAGE HIP INCLUDE_DIRECTORIES "${STRATA_HIP_COMPAT_INCLUDE_DIR}")
|
||||
|
||||
@@ -25786,14 +25786,21 @@
|
||||
{
|
||||
"name": "STRATA_PF_FUSED_Q8D",
|
||||
"backends": [
|
||||
"cuda"
|
||||
"cuda",
|
||||
"hip"
|
||||
],
|
||||
"reads": [
|
||||
{
|
||||
"file": "src/prefill/moe_fused_iq.cu",
|
||||
"line": 1957,
|
||||
"line": 2034,
|
||||
"backend": "cuda",
|
||||
"fn": "getenv"
|
||||
},
|
||||
{
|
||||
"file": "src/prefill/moe_fused_iq.cu",
|
||||
"line": 2360,
|
||||
"backend": "hip",
|
||||
"fn": "getenv"
|
||||
}
|
||||
],
|
||||
"parse": "flag",
|
||||
@@ -25812,7 +25819,7 @@
|
||||
"last_date": "",
|
||||
"status": "research",
|
||||
"owner": "prefill",
|
||||
"note": "CUDA (phase 4, opt-in, default off): a Q8_0 down behind an i-quant gate/up (the pinned UD-IQ4_XS's five Q8_0-down layers) on the fused native kernels on any sm_80+ card instead of MMQ.",
|
||||
"note": "[DRAFT] CUDA and HIP gfx12 (phase 4, opt-in, default off): a Q8_0 down behind an i-quant gate/up (the pinned UD-IQ4_XS's five Q8_0-down layers) on the fused native kernels instead of MMQ, on any sm_80+ card and on gfx1200 / gfx1201.",
|
||||
"retire_after": "",
|
||||
"retired_in": ""
|
||||
},
|
||||
|
||||
@@ -2351,10 +2351,21 @@ bool q50_on(const DevInfo& d) {
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
#if defined(__HIPCC__)
|
||||
// STRATA_PF_FUSED_Q8D on HIP (phase 4, opt-in, gfx12 only): "1" lets a Q8_0 down behind an i-quant gate/up (the pinned UD-IQ4_XS's five Q8_0-down layers:
|
||||
// IQ3_S / Q8_0 4, IQ4_XS / Q8_0 1) take native_w11_kernel's Q8_0 down instead of MMQ, without STRATA_PF_FUSED_KQ (whose meaning is the K-quant experts).
|
||||
// The same switch as CUDA's. No new kernel: the gfx12 int8 Q8_0 down instances exist for the K-quant route. gfx11 keeps its own rules (q8d_f16_default,
|
||||
// STRATA_PF_F16): not measured with this switch.
|
||||
bool q8d_hip_requested() {
|
||||
static const bool on = [] { const char* v = std::getenv("STRATA_PF_FUSED_Q8D"); return v != nullptr && v[0] == '1'; }();
|
||||
return on;
|
||||
}
|
||||
#endif
|
||||
bool d_covered_on(int t, const DevInfo& d) {
|
||||
#if defined(__HIPCC__)
|
||||
if (t == T_Q5_0) return d.w12 ? q50_on(d) : q50_on(d) && f16::requested(); // gfx1151 has no int8 kernel for Q5_0 down (the F16 prompt set must be on); gfx12 has only the int8 one
|
||||
if (t == T_Q8_0 && !d.w12 && (f16::requested() || q8d_f16_default(d))) return true;
|
||||
if (t == T_Q8_0 && d.w12 && q8d_hip_requested()) return true; // (behind an i-quant gate/up only: native_supported)
|
||||
#else
|
||||
if (t == T_Q5_0) return d.q50; // STRATA_PF_FUSED_Q50=1 and its kernels set up (dev_info)
|
||||
if (t == T_Q5_1) return d.kq; // STRATA_PF_FUSED_KQ=1 (behind a K-quant gate/up only: native_supported)
|
||||
@@ -2541,6 +2552,11 @@ bool native_supported(int gu_type, int d_type) {
|
||||
#endif
|
||||
) return false;
|
||||
const DevInfo& d = dev_info();
|
||||
#if defined(__HIPCC__)
|
||||
// STRATA_PF_FUSED_Q8D=1 on gfx12 covers the Q8_0 down behind an i-quant gate/up only (as on CUDA): a Q2_0 gate/up with a Q8_0 down keeps MMQ there
|
||||
// unless STRATA_PF_FUSED_KQ=1 (the K-quant route's wider rule, unchanged; gfx11's rules unchanged)
|
||||
if (d.w12 && gu_type == T_Q2_0 && d_type == T_Q8_0 && !kq_on()) return false;
|
||||
#endif
|
||||
if (!d.ok || !d_covered_on(d_type, d)) return false;
|
||||
if (d.t75 && (gu_type != T_Q2_0 || d_type != T_Q2_0)) return false;
|
||||
if (env < 0) return d.w12;
|
||||
|
||||
@@ -803,14 +803,19 @@ int main(int argc, char** argv) {
|
||||
try {
|
||||
// --unset-pf-fused: STRATA_PF_FUSED unset, as the engine's default (the ctest entry for the opt-in STRATA_PF_FUSED_Q2N=1,
|
||||
// whose Q2_0 / Q2_0 pair the engine takes with the old variable unset or at 1)
|
||||
bool unset_pf = false;
|
||||
for (int i = 1; i < argc; ++i)
|
||||
// --no-kq: STRATA_PF_FUSED_KQ left as it is (HIP: the ctest entry for STRATA_PF_FUSED_Q8D=1 on gfx12, which must cover the i-quant / Q8_0
|
||||
// pairs without the K-quant switch that also covers them there)
|
||||
bool unset_pf = false, no_kq = false;
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (std::strcmp(argv[i], "--unset-pf-fused") == 0) unset_pf = true;
|
||||
if (std::strcmp(argv[i], "--no-kq") == 0) no_kq = true;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
if (unset_pf) _putenv_s("STRATA_PF_FUSED", ""); else _putenv_s("STRATA_PF_FUSED", "1"); // (an empty value removes it)
|
||||
(void) no_kq; // (Windows: the K-quant switch is not set here)
|
||||
#else
|
||||
if (unset_pf) unsetenv("STRATA_PF_FUSED"); else setenv("STRATA_PF_FUSED", "1", 1);
|
||||
setenv("STRATA_PF_FUSED_KQ", "1", 1); // (the HIP build's Q4_K / Q5_K / Q5_1 / Q8_0 pairs)
|
||||
if (!no_kq) setenv("STRATA_PF_FUSED_KQ", "1", 1); // (the HIP build's Q4_K / Q5_K / Q5_1 / Q8_0 pairs)
|
||||
setenv("STRATA_PF_FUSED_Q50", "1", 1); // (gfx12's Q5_0 down pairs)
|
||||
#endif
|
||||
int n = 0;
|
||||
@@ -820,6 +825,12 @@ int main(int argc, char** argv) {
|
||||
std::printf("the fused kernels need sm_80 or newer (or gfx11 / gfx12 matrix cores): skipped\n");
|
||||
return 77;
|
||||
}
|
||||
// --no-kq (the STRATA_PF_FUSED_Q8D entry): a device or build where the i-quant / Q8_0 pairs are not covered without the K-quant switch
|
||||
// (gfx11, or the switch unset) skips instead of failing
|
||||
if (no_kq && !fused::native_supported(GGML_TYPE_IQ3_S, GGML_TYPE_Q8_0)) {
|
||||
std::printf("--no-kq: the i-quant / Q8_0 pairs are not covered here without STRATA_PF_FUSED_KQ (skipped)\n");
|
||||
return 77;
|
||||
}
|
||||
// with STRATA_PF_FUSED unset nothing is set up below sm_80 (Turing's pair is STRATA_PF_FUSED=1 STRATA_PF_FUSED_SM75=1's)
|
||||
if (unset_pf) {
|
||||
int major = 0;
|
||||
|
||||
Reference in new issue
Block a user