Open
Conversation
The engine previously searched to a fixed depth (default 3) regardless of available time, wasting most of the allocated thinking time in timed games. With 60s per move, the engine would finish in <1s. Add search_move_timed() to AlphaBeta that uses iterative deepening under a time constraint: searches depth 1, 2, 3, ... until time runs out, keeping the best move from the last completed depth. Time is checked every 512 nodes to minimize overshoot. Update the UCI handler to parse go parameters (wtime, btime, winc, binc, movetime, movestogo, depth) and calculate appropriate time allocation per move with 1-second safety margins for Python overhead.
Implement a dual-perspective NNUE (Efficiently Updatable Neural Network) evaluator following the Stockfish architecture pattern. The network uses 768 sparse binary features, shared feature transformer weights, SCReLU activation, and incremental accumulator updates during search for efficient inference using only numpy. Architecture: 768 → Linear(768,128) → SCReLU → concat(stm,nstm) → Linear(256,1) Parameters: ~99K | Model size: 386 KB | Inference: ~8μs per position Key components: - moonfish/evaluation/nn.py: NNUEEvaluator with dual-perspective accumulators and incremental updates for all move types (quiet, capture, castling, en passant, promotion) - moonfish/engines/nn_engine.py: NNEngine with accumulator save/restore on the search stack, supporting both fixed-depth and timed iterative deepening - moonfish/evaluation/base.py: Evaluator protocol for pluggable evaluation - moonfish/evaluation/classical.py: ClassicalEvaluator wrapping PeSTO tables - scripts/generate_training_data.py: Stockfish-labeled position generator - scripts/train_nnue.py: PyTorch training with sigmoid-scaled MSE + WDL loss - moonfish/models/nnue_v1.npz: Pre-trained weights (96K positions, depth 8) Integration: - New --algorithm nn flag and --nn-model-path CLI option - Bundled model auto-discovered from package directory - numpy added as core dependency; torch as optional [nn] extra - Full UCI compatibility including go movetime/depth/wtime+btime
BenchmarksThe following benchmarks are available for this PR:
Post a comment with the command to trigger a benchmark run. |
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
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.
Summary
NNEnginewith accumulator state management (save/restore on push/pop) supporting both fixed-depth and timed iterative deepeningscripts/generate_training_data.py) and PyTorch training with sigmoid-scaled MSE + WDL loss (scripts/train_nnue.py)moonfish/models/nnue_v1.npz, 386 KB, ~99K parameters) trained on 96K positions at depth 8Architecture
Verification Results
Inference Speed
Accumulator Correctness
All special move types verified (incremental update matches full recomputation):
NPS Benchmark (depth 3, 48 Stockfish positions)
UCI Test
Existing Tests
Usage
Files Changed
moonfish/evaluation/nn.pymoonfish/evaluation/base.pymoonfish/evaluation/classical.pymoonfish/evaluation/__init__.pymoonfish/engines/nn_engine.pymoonfish/models/nnue_v1.npzscripts/generate_training_data.pyscripts/train_nnue.pymoonfish/config.pynn_model_pathfieldmoonfish/helper.pynnalgorithm, factory function, default model discoverymoonfish/main.py--nn-model-pathCLI optionpyproject.tomlnumpydep,[nn]optional (torch), evaluation/engine packagesTest plan
go movetime,go depthwork with--algorithm nnget_engine()correctly creates NNEngine with bundled model