42 std::shared_ptr<const EvalContextMoECacheSharedModel> sharedModel);
47 static std::shared_ptr<const EvalContextMoECacheSharedModel>
73 std::shared_ptr<const EvalContextMoECacheSharedModel> shared);
76 std::shared_ptr<const EvalContextMoECacheSharedModel>
sharedModel_{};
77 std::array<MoEDoubleAccumulator, 2>
models_{};
95 static uint32_t
read_u32(std::ifstream &in);
97 template <
typename FloatContainer>
98 static void read_floats(std::ifstream &in, FloatContainer &dst,
size_t n) {
99 if constexpr (
requires(FloatContainer &c,
size_t m) { c.resize(m); }) {
103 throw std::runtime_error(
"Fixed-size tensor shape mismatch while reading");
105 in.read(
reinterpret_cast<char *
>(dst.data()),
106 static_cast<std::streamsize
>(n *
sizeof(
float)));
108 throw std::runtime_error(
"Failed reading float block");
114 template <
typename SrcContainer,
typename DstContainer>
116 int rows,
int cols) {
117 const size_t n =
static_cast<size_t>(rows) * cols;
118 if constexpr (
requires(DstContainer &c,
size_t m) { c.resize(m); }) {
122 throw std::runtime_error(
"Fixed-size tensor shape mismatch while transposing");
124 for (
int r = 0; r < rows; ++r) {
125 for (
int c = 0; c < cols; ++c) {
126 dst[(size_t)c * rows + r] = src[(
size_t)r * cols + c];
Abstract interface for board evaluation algorithms.
Factorized Mixture of Experts (MoE) neural network architecture and inference components.
ExpertPoolMode
Defines how spatial features are pooled before entering the fully-connected expert networks.
Definition MoECacheModel.hpp:826
chess::Board Board
Alias for chess::Board.
Definition Types.h:14
Converts neural network WDL outputs to centipawns.
void setEvalNormalization(bool enable) override
Enables or disables dynamic evaluation normalization.
Definition EvalContextMoECache.h:58
float evaluate(const Board &board, int ply=0) override
Evaluates the board from the perspective of the side to move.
Definition EvalContextMoECache.cpp:283
bool enableEvalNormalization_
Definition EvalContextMoECache.h:90
WDLConverter::WDL evaluateWDL(const Board &board, int ply=0) override
Evaluates the board and returns Win/Draw/Loss probabilities.
Definition EvalContextMoECache.cpp:215
static uint32_t read_u32(std::ifstream &in)
Definition EvalContextMoECache.cpp:19
std::array< MoEDoubleAccumulator, 2 > models_
Definition EvalContextMoECache.h:77
uint64_t getFullRebuilds() const override
Retrieves the number of full feature rebuilds performed (for profiling).
Definition EvalContextMoECache.h:64
static void transpose_copy(const SrcContainer &src, DstContainer &dst, int rows, int cols)
Definition EvalContextMoECache.h:115
int rebuildEveryNEvals_
Definition EvalContextMoECache.h:91
void init_from_shared_model(std::shared_ptr< const EvalContextMoECacheSharedModel > shared)
Definition EvalContextMoECache.cpp:187
static ExpertPoolMode pool_mode_from_code(int code)
Definition EvalContextMoECache.cpp:35
static void load_weights_into_target(const std::string &weightsPath, BenchConfig &cfg, SharedMoEWeights &weights)
Definition EvalContextMoECache.cpp:50
BenchConfig cfg_
Definition EvalContextMoECache.h:75
static std::shared_ptr< const EvalContextMoECacheSharedModel > loadSharedModel(const std::string &weightsPath)
Loads the shared model weights from disk.
Definition EvalContextMoECache.cpp:181
std::atomic< uint64_t > totalRebuilds_
Definition EvalContextMoECache.h:93
static void read_floats(std::ifstream &in, FloatContainer &dst, size_t n)
Definition EvalContextMoECache.h:98
std::array< FactorizedInput, 2 > prevInputByStm_
Definition EvalContextMoECache.h:83
static constexpr uint32_t kVersion
Definition EvalContextMoECache.h:70
EvalContextMoECache(const std::string &weightsPath)
Definition EvalContextMoECache.cpp:202
static constexpr uint32_t kMagicWeights
Definition EvalContextMoECache.h:69
std::array< bool, 2 > hasPrevByStm_
Definition EvalContextMoECache.h:84
std::shared_ptr< const EvalContextMoECacheSharedModel > sharedModel_
Definition EvalContextMoECache.h:76
static void read_floats_raw(std::ifstream &in, float *dst, size_t n)
Definition EvalContextMoECache.cpp:27
WDLConverter wdlConverter_
Definition EvalContextMoECache.h:86
void load_weights_into_model(const std::string &weightsPath)
Definition EvalContextMoECache.cpp:176
FactorizedInput scratchInput_
Definition EvalContextMoECache.h:81
int evalScaleWeight_
Definition EvalContextMoECache.h:89
void setAggression(float aggression) override
Sets the contempt or aggression factor for the evaluator.
Definition EvalContextMoECache.h:53
void setIncrementalRebuildInterval(int interval) override
Sets the interval for forcing full feature rebuilds (to correct accumulation errors).
Definition EvalContextMoECache.h:61
int evalScaleBase_
Definition EvalContextMoECache.h:88
std::array< uint32_t, 2 > evalsSinceFullByStm_
Definition EvalContextMoECache.h:92
void setEvalScale(int base, int weight) override
Sets the scaling parameters for the evaluation score.
Definition EvalContextMoECache.h:54
Abstract interface for evaluators.
Definition IEvaluator.h:25
Handles conversion between Win-Draw-Loss probabilities and centipawn scores.
Definition WDLConverter.hpp:34
Definition MoECacheModel.hpp:860
Contains the shared neural network weights.
Definition EvalContextMoECache.h:27
BenchConfig cfg
Configuration of the MoE architecture.
Definition EvalContextMoECache.h:28
SharedMoEWeights weights
Thread-safe shared weights container.
Definition EvalContextMoECache.h:29
Contains the globally shared, read-only weights for the Factorized MoE network.
Definition MoECacheModel.hpp:986
Holds Win, Draw, and Loss probabilities.
Definition WDLConverter.hpp:40