Merge f-kq-line 0ce77eaf8 into f-p4-int (the K-quant start-up line prints only when the loaded model has K-quant experts)

Two commits on 7d7590f40. The line "a model with K-quant experts (Unsloth UD-Q4/Q5/Q6_K_XL) reads its prompt on ..." was printed at option time, before the model is known, so an IQ3_S or IQ2_XS set that has no K-quant layer also showed it. The default is still set at that point; the line is now printed once the expert layout is loaded, and only when some layer has a gate/up or a down tensor of Q4_K, Q5_K, Q6_K or Q5_1 (the types the K-quant switches decide for). The wording is unchanged and so is every default. Unit tests on the two deciding functions; the second commit keeps the unit test from reading STRATA_DEFAULTS before the check that sets it. The same kind of line on gfx12 (HIP) is not changed.
This commit is contained in:
Niko1221 committed 2026-11-13 01:41:31 +01:00
commit 3ffa59e2be
4 files changed
+51 -5

No files matched your search

+10 -2
View File
@@ -45,9 +45,17 @@ namespace strata::core {
constexpr bool kNvKqDefaultOn = true;
std::vector<std::pair<std::string, std::string>> nv_kq_default_env(int min_major, int min_minor, bool defaults026);
std::vector<std::pair<std::string, std::string>> nv_kq_default_env(int min_major, int min_minor);
/// Sets what nv_kq_default_env returns where the user has not set the variable; prints one line to stderr when it set anything. fused_here: Strata's own fused
/// Sets what nv_kq_default_env returns where the user has not set the variable; prints one line to stderr when it set anything and `say` is true. fused_here: Strata's own fused
/// kernels read the K-quant experts on this machine (nv_kq_fused_here for a visible card); the line then says so, otherwise it is the earlier line, byte for byte.
std::vector<std::string> apply_nv_kq_default(int min_major, int min_minor, bool fused_here = false);
/// The engine calls it with say = false before it knows the model (option time) and prints the line itself once the expert layout is loaded, only when
/// nv_kq_line_wanted says the loaded set has experts the switch decides for.
std::vector<std::string> apply_nv_kq_default(int min_major, int min_minor, bool fused_here = false, bool say = true);
/// A ggml type of an expert tensor whose prompt products STRATA_MMQ_KQ / STRATA_PF_FUSED_KQ decide: Q4_K, Q5_K, Q6_K and Q5_1 (the four types
/// prefill::mmq::supported() hands to the K-quant switch). IQ types, Q2_0, Q8_0, Q4_0 ... are not decided by it.
bool nv_kq_expert_type(int ggml_type);
/// Whether the start-up line about K-quant experts is true of the loaded set: some layer has such a type as gate/up or as down (pairs of ggml types per layer).
/// IQ3_S / IQ2_XS sets: no. UD-Q4_K_XL (Q4_K / Q5_K gate/up): yes. A set whose only K-quant-family tensor is a Q5_1 down: yes, the switch decides that product.
bool nv_kq_line_wanted(const std::vector<std::pair<int, int>>& layer_gate_up_down_types);
/// Whether a CUDA card (raw compute capability, its multiprocessor count) reads UD-Q4_K_XL's K-quant experts (Q4_K / Q5_K gate/up with a Q5_1 or Q8_0 down) on Strata's
/// own fused kernels, from the environment as the engine reads it: the card rule of fused_tile::kq_takes with STRATA_PF_FUSED_KQ, STRATA_PF_FUSED_SM40 and
/// STRATA_PF_FUSED_SM86; STRATA_PF_FUSED=0 turns every fused kernel off.
+13 -2
View File
@@ -154,7 +154,18 @@ std::string nv_kq_default_line(bool fused_here) {
"(STRATA_MMQ_KQ=0 or STRATA_NV_KQ_DEFAULT=0 turns it off)";
}
std::vector<std::string> apply_nv_kq_default(int min_major, int min_minor, bool fused_here) {
bool nv_kq_expert_type(int ggml_type) {
// ggml type ids: Q5_1 = 7, Q4_K = 12, Q5_K = 13, Q6_K = 14 (the cases of prefill::mmq::supported() behind kq_ok())
return ggml_type == 7 || ggml_type == 12 || ggml_type == 13 || ggml_type == 14;
}
bool nv_kq_line_wanted(const std::vector<std::pair<int, int>>& layer_gate_up_down_types) {
for (const auto& l : layer_gate_up_down_types)
if (nv_kq_expert_type(l.first) || nv_kq_expert_type(l.second)) return true;
return false;
}
std::vector<std::string> apply_nv_kq_default(int min_major, int min_minor, bool fused_here, bool say) {
std::vector<std::string> set;
for (const auto& kv : nv_kq_default_env(min_major, min_minor)) {
if (std::getenv(kv.first.c_str()) != nullptr) continue; // the user's setting wins, whatever it is
@@ -165,7 +176,7 @@ std::vector<std::string> apply_nv_kq_default(int min_major, int min_minor, bool
#endif
set.push_back(kv.first);
}
if (!set.empty()) // the engine says nothing more on a pack without K-quant experts: the variable is never read there
if (say && !set.empty()) // the engine passes say = false and prints the line after the expert layout is loaded, only for a set with K-quant experts (nv_kq_line_wanted)
std::fprintf(stderr, "%s\n", nv_kq_default_line(fused_here).c_str());
return set;
}
+14
View File
@@ -94,6 +94,20 @@ int main() {
CHECK(nv_kq_default_line(true) ==
"strata: a model with K-quant experts (Unsloth UD-Q4/Q5/Q6_K_XL) reads its prompt on Strata's own kernels where they cover the layer (Q4_K and Q5_K gate/up with a Q5_1 or Q8_0 down) "
"and on llama.cpp's MMQ kernels for the rest (STRATA_PF_FUSED_KQ=0 gives all of them back to MMQ)");
{ // the line is printed only for a loaded set that has K-quant experts (ggml types: IQ2_XS 17, IQ3_S 21, IQ4_NL 20, IQ2_S 22, Q8_0 8, Q5_1 7, Q4_K 12, Q5_K 13, Q6_K 14)
CHECK(nv_kq_expert_type(12) && nv_kq_expert_type(13) && nv_kq_expert_type(14) && nv_kq_expert_type(7));
CHECK(!nv_kq_expert_type(8) && !nv_kq_expert_type(17) && !nv_kq_expert_type(21) && !nv_kq_expert_type(20) && !nv_kq_expert_type(22) && !nv_kq_expert_type(-1) && !nv_kq_expert_type(0));
CHECK(!nv_kq_line_wanted({})); // nothing loaded
CHECK(!nv_kq_line_wanted({{21, 20}, {21, 20}, {22, 20}, {17, 20}})); // IQ3_S / IQ2_S / IQ2_XS with IQ4_NL down: no line
CHECK(!nv_kq_line_wanted({{21, 8}, {17, 8}})); // Q8_0 down only: the switch decides nothing there
CHECK(nv_kq_line_wanted({{12, 7}})); // UD-Q4_K_XL: Q4_K gate/up, Q5_1 down
CHECK(nv_kq_line_wanted({{21, 20}, {13, 8}, {21, 20}})); // one Q5_K layer among i-quant ones is enough
CHECK(nv_kq_line_wanted({{12, 14}})); // Q6_K down
CHECK(nv_kq_line_wanted({{21, 7}})); // only a Q5_1 down (i-quant gate/up): the switch decides that product, so the line stands
CHECK(nv_kq_line_wanted({{21, 20}, {21, 7}}));
// apply_nv_kq_default is not called here: its two-argument path reads strata::qwen_defaults_026(), which caches STRATA_DEFAULTS at its first call,
// and the one-argument check at the end of main needs that first call to see STRATA_DEFAULTS=026.
}
{ // which cards: fused_tile::kq_takes with the engine's switches (raw compute capability, SM count)
unset("STRATA_PF_FUSED"); unset("STRATA_PF_FUSED_KQ"); unset("STRATA_PF_FUSED_SM40"); unset("STRATA_PF_FUSED_SM86");
CHECK(nv_kq_fused_here(8, 6, 84) && nv_kq_fused_here(8, 6, 80) && nv_kq_fused_here(12, 0, 110) && nv_kq_fused_here(12, 0, 80)); // RTX A6000, RTX PRO 5000 class
+14 -1
View File
@@ -4049,6 +4049,9 @@ int main(int argc, char** argv) {
"#1630); 7500 and below were stable. Kept as asked; a bare --prefill auto stops at %lld\n",
o.prefill_cap_warn.c_str(), (long long) strata::platform::host_limits::kWinHipAutoChunkCap);
#if !defined(STRATA_USE_HIP) && !defined(STRATA_GPU_METAL)
// the start-up line about K-quant experts: the default is set here (before any engine code reads its switches), the line is printed once the expert layout is
// loaded and only when the loaded set has K-quant experts (strata::core::nv_kq_line_wanted), so a model without them says nothing untrue
bool kq_line_pending = false, kq_line_fused = false;
{ // CUDA sm_86 / sm_60: the switches that are exact AND faster there are on by default (strata/core/nv_defaults.hpp), when every
// visible card has that one compute capability; before any engine code reads its switches, the user's own settings are kept
int nd = 0;
@@ -4077,7 +4080,8 @@ int main(int argc, char** argv) {
cudaDeviceGetAttribute(&sms, cudaDevAttrMultiProcessorCount, d) == cudaSuccess && strata::core::nv_kq_fused_here(m, n, sms))
kq_fused_here = true;
}
strata::core::apply_nv_kq_default(lo_m, lo_n, kq_fused_here);
kq_line_pending = !strata::core::apply_nv_kq_default(lo_m, lo_n, kq_fused_here, false).empty();
kq_line_fused = kq_fused_here;
}
}
(void) cudaGetLastError();
@@ -4825,6 +4829,15 @@ int main(int argc, char** argv) {
(void) strata::prefill::mmq::supported(f.d_type);
#endif
}
#if !defined(STRATA_USE_HIP) && !defined(STRATA_GPU_METAL)
if (kq_line_pending && lay.native) {
std::vector<std::pair<int, int>> kq_types;
kq_types.reserve(lay.fmt.size());
for (const auto& f : lay.fmt) kq_types.emplace_back(f.gu_type, f.d_type);
if (strata::core::nv_kq_line_wanted(kq_types))
std::fprintf(stderr, "%s\n", strata::core::nv_kq_default_line(kq_line_fused).c_str());
}
#endif
// APR (prism.hadamard) packs: every expert path rotates its activations (CPU pool: native_quant_act / _h;
// GPU verify, remote GPUs, prompt FP16 path: hadamard_rows). Validated end to end on CUDA (sm_86, sm_89 with
// a two-GPU layer split and peer decode, sm_120) and on HIP gfx1151. Other HIP architectures run the same