Merge branch 'f-139b-spd' into f-139-rel

# Conflicts:
#	src/core/expert_source.cpp
#	src/kernels/cuda/iq_kernels.cu
This commit is contained in:
Niko1221 committed 2026-10-04 10:12:55 +02:00
commit 4f5e6c841d
53 files changed
+3426 -493

No files matched your search

+30 -12
View File
@@ -2127,16 +2127,30 @@ void expert_pool_dispatch_multi(ExpertDispatch& d, const float* x_f, const int32
for (int64_t i = 0; i < n; ++i) if (d.remote[r]->owns(i)) kind[i] = 2;
}
}
static const bool dec_batch = [] { const char* v = std::getenv("STRATA_DEC_BATCH"); return v == nullptr || std::atoi(v) != 0; }();
// the GPU's copy_rows_from_mapped zeroes the rows it computed itself (dec_batch); STRATA_VERIFY_DEVICE_PLAN's
// copy_or_zero_from_mapped copies every row, so there the host still zeroes them
static const bool device_plan = [] { const char* v = std::getenv("STRATA_VERIFY_DEVICE_PLAN"); return v != nullptr && std::atoi(v) != 0; }();
const bool gpu_zeroes_hits = (d.plan != nullptr && n <= kMaxWindowEntries && n <= d.plan->cap && dec_batch && !device_plan);
bool any_cpu = false;
for (int64_t i = 0; i < n; ++i)
if (kind[i] < 0) { any_cpu = true; break; }
const auto c1 = std::chrono::steady_clock::now();
if (native && strata::kernels::cpu::q2_native_kernels(lay.fmt[(size_t) d.layers].gu_type)) // a native Q2_0 pack: the Q2_0 kernels' activations
for (int64_t t = 0; t < n_tok; ++t) act_quant_any(x_f + (size_t) t * H, H, d.act_multi[(size_t) t]);
else if (native)
for (int64_t t = 0; t < n_tok; ++t)
native_quant_act(lay.fmt[(size_t) d.layers], x_f + (size_t) t * H, d.nact_multi.data() + (size_t) t * kNativeActBytes);
else
for (int64_t t = 0; t < n_tok; ++t) act_quant_q8_1(x_f + (size_t) t * H, H, d.act_multi[(size_t) t]);
if (any_cpu) {
// #578 --remote-expert-opt: a token whose experts all run on a GPU (CUDA0 or a helper) needs no CPU activation
const bool ep = d.remote_count > 0 && d.remote[0]->optimized_decode();
for (int64_t t = 0; t < n_tok; ++t) {
if (ep && std::all_of(kind + t * k, kind + (t + 1) * k, [](int32_t v) { return v >= 0; })) continue;
if (native && strata::kernels::cpu::q2_native_kernels(lay.fmt[(size_t) d.layers].gu_type)) // a native Q2_0 pack: the Q2_0 kernels' activations
act_quant_any(x_f + (size_t) t * H, H, d.act_multi[(size_t) t]);
else if (native)
native_quant_act(lay.fmt[(size_t) d.layers], x_f + (size_t) t * H, d.nact_multi.data() + (size_t) t * kNativeActBytes);
else
act_quant_q8_1(x_f + (size_t) t * H, H, d.act_multi[(size_t) t]);
}
}
const auto c2 = std::chrono::steady_clock::now();
{ // CS-T: the experts the CPU computes, fetched together (the GGUF in place reads them on several threads)
if (any_cpu) { // CS-T: the experts the CPU computes, fetched together (the GGUF in place reads them on several threads)
static thread_local std::vector<int64_t> miss;
miss.clear();
for (int64_t i = 0; i < n_tok * k; ++i)
@@ -2162,8 +2176,10 @@ void expert_pool_dispatch_multi(ExpertDispatch& d, const float* x_f, const int32
if (kind[i] == 0) ++d.cache_hits;
else ++d.offload_entries; // #588: PCIe or another GPU
if (kind[i] == 2 && d.peer != nullptr) ++d.peer_entries;
// multi-GPU: a direct peer launch is writing this row right now - zeroing it would race it
if (!(kind[i] == 2 && d.peer != nullptr && d.peer->launched_direct()))
// multi-GPU: a direct peer launch is writing this row right now - zeroing it would race it;
// dec_batch: copy_rows_from_mapped_kernel already zeroes kind 0/1 rows on the GPU
if (!((kind[i] == 2 && d.peer != nullptr && d.peer->launched_direct()) ||
(gpu_zeroes_hits && (kind[i] == 0 || kind[i] == 1))))
std::memset(row, 0, (size_t) H * sizeof(float));
continue;
}
@@ -2193,8 +2209,10 @@ void expert_pool_dispatch_multi(ExpertDispatch& d, const float* x_f, const int32
}
const auto c3 = std::chrono::steady_clock::now();
pt("run", njobs);
if (native) d.pool->run_split_multi_native(lay.fmt[(size_t) d.layers], d.jobs_multi.data(), njobs);
else d.pool->run_split_multi(d.jobs_multi.data(), njobs);
if (njobs > 0) {
if (native) d.pool->run_split_multi_native(lay.fmt[(size_t) d.layers], d.jobs_multi.data(), njobs);
else d.pool->run_split_multi(d.jobs_multi.data(), njobs);
}
if (d.remote_count > 0) {
static thread_local std::string remote_error;
for (int r = 0; r < d.remote_count; ++r)