Nnue test #48
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) {
|
void Accumulator::Add(const NNUE::Network* net, int index) {
|
||||||
for (int i = 0; i < NNUE::HL_SIZE; i ++) {
|
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) {
|
void Accumulator::Sub(const NNUE::Network* net, int index) {
|
||||||
for (int i = 0; i < NNUE::HL_SIZE; i ++) {
|
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 "benchmark.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
#include "datagen.h"
|
#include "datagen.h"
|
||||||
|
#include "nnue.h"
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
MOVEGEN::initLeaperAttacks();
|
MOVEGEN::initLeaperAttacks();
|
||||||
@@ -12,6 +13,8 @@ int main(int argc, char* argv[]) {
|
|||||||
UTILS::InitZobrist();
|
UTILS::InitZobrist();
|
||||||
SEARCH::InitLMRTable();
|
SEARCH::InitLMRTable();
|
||||||
|
|
||||||
|
NNUE::net.Load("beans.bin");
|
||||||
|
|
||||||
Board board;
|
Board board;
|
||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#include <immintrin.h>
|
#include <immintrin.h>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
#include "nnue.h"
|
#include "nnue.h"
|
||||||
#include "accumulator.h"
|
#include "accumulator.h"
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
@@ -6,6 +8,43 @@
|
|||||||
|
|
||||||
namespace NNUE {
|
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,
|
static int32_t Forward(const Board& board,
|
||||||
const Network* net) {
|
const Network* net) {
|
||||||
const ACC::Accumulator& stmAcc = board.sideToMove == White ? board.accPair.white : board.accPair.black;
|
const ACC::Accumulator& stmAcc = board.sideToMove == White ? board.accPair.white : board.accPair.black;
|
||||||
|
|||||||
+7
-3
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <array>
|
||||||
|
|
||||||
namespace NNUE {
|
namespace NNUE {
|
||||||
|
|
||||||
@@ -12,12 +13,15 @@ constexpr int QA = 255;
|
|||||||
constexpr int QB = 64;
|
constexpr int QB = 64;
|
||||||
|
|
||||||
struct Network {
|
struct Network {
|
||||||
int16_t accumulator_weights[INPUT_SIZE][HL_SIZE];
|
std::array<int16_t, HL_SIZE * INPUT_SIZE> accumulator_weights;
|
||||||
int16_t accumulator_biases[HL_SIZE];
|
std::array<int16_t, HL_SIZE> accumulator_biases;
|
||||||
int16_t output_weights[2 * HL_SIZE];
|
std::array<int16_t, 2 * HL_SIZE> output_weights;
|
||||||
int16_t output_bias;
|
int16_t output_bias;
|
||||||
|
|
||||||
void Load(const std::string& path);
|
void Load(const std::string& path);
|
||||||
|
void Print();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline Network net;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -193,5 +193,9 @@ void UCILoop(Board &board) {
|
|||||||
board.ListMoves();
|
board.ListMoves();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (input.find("nnue") != std::string::npos) {
|
||||||
|
NNUE::net.Print();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user