io-chess
UCI chess engine
Loading...
Searching...
No Matches
EvalContextMoECache Class Reference

Thread-local evaluator context utilizing the MoE network. More...

#include <EvalContextMoECache.h>

Inheritance diagram for EvalContextMoECache:
Collaboration diagram for EvalContextMoECache:

Public Member Functions

 EvalContextMoECache (const std::string &weightsPath)
 EvalContextMoECache (std::shared_ptr< const EvalContextMoECacheSharedModel > sharedModel)
float evaluate (const Board &board, int ply=0) override
 Evaluates the board from the perspective of the side to move.
WDLConverter::WDL evaluateWDL (const Board &board, int ply=0) override
 Evaluates the board and returns Win/Draw/Loss probabilities.
void setAggression (float aggression) override
 Sets the contempt or aggression factor for the evaluator.
void setEvalScale (int base, int weight) override
 Sets the scaling parameters for the evaluation score.
void setEvalNormalization (bool enable) override
 Enables or disables dynamic evaluation normalization.
void setIncrementalRebuildInterval (int interval) override
 Sets the interval for forcing full feature rebuilds (to correct accumulation errors).
uint64_t getFullRebuilds () const override
 Retrieves the number of full feature rebuilds performed (for profiling).
Public Member Functions inherited from IEvaluator
virtual ~IEvaluator ()=default
virtual float evaluate (const ChessInput &input)
 Evaluates the position using pre-computed features.

Static Public Member Functions

static std::shared_ptr< const EvalContextMoECacheSharedModelloadSharedModel (const std::string &weightsPath)
 Loads the shared model weights from disk.

Private Member Functions

void init_from_shared_model (std::shared_ptr< const EvalContextMoECacheSharedModel > shared)
void load_weights_into_model (const std::string &weightsPath)

Static Private Member Functions

static uint32_t read_u32 (std::ifstream &in)
template<typename FloatContainer>
static void read_floats (std::ifstream &in, FloatContainer &dst, size_t n)
static void read_floats_raw (std::ifstream &in, float *dst, size_t n)
static ExpertPoolMode pool_mode_from_code (int code)
template<typename SrcContainer, typename DstContainer>
static void transpose_copy (const SrcContainer &src, DstContainer &dst, int rows, int cols)
static void load_weights_into_target (const std::string &weightsPath, BenchConfig &cfg, SharedMoEWeights &weights)

Private Attributes

BenchConfig cfg_ {}
std::shared_ptr< const EvalContextMoECacheSharedModelsharedModel_ {}
std::array< MoEDoubleAccumulator, 2 > models_ {}
FactorizedInput scratchInput_ {}
std::array< FactorizedInput, 2 > prevInputByStm_ {}
std::array< bool, 2 > hasPrevByStm_ {{false, false}}
WDLConverter wdlConverter_
int evalScaleBase_ = 750
int evalScaleWeight_ = 25
bool enableEvalNormalization_ = true
int rebuildEveryNEvals_ = 0
std::array< uint32_t, 2 > evalsSinceFullByStm_ {{0, 0}}
std::atomic< uint64_t > totalRebuilds_ {0}

Static Private Attributes

static constexpr uint32_t kMagicWeights = 0x32454F4D
static constexpr uint32_t kVersion = 1

Detailed Description

Thread-local evaluator context utilizing the MoE network.

Maintains incremental accumulator state and evaluates positions rapidly.

Constructor & Destructor Documentation

◆ EvalContextMoECache() [1/2]

EvalContextMoECache::EvalContextMoECache ( const std::string & weightsPath)
explicit
Here is the call graph for this function:

◆ EvalContextMoECache() [2/2]

EvalContextMoECache::EvalContextMoECache ( std::shared_ptr< const EvalContextMoECacheSharedModel > sharedModel)
explicit
Here is the call graph for this function:

Member Function Documentation

◆ evaluate()

float EvalContextMoECache::evaluate ( const Board & board,
int ply = 0 )
overridevirtual

Evaluates the board from the perspective of the side to move.

Parameters
boardThe current chess board state.
plyThe current depth from the root of the search (used for scaling).
Returns
Evaluation score in centipawns (e.g., 150 = +1.5 pawns advantage).

Implements IEvaluator.

Here is the call graph for this function:

◆ evaluateWDL()

WDLConverter::WDL EvalContextMoECache::evaluateWDL ( const Board & board,
int ply = 0 )
overridevirtual

Evaluates the board and returns Win/Draw/Loss probabilities.

Parameters
boardThe current chess board state.
plyThe current depth from the root of the search.
Returns
WDL probability distribution.

Reimplemented from IEvaluator.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFullRebuilds()

uint64_t EvalContextMoECache::getFullRebuilds ( ) const
inlineoverridevirtual

Retrieves the number of full feature rebuilds performed (for profiling).

Returns
The number of full rebuilds.

Reimplemented from IEvaluator.

◆ init_from_shared_model()

void EvalContextMoECache::init_from_shared_model ( std::shared_ptr< const EvalContextMoECacheSharedModel > shared)
private
Here is the caller graph for this function:

◆ load_weights_into_model()

void EvalContextMoECache::load_weights_into_model ( const std::string & weightsPath)
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_weights_into_target()

void EvalContextMoECache::load_weights_into_target ( const std::string & weightsPath,
BenchConfig & cfg,
SharedMoEWeights & weights )
staticprivate
Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadSharedModel()

std::shared_ptr< const EvalContextMoECacheSharedModel > EvalContextMoECache::loadSharedModel ( const std::string & weightsPath)
static

Loads the shared model weights from disk.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pool_mode_from_code()

ExpertPoolMode EvalContextMoECache::pool_mode_from_code ( int code)
staticprivate
Here is the caller graph for this function:

◆ read_floats()

template<typename FloatContainer>
void EvalContextMoECache::read_floats ( std::ifstream & in,
FloatContainer & dst,
size_t n )
inlinestaticprivate
Here is the caller graph for this function:

◆ read_floats_raw()

void EvalContextMoECache::read_floats_raw ( std::ifstream & in,
float * dst,
size_t n )
staticprivate

◆ read_u32()

uint32_t EvalContextMoECache::read_u32 ( std::ifstream & in)
staticprivate
Here is the caller graph for this function:

◆ setAggression()

void EvalContextMoECache::setAggression ( float aggression)
inlineoverridevirtual

Sets the contempt or aggression factor for the evaluator.

Parameters
aggressionThe aggression factor (positive encourages risk, negative encourages draws).

Reimplemented from IEvaluator.

◆ setEvalNormalization()

void EvalContextMoECache::setEvalNormalization ( bool enable)
inlineoverridevirtual

Enables or disables dynamic evaluation normalization.

Parameters
enableTrue to enable normalization, false to use raw scores.

Reimplemented from IEvaluator.

◆ setEvalScale()

void EvalContextMoECache::setEvalScale ( int base,
int weight )
inlineoverridevirtual

Sets the scaling parameters for the evaluation score.

Parameters
baseThe base scaling divisor.
weightThe material weight scaling factor.

Reimplemented from IEvaluator.

◆ setIncrementalRebuildInterval()

void EvalContextMoECache::setIncrementalRebuildInterval ( int interval)
inlineoverridevirtual

Sets the interval for forcing full feature rebuilds (to correct accumulation errors).

Parameters
intervalThe number of incremental updates before forcing a rebuild.

Reimplemented from IEvaluator.

◆ transpose_copy()

template<typename SrcContainer, typename DstContainer>
void EvalContextMoECache::transpose_copy ( const SrcContainer & src,
DstContainer & dst,
int rows,
int cols )
inlinestaticprivate
Here is the caller graph for this function:

Member Data Documentation

◆ cfg_

BenchConfig EvalContextMoECache::cfg_ {}
private

◆ enableEvalNormalization_

bool EvalContextMoECache::enableEvalNormalization_ = true
private

◆ evalScaleBase_

int EvalContextMoECache::evalScaleBase_ = 750
private

◆ evalScaleWeight_

int EvalContextMoECache::evalScaleWeight_ = 25
private

◆ evalsSinceFullByStm_

std::array<uint32_t, 2> EvalContextMoECache::evalsSinceFullByStm_ {{0, 0}}
private

◆ hasPrevByStm_

std::array<bool, 2> EvalContextMoECache::hasPrevByStm_ {{false, false}}
private

◆ kMagicWeights

uint32_t EvalContextMoECache::kMagicWeights = 0x32454F4D
staticconstexprprivate

◆ kVersion

uint32_t EvalContextMoECache::kVersion = 1
staticconstexprprivate

◆ models_

std::array<MoEDoubleAccumulator, 2> EvalContextMoECache::models_ {}
private

◆ prevInputByStm_

std::array<FactorizedInput, 2> EvalContextMoECache::prevInputByStm_ {}
private

◆ rebuildEveryNEvals_

int EvalContextMoECache::rebuildEveryNEvals_ = 0
private

◆ scratchInput_

FactorizedInput EvalContextMoECache::scratchInput_ {}
private

◆ sharedModel_

std::shared_ptr<const EvalContextMoECacheSharedModel> EvalContextMoECache::sharedModel_ {}
private

◆ totalRebuilds_

std::atomic<uint64_t> EvalContextMoECache::totalRebuilds_ {0}
private

◆ wdlConverter_

WDLConverter EvalContextMoECache::wdlConverter_
private

The documentation for this class was generated from the following files: