What is "NNUE"?
NNUE (Efficiently Updatable Neural Network) is a neural network architecture suited to inference on CPUs.
All of today's top Xiangqi engines use NNUE. NNUE is only an evaluation network and is responsible solely for evaluating positions. (For what evaluation is, see What is "evaluation"?)
The search algorithm used by today's top Xiangqi engines is still the traditional alpha-beta (ab) pruning search.
Details
NNUE stands for Efficiently Updatable Neural Network (written backwards; Nue (鵺) is a Japanese mythical creature, and the name plays on its sound). Its core idea is to design a neural network structure especially suited to scenarios like board games, where the input changes very little. For example, when we make one move, the board changes only slightly, so we can update incrementally instead of recomputing the whole board, which greatly improves efficiency.
NNUE was originally designed for Japanese Shogi by Yu Nasu. In 2018 it was applied in Motohiro Isozaki's YaneuraOu, and in June 2019 it was ported to Stockfish by Nodchip (Hisayori Noda).
Input feature sets
First we need to convert the board position into an input the neural network can understand, which requires a feature set. Here we use Stockfish as the example.[1]
Common feature sets include HalfKP and HalfKA(v2). Stockfish used HalfKP early on and now uses HalfKAv2.
In HalfKP, K stands for King and P stands for Piece (excluding the King). Half stresses that it is one side's King. A feature is a combination of (our King's square Sk, some piece's square Sp, that piece's type Tp, that piece's relative color Cp).
In chess, a piece can be on any of 64 squares, there are only 5 piece types once the King is removed, and there are two piece colors, so the total number of features is 64×64×5×2=40960.
The A in HalfKA stands for All, meaning the piece types include the King too, treating the King like any other piece. The total number of HalfKA features is therefore 64×64×6×2=49152. This design helps NNUE capture King-related value.
HalfKAv2 reduces the number of features compared with HalfKA. The 12 piece types include our King and the opponent's King, but the first feature Sk of our King necessarily corresponds to the Tp of our King, and likewise for the opponent's King, so the two can be merged into one without distinguishing whose King it is. This brings the total down to 64×64×11=45056.
Since a chess board can be mirrored horizontally, there is also HalfKAv2_hm, where hm stands for horizontally mirrored. Our King on the left half of the board is equivalent to being on the right half, which reduces the number of King squares from 64 to 32 (total features 32×64×11=22528).
Accumulator
The accumulator is the core of NNUE's incremental update. The output of NNUE's first layer (22528->2560[2]) is stored in the accumulator. When the board changes (for example, a move is played), the accumulator changes accordingly (we only need to add or subtract the first-layer weight columns corresponding to the changed features). This lets us update the accumulator much faster without recomputing the first layer. The accumulator distinguishes our perspective from the opponent's, so there are two separate accumulators.
More
See NNUE.md: nnue-pytorch/docs/nnue.md
