Skip to content

DRAFT: Jac/rust parallel cache#356

Open
adamantivm wants to merge 8 commits into
jonbinney:mainfrom
adamantivm:jac/rust-parallel-cache
Open

DRAFT: Jac/rust parallel cache#356
adamantivm wants to merge 8 commits into
jonbinney:mainfrom
adamantivm:jac/rust-parallel-cache

Conversation

@adamantivm

Copy link
Copy Markdown
Collaborator

No description provided.

Julian Cerruti added 8 commits March 12, 2026 22:12
…ly required &mut self, which\nprevented sharing an evaluator across threads. Since\nort::Session::run() already takes &self, OnnxEvaluator\nworks with &self trivially. This prepares for thread-safe\nsharing of evaluators in parallel game execution."}

</invoke>
AlphaZeroAgent now holds Arc<dyn Evaluator + Send + Sync>
instead of owning OnnxEvaluator directly. The evaluator is
created externally and shared via Arc, preparing for
multi-threaded parallel game execution where multiple agents
share a single evaluator with caching.
Adds a thread-safe CachingEvaluator that wraps an ONNX session
with an LRU cache keyed by GameState::get_fast_hash(). Cache
hits skip NN inference entirely. Supports model hot-reload via
reload_model() which replaces the session and clears the cache.
Uses Mutex for both session and cache since ort Session::run()
requires &mut self.
Implement play_games_parallel() in game_runner.rs using
std::thread::scope to run games across multiple threads.
Each thread shares the evaluator via Arc and creates its
own AlphaZeroAgent instances. Function and imports are
feature-gated behind binary. Includes two integration tests.
Add --parallel-games and --max-cache-size CLI flags.
When parallel_games > 1 and using AlphaZero self-play,
use CachingEvaluator + play_games_parallel for both
batch and continuous modes. In continuous mode, use
reload_model for hot-reload without recreating the
evaluator. Sequential mode preserved as fallback.
Remove NN Evaluation Caching item (now implemented).
Rename Batch Search to Batched NN Inference and update
description to focus on batching MCTS leaves across
trees into a single GPU forward pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant