Repository navigation
Expand file tree
/
Copy pathnv_defaults.cpp
More file actions
167 lines (155 loc) · 9.16 KB
/
Copy pathnv_defaults.cpp
File metadata and controls
167 lines (155 loc) · 9.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// src/core/nv_defaults.cpp - see include/strata/core/nv_defaults.hpp.
#include "strata/core/nv_defaults.hpp"
#include "strata/core/defaults_026.hpp"
#include "strata/core/emulate.hpp"
#include <cstdio>
#include <cstdlib>
namespace strata::core {
namespace {
bool off(const char* name) {
const char* v = std::getenv(name);
return v != nullptr && v[0] == '0';
}
} // namespace
std::vector<std::pair<std::string, std::string>> nv_default_env(int major, int minor) {
return nv_default_env(major, minor, strata::qwen_defaults_026());
}
std::vector<std::pair<std::string, std::string>> nv_default_env(int major, int minor, bool defaults026) {
std::vector<std::pair<std::string, std::string>> t;
const int mj = strata::cc_major_of(major), mn = strata::cc_minor_of(minor);
if (mj == 8 && mn == 6) {
if (off("STRATA_SM86_PERF")) return t;
t = {
// 148-nv, RTX 3060 + RTX A4000 (IQ3_XXS, default flags, 8 pairs): the stack +9.6% / +14.6% (8/8 each), identity gate IDENTICAL.
// Each is in because removing it from the full stack cost speed on a card (drop-one, 4 rounds) and saved none on the other.
{"STRATA_ADAPT_NOWAIT", "1"}, // A4000 -6.3 points when removed (with ADAPT_LAG), 3060 -0.8
{"STRATA_ADAPT_LAG", "2"},
{"STRATA_CPU_IQ_ALL_EXACT1", "1"}, // A4000 -3.3, 3060 -0.6
{"STRATA_SIDE_MIXER", "2"}, // A4000 -1.2, 3060 -2.3
{"STRATA_ATTN_DAILY", "1"}, // -1.2, -1.3
{"STRATA_GR_UP75", "1"}, // -0.9, -1.8
{"STRATA_GU_SWIGLU", "1"}, // -0.8, -1.4
{"STRATA_QSA_ROWS", "1"}, // -0.5, -1.2
{"STRATA_B6_MMVQ_ROWS", "1"}, // A4000 0, 3060 -1.7
};
} else if (mj == 6 && mn == 0) {
if (off("STRATA_SM60_PERF")) return t;
t = {
// 148-nv, Tesla P100 (IQ3_XXS, default flags, 8 pairs): the stack +17.8% (8/8), identity gate IDENTICAL.
{"STRATA_ADAPT_NOWAIT", "1"}, // -10 points when removed (with ADAPT_LAG)
{"STRATA_ADAPT_LAG", "2"},
{"STRATA_SIDE_MIXER", "2"}, // -1.8
{"STRATA_FUSE_WAIT", "2"}, // -1.6
{"STRATA_B6_MMVQ_ROWS", "1"}, // -1.3
{"STRATA_FUSE_DECODE", "1"}, // -1.3
{"STRATA_GR_UP75", "1"}, // -1.2
};
} else if (mj == 12 && mn == 1) {
// GB10 (NVIDIA DGX Spark, 48 SMs, unified memory): only what was measured on that part goes in. New in 0.2.7.1, so
// STRATA_DEFAULTS=026 (the master switch of everything since 0.2.6) leaves the table out, like STRATA_SM121_PERF=0.
if (off("STRATA_SM121_PERF") || defaults026) return t;
t = {
// the fused IQ prompt kernels. IQ3_S, 64K context, fresh 4K/16K/32K prompts at T=0, 3 paired rounds against
// the same tree without it: prompt 1.139 / 1.149 / 1.121, decode unchanged; 5 of 5 greedy answers byte-
// identical with it on and off (docs/DGX_SPARK_LINUX.md; HANDOVER §6.2). It rounds differently from MMQ,
// so it is a default with an off switch, like the sm_86 table.
{"STRATA_PF_FUSED", "1"},
// NVFP4 prompt MMQ with FP4 activations (W4A4), the Blackwell path the engine keeps opt-in. On this part, the
// NVFP4 pack measured prompt 1.106x at 4K and 1.229x at 16K against the default W4A8 MMQ, decode unchanged
// (1.015x), and 24 of 24 greedy answers byte-identical with it on and off. Opt-in upstream because it is only
// checked on Blackwell; switched on here for the same reason as the row above, with the same off switch.
{"STRATA_PREFILL_NVFP4", "w4a4"},
// the hyper-connection read's fused up projection + mix (gr_upmix). Measured on IQ3_S against the unfused read:
// decode 1.054x [1.007, 1.089], prompt unchanged, and 24 of 24 greedy answers byte-identical (the parity test
// src/prefill/gr_upmix_parity.cu covers it upstream). The HC read is ~13% of a decode round here, which is
// why a fusion on it moves the number at all.
{"STRATA_HC_UPMIX", "1"},
// Run the mixer's input-only QSA/GDN work on graph branches. With the grouped experts' mode 8 selected,
// fixed-work IQ3_S decode measured +6.68% paired median and +6.67% geometric mean over 8 balanced pairs
// (AB +11.60%, BA +6.68%, identical 512-token output and verifier work). The branch changes no arithmetic.
{"STRATA_SIDE_MIXER", "2"},
// the cost-aware MTP window: pick the verify window from what a draft costs against what it has been paying.
// Measured on IQ3_S: decode 1.047x [1.019, 1.079], prompt unchanged, 24 of 24 greedy answers byte-identical.
// It only changes which drafts are attempted, and every draft is verified, so the answers cannot drift.
{"STRATA_SPEC_COST", "1"},
};
}
return t;
}
std::vector<std::string> apply_nv_defaults(int major, int minor) {
const int mj = strata::cc_major_of(major), mn = strata::cc_minor_of(minor);
std::vector<std::string> set;
for (const auto& kv : nv_default_env(major, minor)) {
if (std::getenv(kv.first.c_str()) != nullptr) continue; // the user's setting wins, whatever it is
#if defined(_WIN32)
_putenv_s(kv.first.c_str(), kv.second.c_str());
#else
setenv(kv.first.c_str(), kv.second.c_str(), 0);
#endif
set.push_back(kv.first);
}
if (!set.empty()) {
const bool sm86 = mj == 8;
const bool sm121 = mj == 12 && mn == 1;
// sm_86 / sm_60: bit-exact switches. sm_121: the fused prompt path and the FP4-activation NVFP4 prompt round differently from the
// paths they replace (24 of 24 greedy answers were identical on the Spark; no KL run), so the line does not say "exact".
std::fprintf(stderr, "strata: %s: %zu %sspeed switches on by default (%s=0 turns them off%s; a switch you set is kept): ",
sm86 ? "sm_86 (Ampere)" : sm121 ? "sm_121 (GB10)" : "sm_60 (Pascal)", set.size(), sm121 ? "" : "exact ",
sm86 ? "STRATA_SM86_PERF" : sm121 ? "STRATA_SM121_PERF" : "STRATA_SM60_PERF",
sm121 ? ", as does STRATA_DEFAULTS=026" : "");
for (size_t i = 0; i < set.size(); ++i) std::fprintf(stderr, "%s%s", i ? " " : "", set[i].c_str() + 7);
std::fprintf(stderr, "\n");
}
return set;
}
std::vector<std::pair<std::string, std::string>> nv_kq_default_env(int min_major, int min_minor) {
return nv_kq_default_env(min_major, min_minor, strata::qwen_defaults_026());
}
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>> t;
if (defaults026) return t;
if (strata::cc_major_of(min_major) < 8) return t; // Volta / Turing / Pascal: not measured, keep the FP16 prompt path
const char* sw = std::getenv("STRATA_NV_KQ_DEFAULT");
if (sw != nullptr && sw[0] == '0') return t;
if (!kNvKqDefaultOn && !(sw != nullptr && sw[0] == '1')) return t;
t.push_back({"STRATA_MMQ_KQ", "1"});
(void) min_minor;
return t;
}
std::vector<std::string> apply_nv_kq_default(int min_major, int min_minor) {
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
#if defined(_WIN32)
_putenv_s(kv.first.c_str(), kv.second.c_str());
#else
setenv(kv.first.c_str(), kv.second.c_str(), 0);
#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
std::fprintf(stderr, "strata: a model with K-quant experts (Unsloth UD-Q4/Q5/Q6_K_XL) reads its prompt on llama.cpp's MMQ kernels "
"(STRATA_MMQ_KQ=0 or STRATA_NV_KQ_DEFAULT=0 turns it off)\n");
return set;
}
void apply_spec_adapt_default(int major, int minor) {
const int mj = strata::cc_major_of(major), mn = strata::cc_minor_of(minor);
// sm_86 only: the P100 (sm_60) gained 4-16% on JSON/code/chat/tool calls but lost 3% on the 4K agent transcript (5/5 pairs), so there it stays opt-in
// Owner round 9 (2026-10-22): on the z440 A4000s the 5-pair A/B against 0.2.2 was 0.995 (code 0.996, json 1.019, tool 0.973,
// agent 0.991) and the 3060 was length-confounded, so the earlier +9..17% did not reproduce: opt-in (STRATA_SPEC_ADAPT_SM86=1)
// until a clean A/B shows it.
const bool sm86 = mj == 8 && mn == 6;
if (!sm86) return;
if (const char* v = std::getenv("STRATA_SPEC_ADAPT_SM86"); v == nullptr || v[0] != '1') return;
if (off("STRATA_SM86_PERF")) return;
const std::pair<const char*, const char*> kv[2] = {{"STRATA_SPEC_ADAPT_EVERY", "2"}, {"STRATA_SPEC_ADAPT_WARM", "200"}};
for (const auto& p : kv) {
if (std::getenv(p.first) != nullptr) continue;
#if defined(_WIN32)
_putenv_s(p.first, p.second);
#else
setenv(p.first, p.second, 0);
#endif
}
}
} // namespace strata::core