The Ethereal repository contains code for a chess engine that uses neural networks to evaluate positions. The networks are defined in the network.c and nnue.c files.
Normalization is a common technique used in deep learning to normalize the inputs to a network, which can help improve the stability and speed of training. However, the networks in the Ethereal repository do not use normalization.
There are a few possible reasons why normalization may not be used in these networks:
Simple architecture: The networks in Ethereal are relatively simple, with only a few layers and a small number of neurons. Normalization may not be necessary for such simple architectures.
Specific problem domain: The networks in Ethereal are designed to evaluate chess positions, which is a specific problem domain that may not require normalization. The inputs to the network are likely to be well-behaved and not require normalization.
Custom implementation: The Ethereal repository is a custom implementation of a chess engine, and the authors may have chosen not to use normalization for specific reasons related to their implementation.
Regarding the second part of your question, an RMS (Root Mean Square) normalization in vectorized C would likely have a negligible impact on runtime performance. RMS normalization is a simple operation that involves computing the square root of the mean of the squared values of the input vector.
In vectorized C, this operation can be implemented using SIMD instructions, which can perform the same operation on multiple elements of the input vector simultaneously. This can lead to significant performance improvements compared to a scalar implementation.
However, the impact of RMS normalization on runtime performance would depend on the specific implementation and the size of the input vectors. In general, the overhead of RMS normalization is likely to be small compared to the overall computation time of the network.
To give you a rough estimate, here is an example implementation of RMS normalization in vectorized C using SIMD instructions:
c
#include <immintrin.h>
void rms_norm(float *input, float *output, int length) {
__m256 sum = _mm256_setzero_ps();
__m256 sum_squares = _mm256_setzero_ps();
for (int i = 0; i < length; i += 8) {
__m256 chunk = _mm256_loadu_ps(input + i);
sum = _mm256_add_ps(sum, chunk);
sum_squares = _mm256_add_ps(sum_squares, _mm256_mul_ps(chunk, chunk));
}
float mean = _mm256_extractf128_ps(sum, 0)[0] / length;
float mean_squares = _mm256_extractf128_ps(sum_squares, 0)[0] / length;
float rms = sqrtf(mean_squares - mean * mean);
for (int i = 0; i < length; i += 8) {
__m256 chunk = _mm256_loadu_ps(input + i);
chunk = _mm256_div_ps(chunk, _mm256_set1_ps(rms));
_mm256_storeu_ps(output + i, chunk);
}
}
This implementation uses the immintrin.h header to access SIMD instructions, and assumes that the input and output vectors are aligned to 32-byte boundaries. The rms_norm function computes the RMS normalization of the input vector and stores the result in the output vector.
Note that this is just one possible implementation, and there are many other ways to implement RMS normalization in vectorized C. The performance impact will depend on the specific implementation and the hardware platform.
The implementation I provided earlier uses SIMD instructions to perform the RMS normalization. Specifically, it uses the following instructions:
_mm256_loadu_ps: loads 8 single-precision floating-point values from memory into a 256-bit vector register
_mm256_add_ps: adds two 256-bit vector registers element-wise
_mm256_mul_ps: multiplies two 256-bit vector registers element-wise
_mm256_extractf128_ps: extracts the lower 128 bits of a 256-bit vector register as a 128-bit vector register
_mm256_set1_ps: sets all elements of a 256-bit vector register to a single value
_mm256_div_ps: divides two 256-bit vector registers element-wise
_mm256_storeu_ps: stores 8 single-precision floating-point values from a 256-bit vector register into memory
Using the Intel Intrinsics Guide, we can estimate the number of cycles required for each instruction:
_mm256_loadu_ps: 2-3 cycles
_mm256_add_ps: 2-3 cycles
_mm256_mul_ps: 4-5 cycles
_mm256_extractf128_ps: 1-2 cycles
_mm256_set1_ps: 1-2 cycles
_mm256_div_ps: 10-12 cycles
_mm256_storeu_ps: 2-3 cycles
Assuming a 2.2GHz clock frequency, we can estimate the total number of cycles required for the RMS normalization implementation:
Load input vector: 2-3 cycles
Compute sum and sum_squares: 2-3 cycles (add) + 4-5 cycles (mul) = 6-8 cycles
Compute mean and mean_squares: 1-2 cycles (extract) + 1-2 cycles (set1) = 2-4 cycles
Compute RMS: 10-12 cycles (div)
Store output vector: 2-3 cycles
Total estimated cycles: 24-40 cycles
Using the estimated cycles, we can estimate the runtime performance impact:
Assuming a 256-element input vector, the estimated runtime would be approximately 24-40 cycles * 256 elements / 2.2 GHz = 2.7-4.5 microseconds
Assuming a 1024-element input vector, the estimated runtime would be approximately 24-40 cycles * 1024 elements / 2.2 GHz = 10.9-18.2 microseconds
Please note that these estimates are rough and may vary depending on the specific hardware platform, memory bandwidth, and other factors. Additionally, this implementation is not optimized for performance, and further optimizations may be possible.
In general, the RMS normalization implementation is expected to have a negligible impact on runtime performance, especially when compared to the overall computation time of the neural network. However, the actual performance impact will depend on the specific use case and requirements.