Assume the NNUE is modified to add an RMSNorm on the 256dim embedding, should this occur before the clip/packu or after, or maybe doesn't make sense to norm here.
Assistant
RMSNorm is a normalization technique that is typically applied to the output of a linear layer or an embedding layer. In the context of the NNUE, the 256dim embedding is the output of the input layer, which is then passed through a clip/packu operation.
Applying RMSNorm before the clip/packu operation would normalize the embedding values before they are clipped and packed. This could potentially help to:
User
Does normalization make sense here for a NNUE, or perhaps just at the final 64 layer at end?
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Reduce the effect of outliers in the embedding values, which could improve the stability of the network.
Improve the conditioning of the input data, which could make the network more robust to different input distributions.
On the other hand, applying RMSNorm after the clip/packu operation might not be as effective, since the clipping and packing operations would already have altered the distribution of the embedding values.
However, it's also possible that applying RMSNorm at this point in the network might not make sense at all. The NNUE is a highly optimized and specialized network architecture, and adding RMSNorm might disrupt the careful tuning of the network's weights and biases.
To determine whether RMSNorm is beneficial in this context, I would recommend experimenting with both approaches (applying RMSNorm before and after the clip/packu operation) and evaluating the impact on the network's performance. It's also possible that RMSNorm might not be necessary at all, and the network might perform well without it.
Here's an example of how you could modify the halfkp_relu_quant_affine_relu function to apply RMSNorm before the clip/packu operation:
c
INLINE void halfkp_relu_quant_affine_relu(int8_t *weights, int32_t *biases, int16_t *us_accum, int16_t *opp_accum, float *outputs) {
// ...
// Apply RMSNorm to the embedding values
for (int i = 0; i < KPSIZE / vepi16_cnt; i++) {
vepi16 embedding = vepi16_load(us_accum + i * vepi16_cnt);
vepi16 rmsnorm_embedding = vepi16_rmsnorm(embedding);
vepi16_store(us_accum + i * vepi16_cnt, rmsnorm_embedding);
}
// Clip and pack the embedding values
for (int i = 0; i < KPSIZE / vepi16_cnt; i += 2) {
// ...
}
// ...
}
Note that this is just a hypothetical example, and you would need to implement the vepi16_rmsnorm function to perform the actual RMSNorm computation.
Normalization can be beneficial in various parts of a neural network, but in the context of a NNUE, it might not be necessary or even counterproductive in the early layers.
NNUEs are designed to be highly efficient and optimized for chess evaluation, and the input data is already carefully crafted to be compact and informative. The input layer is essentially a lookup table that maps chess positions to a set of learned features, which are then processed by the subsequent layers.
In this context, normalizing the input data or the early layers might not provide significant benefits for several reasons:
Input data is already normalized: The input data is a set of binary features (piece presence/absence, piece types, etc.) that are already normalized in the sense that they have a fixed range (0/1) and are not subject to large variations.
Early layers are designed for feature extraction: The early layers of a NNUE are designed to extract specific features from the input data, such as piece interactions, pawn structure, and so on. Normalization might interfere with this feature extraction process.
Efficiency concerns: NNUEs are optimized for performance, and adding normalization layers can increase computational overhead.
However, normalizing the final layer (the 64-neuron layer) might be more beneficial, as it can help with:
Output scaling: Normalization can help scale the output values to a common range, which can improve the stability and interpretability of the evaluation scores.
Reducing overfitting: Normalization can help reduce overfitting by preventing any single neuron from dominating the output.
If you decide to apply normalization, I would recommend exploring the following options:
Only normalize the final layer: Apply normalization only to the output of the final 64-neuron layer.
Use a simple normalization scheme: Use a simple normalization scheme, such as L2 normalization or scaling, to avoid introducing additional complexity.
Experiment and evaluate: Experiment with different normalization schemes and evaluate their impact on the NNUE's performance.
Here's an updated example of how you could modify the output_transform function to apply L2 normalization to the final layer: