Merge pull request #69 from rektdie/net1.5

new net trained on 6GB of data, 0.65 WDL + output buckets | bench 3370940
This commit was merged in pull request #69.
This commit is contained in:
rektdie authored and GitHub committed 2025-05-31 17:26:20 +02:00
commit 21a9894662
4 files changed
+18 -30

No files matched your search

BIN
View File
Binary file not shown.
-20
View File
@@ -218,26 +218,6 @@ void Board::PrintBoard() {
}
void Board::PrintNNUE() {
std::cout << "First 16 HL biases: ";
for (int i = 0; i < 16; i++) {
std::cout << NNUE::net.accumulator_biases[i] << ' ';
}
std::cout << std::endl;
std::cout << "Output neuron bias: " << NNUE::net.output_bias << std::endl;
std::cout << "First 16 accumulator values (pre-activation)[white] ";
for (int i = 0; i < 16; i++) {
if (accPair.white[i] != 0) {
std::cout << accPair.white[i] << ' ';
}
}
std::cout << std::endl;
std::cout << "Final eval: " << NNUE::net.Evaluate(*this) << std::endl;
}
+15 -8
View File
@@ -27,11 +27,15 @@ void Network::Load(const std::string& path) {
// Output weights
for (size_t i = 0; i < output_weights.size(); i++) {
file.read(reinterpret_cast<char*>(&output_weights[i]), sizeof(int16_t));
for (size_t j = 0; j < output_weights[i].size(); j++) {
file.read(reinterpret_cast<char*>(&output_weights[i][j]), sizeof(int16_t));
}
}
// Output bias
file.read(reinterpret_cast<char*>(&output_bias), sizeof(int16_t));
// Output biases
for (size_t i = 0; i < output_bias.size(); i++) {
file.read(reinterpret_cast<char*>(&output_bias[i]), sizeof(int16_t));
}
}
#if defined(__x86_64__) || defined(__amd64__) || (defined(_WIN64) && (defined(_M_X64) || defined(_M_AMD64)))
@@ -89,7 +93,7 @@ using nativeVector = __m128i;
}
#endif
static int32_t VectorizedSCReLU(const Board& board, const Network& net) {
static int32_t VectorizedSCReLU(const Board& board, const Network& net, size_t outputBucket) {
const size_t VECTOR_SIZE = sizeof(nativeVector) / sizeof(int16_t);
static_assert(HL_SIZE % VECTOR_SIZE == 0, "HL size must be divisible by the native register size of your CPU for vectorization to work");
@@ -111,8 +115,8 @@ static int32_t VectorizedSCReLU(const Board& board, const Network& net) {
const nativeVector nstmClamped = min_epi16(VEC_QA, max_epi16(nstmAccumValues, VEC_ZERO));
// Load weights
const nativeVector stmWeights = load_epi16(reinterpret_cast<const nativeVector*>(&net.output_weights[i]));
const nativeVector nstmWeights = load_epi16(reinterpret_cast<const nativeVector*>(&net.output_weights[i + HL_SIZE]));
const nativeVector stmWeights = load_epi16(reinterpret_cast<const nativeVector*>(&net.output_weights[outputBucket][i]));
const nativeVector nstmWeights = load_epi16(reinterpret_cast<const nativeVector*>(&net.output_weights[outputBucket][i + HL_SIZE]));
// SCReLU activation
const nativeVector stmActivated = madd_epi16(stmClamped, mullo_epi16(stmClamped, stmWeights));
@@ -129,16 +133,19 @@ static int32_t VectorizedSCReLU(const Board& board, const Network& net) {
int Forward(const Board& board, const Network& net) {
bool stm = board.sideToMove;
const size_t divisor = 32 / OUTPUT_BUCKETS;
const size_t outputBucket = (board.occupied.PopCount() - 2) / divisor;
const ACC::Accumulator& stmACC = stm ? board.accPair.white : board.accPair.black;
const ACC::Accumulator& nstmACC = !stm ? board.accPair.white : board.accPair.black;
int64_t eval = 0;
eval = VectorizedSCReLU(board, net);
eval = VectorizedSCReLU(board, net, outputBucket);
eval /= QA;
eval += net.output_bias;
eval += net.output_bias[outputBucket];
return (eval * SCALE) / (QA * QB);
}
+3 -2
View File
@@ -17,6 +17,7 @@ namespace NNUE {
constexpr size_t INPUT_SIZE = 768;
constexpr size_t HL_SIZE = 256;
constexpr size_t OUTPUT_BUCKETS = 8;
constexpr int16_t SCALE = 400;
constexpr int16_t QA = 255;
@@ -25,8 +26,8 @@ constexpr int16_t QB = 64;
struct Network {
alignas(ALIGNMENT) std::array<int16_t, HL_SIZE * INPUT_SIZE> accumulator_weights;
alignas(ALIGNMENT) std::array<int16_t, HL_SIZE> accumulator_biases;
alignas(ALIGNMENT) std::array<int16_t, 2 * HL_SIZE> output_weights;
int16_t output_bias;
alignas(ALIGNMENT) std::array<std::array<int16_t, 2 * HL_SIZE>, OUTPUT_BUCKETS> output_weights;
std::array<int16_t, OUTPUT_BUCKETS> output_bias;
void Load(const std::string& path);