Merge f-nvfp4 into f-144-rel

This commit is contained in:
Niko1221 committed 2026-10-13 09:21:19 +02:00
commit 66db34dc40
36 files changed
+3374 -158

No files matched your search

+25 -5
View File
@@ -2796,8 +2796,13 @@ int main(int argc, char** argv) {
// link (the copy kernel, since 0.1.14), so on a slower link it must shrink or the window waits for it. The
// real H2D bandwidth is probed once; from 20 GB/s up (x16 PCIe 4/5) the measured default stays. The canonical
// pack keeps 0.2 as its start value (0.1.43: PcieAuto refines it on CUDA). `--calibrate` measures it outright.
// NVFP4 packs: 0.25. Their 2.76 MB experts cross the link twice as long as the i-quants' the 0.55 was
// measured on, and that copy sits on the GPU's critical path while the CPU pool runs beside it: decode
// 103 -> 117 tok/s short, 105 -> 124 at 32K (RTX 5090, PCIe 5 x16, 9950X3D; 0.10 and 0.40 both slower).
if (o.pcie_frac < 0.0) {
const double base = native_pack ? 0.55 : 0.2;
const auto& lay0 = strata::kernels::cpu::expert_layout();
const bool nvfp4_pack = native_pack && !lay0.fmt.empty() && lay0.fmt[0].gu_type == 40;
const double base = nvfp4_pack ? 0.25 : native_pack ? 0.55 : 0.2;
std::string bursts;
const char* pfd = std::getenv("STRATA_PCIE_FRAC_DEFAULT");
const bool pf_old = pfd != nullptr && std::strcmp(pfd, "old") == 0;
@@ -5125,7 +5130,10 @@ int main(int argc, char** argv) {
size_t free_b = 0, total_b = 0;
free_b = strata::core::device_free_bytes(); (void) total_b;
const auto& lay = strata::kernels::cpu::expert_layout();
const uint64_t budget = (uint64_t) o.expert_cache * lay.max_blob; // what the uniform sizing granted
// what the uniform sizing granted, in the 256-byte slots the loop below counts: the blob formats of 1280 / 2560
// rows are whole multiples of 256 already; an NVFP4 blob's 16-byte scale tail is not, and the unrounded budget
// held one slot fewer than asked (--expert-cache 1: none)
const uint64_t budget = (uint64_t) o.expert_cache * ((lay.max_blob + 255) / 256 * 256);
uint64_t used = 0;
const size_t keep_free = ((size_t) o.vram_reserve_mib << 20) + (size_t) pipe_first;
size_t free_room = free_b > keep_free ? free_b - keep_free : 0;
@@ -8476,9 +8484,21 @@ int main(int argc, char** argv) {
const double max_cached = mcs != nullptr && mcs[0] != 0 ? std::atof(mcs) / 100.0 : max_cached_default;
const bool nearly_all_cached = !host_res.empty() && !all_experts_resident &&
(double) cached_experts >= max_cached * (double) host_res.size();
const bool tail_default_ok = tse == nullptr && !all_experts_resident && !nearly_all_cached && o.batch == 0 &&
decode_defaults_arch_ok() &&
o.peer_device < 0;
// NVFP4 experts (any layer): no default (sergqwer/strata-nvfp4 c83625c3). On the fork's qwen-nvfp4-gptq pack the
// skip moved the answers by teacher-forced KL 0.035 against it off - as much as the GPTQ quantization's own error
// against an all-Q8_0 reference (0.038) - for +11.5% decode (RTX 5090). STRATA_ROUTE_TAIL_SKIP=7 opts in.
bool nvfp4_experts = false;
if (native_pack)
for (const auto& f : strata::kernels::cpu::expert_layout().fmt)
nvfp4_experts = nvfp4_experts || f.gu_type == strata::kernels::cpu::kNvfp4Type ||
f.d_type == strata::kernels::cpu::kNvfp4Type;
const bool tail_default_path = tse == nullptr && !all_experts_resident && !nearly_all_cached && o.batch == 0 &&
decode_defaults_arch_ok() &&
o.peer_device < 0;
const bool tail_default_ok = tail_default_path && !nvfp4_experts;
if (tail_default_path && nvfp4_experts)
std::fprintf(stderr, "strata serve: STRATA_ROUTE_TAIL_SKIP is off by default with NVFP4 experts (it moved an NVFP4 "
"pack's answers by about as much as its quantization does); STRATA_ROUTE_TAIL_SKIP=7 turns it on\n");
if (tse == nullptr && nearly_all_cached && o.batch == 0 && o.peer_device < 0 && decode_defaults_arch_ok())
std::fprintf(stderr, "strata serve: STRATA_ROUTE_TAIL_SKIP is off by default: %.1f%% of the experts are in the GPU cache, so "
"few are missed and skipping them costs more draft acceptance than it saves; "