DRAFT: Jac/rust parallel cache#356
Open
adamantivm wants to merge 8 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.