diff --git a/include/strata/core/remote_experts.hpp b/include/strata/core/remote_experts.hpp index 224d24f5..218ff55b 100644 --- a/include/strata/core/remote_experts.hpp +++ b/include/strata/core/remote_experts.hpp @@ -37,6 +37,8 @@ public: int64_t k, const int32_t* kind, const int32_t* primary_res, std::string& err); bool owns(int64_t index) const { return owned_[(size_t) index] != 0; } + /// This helper's cache holds (layer, expert): begin() will take its rows unless the plan gave them away. + bool holds(int64_t layer, int32_t expert) const { return cache_.slot_of(layer, expert) >= 0; } bool optimized_decode() const { return remote_opt_ != nullptr; } bool finish(float* out, std::string& err); int64_t resident() const { return cache_.resident(); } diff --git a/src/core/expert_source.cpp b/src/core/expert_source.cpp index 98e1952d..c145db45 100644 --- a/src/core/expert_source.cpp +++ b/src/core/expert_source.cpp @@ -2020,6 +2020,15 @@ void expert_pool_dispatch_multi(ExpertDispatch& d, const float* x_f, const int32 if (d.plan != nullptr && n <= kMaxWindowEntries && n <= d.plan->cap) { int64_t distinct[kMaxWindowEntries], first_of[kMaxWindowEntries]; int nd = 0, nmiss = 0; + // a helper GPU (RemoteExperts) holding the expert computes it in its own VRAM once begin() claims the row: like + // the peer tier's, such an expert is no miss of this plan and never part of the PCIe share, which would read it + // over the primary's link instead (2x RX 6900 XT, IQ3_S, --remote-expert-opt with the probed share 0.39: ~4 + // helper experts per layer-window moved to PCIe, 59 ms per window against 34 ms) + auto helper_holds = [&](int32_t e) { + for (int r = 0; r < d.remote_count; ++r) + if (d.remote[r]->holds(d.layers, e)) return true; + return false; + }; for (int64_t i = 0; i < n; ++i) { first_of[i] = i; for (int64_t j = 0; j < i; ++j) @@ -2028,7 +2037,7 @@ void expert_pool_dispatch_multi(ExpertDispatch& d, const float* x_f, const int32 distinct[nd++] = i; const int32_t e = ids[i]; if (e >= 0 && e < d.n_expert && d.host_res[(size_t) d.layers * (size_t) d.n_expert + (size_t) e] < 0 && - !(d.peer != nullptr && d.peer->has(d.layers, e))) ++nmiss; + !(d.peer != nullptr && d.peer->has(d.layers, e)) && !helper_holds(e)) ++nmiss; } } const bool pcie_ok = d.pcie_num > 0 && d.src->pcie_layer(d.layers); @@ -2050,6 +2059,8 @@ void expert_pool_dispatch_multi(ExpertDispatch& d, const float* x_f, const int32 : (size_t) slot * (size_t) d.cache_blob)); } else if (d.peer != nullptr && d.peer->has(d.layers, e)) { kd = 2; // multi-GPU: the second GPU computes it + } else if (helper_holds(e)) { + // left to the helper: kind -1 until RemoteExperts::begin() claims the row (see above) } else { if (miss_rank >= nmiss - m && fetches < P.staging_cap && fetches < 64) { const uint8_t* src = d.src->pinned(d.layers, e) ? d.src->blob(d.layers, e) : nullptr;