implemented nnue load
This commit is contained in:
1 parent
82c969a2ad
commit
67e9ebdda3
6 files changed
+55
-6
No files matched your search
@@ -15,15 +15,14 @@ int CalculateIndex(bool perspective, int square, int pieceType, bool side) {
|
||||
|
||||
void Accumulator::Add(const NNUE::Network* net, int index) {
|
||||
for (int i = 0; i < NNUE::HL_SIZE; i ++) {
|
||||
values[i] += net->accumulator_weights[index][i];
|
||||
values[i] += net->accumulator_weights[index * NNUE::INPUT_SIZE + i];
|
||||
}
|
||||
}
|
||||
|
||||
void Accumulator::Sub(const NNUE::Network* net, int index) {
|
||||
for (int i = 0; i < NNUE::HL_SIZE; i ++) {
|
||||
values[i] -= net->accumulator_weights[index][i];
|
||||
values[i] -= net->accumulator_weights[index * NNUE::INPUT_SIZE + i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "benchmark.h"
|
||||
#include "search.h"
|
||||
#include "datagen.h"
|
||||
#include "nnue.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
MOVEGEN::initLeaperAttacks();
|
||||
@@ -12,6 +13,8 @@ int main(int argc, char* argv[]) {
|
||||
UTILS::InitZobrist();
|
||||
SEARCH::InitLMRTable();
|
||||
|
||||
NNUE::net.Load("beans.bin");
|
||||
|
||||
Board board;
|
||||
|
||||
if (argc > 1) {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include <immintrin.h>
|
||||
#include <fstream>
|
||||
|
||||
#include "nnue.h"
|
||||
#include "accumulator.h"
|
||||
#include "board.h"
|
||||
@@ -6,6 +8,43 @@
|
||||
|
||||
namespace NNUE {
|
||||
|
||||
void Network::Load(const std::string& path) {
|
||||
std::ifstream file(path, std::ios::binary);
|
||||
if (!file.is_open()){
|
||||
std::cerr << "Failed to open file " + path << std::endl;
|
||||
}
|
||||
|
||||
// HL weights
|
||||
for (int i = 0; i < accumulator_weights.size(); i++) {
|
||||
file.read(reinterpret_cast<char*>(&accumulator_weights[i]), sizeof(int16_t));
|
||||
}
|
||||
|
||||
// HL biases
|
||||
for (int i = 0; i < accumulator_biases.size(); i++) {
|
||||
file.read(reinterpret_cast<char*>(&accumulator_biases[i]), sizeof(int16_t));
|
||||
}
|
||||
|
||||
// Output weights
|
||||
for (int i = 0; i < output_weights.size(); i++) {
|
||||
file.read(reinterpret_cast<char*>(&output_weights[i]), sizeof(int16_t));
|
||||
}
|
||||
|
||||
// Output bias
|
||||
file.read(reinterpret_cast<char*>(&output_bias), sizeof(int16_t));
|
||||
}
|
||||
|
||||
void Network::Print() {
|
||||
std::cout << "First 16 HL biases: ";
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
std::cout << accumulator_biases[i] << ' ';
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "Output neuron bias: " << output_bias << std::endl;
|
||||
}
|
||||
|
||||
static int32_t Forward(const Board& board,
|
||||
const Network* net) {
|
||||
const ACC::Accumulator& stmAcc = board.sideToMove == White ? board.accPair.white : board.accPair.black;
|
||||
|
||||
+7
-3
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <array>
|
||||
|
||||
namespace NNUE {
|
||||
|
||||
@@ -12,12 +13,15 @@ constexpr int QA = 255;
|
||||
constexpr int QB = 64;
|
||||
|
||||
struct Network {
|
||||
int16_t accumulator_weights[INPUT_SIZE][HL_SIZE];
|
||||
int16_t accumulator_biases[HL_SIZE];
|
||||
int16_t output_weights[2 * HL_SIZE];
|
||||
std::array<int16_t, HL_SIZE * INPUT_SIZE> accumulator_weights;
|
||||
std::array<int16_t, HL_SIZE> accumulator_biases;
|
||||
std::array<int16_t, 2 * HL_SIZE> output_weights;
|
||||
int16_t output_bias;
|
||||
|
||||
void Load(const std::string& path);
|
||||
void Print();
|
||||
};
|
||||
|
||||
inline Network net;
|
||||
|
||||
}
|
||||
@@ -193,5 +193,9 @@ void UCILoop(Board &board) {
|
||||
board.ListMoves();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (input.find("nnue") != std::string::npos) {
|
||||
NNUE::net.Print();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user