Skip to content

Commit

Permalink
Switch to 16-bit accumulators and reorder network (#21)
Browse files Browse the repository at this point in the history
This uses smaller accumulators for the network, rendering a noticeable speedup. Furthermore, the weights of the network have been reordered to align with the accumulator's order.

STC:
LLR:  2.97/2.94<0.00, 10.00> Elo diff: 9.91 [3.04, 16.79] (95%)         
Games: 2350 W: 331 L: 264 D: 1755 Draw ratio: 74.7% 
Pntl: [10, 200, 697, 249, 19]

No functional change
  • Loading branch information
ruicoelhopedro committed Dec 12, 2023
1 parent a5e781a commit d43df9f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Binary file renamed nnue-10427ad1e4e6.dat → nnue-e04a4f84c87d.dat
Binary file not shown.
4 changes: 2 additions & 2 deletions src/NNUE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ namespace NNUE
for (std::size_t i = 0; i < NUM_ACCUMULATORS; i++)
{
// Clipped ReLU on the accumulators
int stm_acc = std::clamp(stm.m_net[i], 0, SCALE_FACTOR);
int ntm_acc = std::clamp(ntm.m_net[i], 0, SCALE_FACTOR);
int stm_acc = std::clamp(stm.m_net[i], int16_t(0), SCALE_FACTOR);
int ntm_acc = std::clamp(ntm.m_net[i], int16_t(0), SCALE_FACTOR);

// Net output
int j = i + NUM_ACCUMULATORS;
Expand Down
12 changes: 6 additions & 6 deletions src/NNUE.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@
#include "Types.hpp"


#define NNUE_Default_File "nnue-10427ad1e4e6.dat"
#define NNUE_Default_File "nnue-e04a4f84c87d.dat"


namespace NNUE
{

using Weight = int16_t;
using Feature = int;
constexpr int SCALE_FACTOR = 1024;
using Feature = uint16_t;
constexpr int16_t SCALE_FACTOR = 1024;
constexpr std::size_t NUM_FEATURES = 20480;
constexpr std::size_t NUM_ACCUMULATORS = 128;
constexpr std::size_t NUM_MAX_ACTIVE_FEATURES = 30;
constexpr std::size_t NUM_BUCKETS = 4;

struct Net
{
Weight m_psqt[NUM_FEATURES][NUM_BUCKETS];
Weight m_sparse_layer[NUM_FEATURES][NUM_ACCUMULATORS];
Weight m_psqt[NUM_FEATURES][NUM_BUCKETS];
Weight m_bias[NUM_ACCUMULATORS];
Weight m_dense[NUM_BUCKETS][2 * NUM_ACCUMULATORS];
Weight m_dense_bias[NUM_BUCKETS];
};

class Accumulator
{
int m_net[NUM_ACCUMULATORS];
int m_psqt[NUM_BUCKETS];
int16_t m_net[NUM_ACCUMULATORS];
int16_t m_psqt[NUM_BUCKETS];

public:
Accumulator();
Expand Down

0 comments on commit d43df9f

Please sign in to comment.