Expand description
Load and evaluate NNUE (Efficiently Updatable Neural Network) chess networks.
The crate is small, dependency-free and cross-platform, with an optional AVX2 fast path (used automatically at runtime when available, with a scalar fallback everywhere else).
§Architectures
The architecture is detected automatically from the network file’s header:
SFNNv10— Stockfish 18 big nets with threat inputs.HalfKAv2_hm— Stockfish SFNNv5-v9 (Stockfish 16/17 and SF 18 small nets).HalfKAv2— the non-mirrored predecessor (Stockfish SFNNv2-v4, SF 14).HalfKP— the classic Stockfish NNUE feature set (Stockfish 12-14 nets).
§Integration
Feed positions either by FEN or by implementing the Board trait on your
own position type.
By FEN:
use nnue_rs::Network;
let net = Network::from_file("net.nnue")?;
let cp = net.evaluate_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1")?;By implementing Board:
use nnue_rs::{Board, Color, Piece, Network};
impl Board for MyPosition {
fn side_to_move(&self) -> Color { /* ... */ todo!() }
fn king_square(&self, color: Color) -> u8 { /* ... */ todo!() }
fn for_each_piece(&self, f: &mut dyn FnMut(u8, Piece)) { /* ... */ todo!() }
}
let score = net.evaluate(&position);§Incremental evaluation
For a search, advance an Accumulator as moves are made instead of
recomputing from scratch. See Network::accumulator, Network::update
(or Network::update_changes for known piece changes) and
Network::evaluate_accumulator. Common updates use fused arithmetic;
HalfKAv2_hm and SFNNv10 inference uses a packed first layer on AVX2 CPUs.
Public APIs and network-file formats are unchanged from 0.4.1.
Structs§
- Accumulator
- A pair of feature-transformer accumulators (one per side-to-move perspective) plus the piece count for the position they describe.
- FenBoard
- A minimal board built from a FEN string, implementing
Board. - Network
- A loaded NNUE network.
- Piece
- A colored chess piece.
Enums§
- Arch
- The feature set (input layer) an NNUE network is built on.
- Color
- Side of a piece or the side to move.
- Error
- Errors returned when loading a network or parsing a position.
- Piece
Kind - Type of a chess piece, color-independent.
Traits§
- Board
- A chess position, as seen by the network.
Type Aliases§
- Result
- Convenience alias for results returned by this crate.