From e57c907221ecdaa631ff5ad28e498b63d7f6641e Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Mon, 5 Oct 2026 10:06:47 +0200 Subject: [PATCH] exchange rotation (#864) on top of the async tier (#876): rotation-aware commit_flip/commit_copies/resident_blob, test only under STRATA_BUILD_TESTS, drop a banner edit Co-authored-by: David --- CMakeLists.txt | 2 +- src/core/expert_source.cpp | 14 ++++++++++++-- src/program/generate.cpp | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fab75147..e69ece0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -423,7 +423,7 @@ if(STRATA_ENABLE_CUDA OR STRATA_ENABLE_HIP) src/core/conversation_snapshot.cpp src/core/conversation_state.cpp src/core/conversation_memory.cpp src/core/peer_experts.cpp) target_include_directories(strata_engine PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_link_libraries(strata_engine PUBLIC strata_core strata_kernels strata_kernels_cpu ${_strata_gpu_runtime_target}) - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/core/exchange_storage_test.cpp") + if(STRATA_BUILD_TESTS AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/core/exchange_storage_test.cpp") add_executable(exchange_storage_test tests/core/exchange_storage_test.cpp) target_include_directories(exchange_storage_test PRIVATE include) target_link_libraries(exchange_storage_test PRIVATE Threads::Threads) diff --git a/src/core/expert_source.cpp b/src/core/expert_source.cpp index a9cf15d1..f62ea07c 100644 --- a/src/core/expert_source.cpp +++ b/src/core/expert_source.cpp @@ -1846,6 +1846,7 @@ int64_t FileExpertSource::commit_exchanges() { } void FileExpertSource::commit_copies() { + if (exchange_storage_.active()) return; // STRATA_EXCHANGE_ROTATE: ownership moves in commit_flip, nothing to copy for (const Exchange& x : staged_) { const uint8_t* src = override_.empty() ? nullptr : override_[x.out]; const uint64_t at = complement_offsets_[x.in]; @@ -1859,6 +1860,15 @@ int64_t FileExpertSource::commit_flip() { int64_t n = 0; for (const Exchange& x : staged_) { const uint8_t* src = override_[x.out]; + if (exchange_storage_.active()) { // STRATA_EXCHANGE_ROTATE: the same ownership transfer as commit_exchanges + if (!exchange_storage_.commit(x.in, x.out, (size_t) x.q, src, (size_t) x.bytes)) { + std::fprintf(stderr, "FileExpertSource: invalid exchange rotation commit; refusing corrupt residency\n"); + std::abort(); + } + ++n; + override_[x.out] = nullptr; + continue; + } const uint64_t at = complement_offsets_[x.in]; // the same test as commit_copies: an exchange whose bytes were copied is the one that flips if (src != nullptr && at != kNoComplement && at <= complement_bytes_ && x.bytes <= complement_bytes_ - at && @@ -1875,8 +1885,8 @@ const uint8_t* FileExpertSource::resident_blob(int64_t layer, int64_t expert) co if (!complement_ready_ || complement_host_ == nullptr || layer < 0 || expert < 0 || layer >= n_layers_ || expert >= n_expert_) return nullptr; const size_t index = (size_t) layer * (size_t) n_expert_ + (size_t) expert; - if (index >= complement_offsets_.size() || complement_offsets_[index] == kNoComplement) return nullptr; - return complement_host_ + (size_t) complement_offsets_[index]; + if (index >= complement_offsets_.size()) return nullptr; + return resident_blob(index); // through the rotation's ownership table when STRATA_EXCHANGE_ROTATE is on } const uint8_t* FileExpertSource::blob(int64_t layer, int64_t expert) { diff --git a/src/program/generate.cpp b/src/program/generate.cpp index 221495dc..a8c90809 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -2498,7 +2498,8 @@ int main(int argc, char** argv) { } ss.db = &db; - // ================================ THE PLE ========================= // + // ================================ THE PLE ================================ + // // **ITS ABSENCE IS WHY GATE C1 FAILED** (LEDGER L123): layer 1 carries six `blk.1.ple_*` tensors, the whole // module was built and parity-tested, and nothing called it. Everything below is construction - the table // is a mapping of the ORIGINAL second GGUF shard, the six weights are already loaded in the arena, and the @@ -8003,7 +8004,6 @@ int main(int argc, char** argv) { std::fprintf(stderr, "strata serve: asynchronous adaptive tier: %lld rounds, %lld experts swapped in, " "%.1f ms per round (start to flip, between windows)\n", (long long) a_rounds, (long long) a_swapped, a_rounds > 0 ? a_ms / (double) a_rounds : 0.0); -======= if (src.exchange_rotation()) std::fprintf(stderr, "strata serve: exchange rotation: %llu blocks, %llu host memcpy bytes avoided (cumulative payload)\n", (unsigned long long)src.rotated_exchanges(),