Skip to content

Commit e8185be

Browse files
committed
Try option to use parent average for fpu instead of parent nn value
1 parent e7f4bfe commit e8185be

4 files changed

Lines changed: 21 additions & 6 deletions

File tree

cpp/program/setup.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ void Setup::initializeSession(ConfigParser& cfg) {
1111
if(cfg.contains("tensorflowPerProcessGpuMemoryFraction"))
1212
tensorflowPerProcessGpuMemoryFraction = cfg.getDouble("tensorflowPerProcessGpuMemoryFraction",0.0,1.0);
1313

14-
NeuralNet::globalInitialize(tensorflowGpuVisibleDeviceList,tensorflowPerProcessGpuMemoryFraction);
14+
NeuralNet::globalInitialize(tensorflowGpuVisibleDeviceList,tensorflowPerProcessGpuMemoryFraction);
1515
}
1616

1717
vector<NNEvaluator*> Setup::initializeNNEvaluators(
@@ -58,7 +58,7 @@ vector<NNEvaluator*> Setup::initializeNNEvaluators(
5858
else
5959
cudaGpuIdxByServerThread.push_back(0);
6060
}
61-
61+
6262
int defaultSymmetry = 0;
6363
nnEval->spawnServerThreads(
6464
numNNServerThreadsPerModel,
@@ -113,9 +113,11 @@ vector<SearchParams> Setup::loadParams(
113113
else params.cpuctExploration = cfg.getDouble("cpuctExploration", 0.0, 10.0);
114114
if(cfg.contains("fpuReductionMax"+idxStr)) params.fpuReductionMax = cfg.getDouble("fpuReductionMax"+idxStr, 0.0, 2.0);
115115
else params.fpuReductionMax = cfg.getDouble("fpuReductionMax", 0.0, 2.0);
116+
if(cfg.contains("fpuUseParentAverage"+idxStr)) params.fpuUseParentAverage = cfg.getBool("fpuUseParentAverage"+idxStr);
117+
else if(cfg.contains("fpuUseParentAverage")) params.fpuUseParentAverage = cfg.getBool("fpuUseParentAverage");
118+
116119
if(cfg.contains("rootNoiseEnabled"+idxStr)) params.rootNoiseEnabled = cfg.getBool("rootNoiseEnabled"+idxStr);
117120
else params.rootNoiseEnabled = cfg.getBool("rootNoiseEnabled");
118-
119121
if(cfg.contains("rootDirichletNoiseTotalConcentration"+idxStr))
120122
params.rootDirichletNoiseTotalConcentration = cfg.getDouble("rootDirichletNoiseTotalConcentration"+idxStr, 0.001, 10000.0);
121123
else

cpp/search/search.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ Loc Search::getChosenMoveLoc() {
271271
temperature +=
272272
(searchParams.chosenMoveTemperatureEarly - searchParams.chosenMoveTemperature) *
273273
pow(0.5,rootHistory.moveHistory.size() / searchParams.chosenMoveTemperatureHalflife);
274-
274+
275275
//Temperature so close to 0 that we just calculate the max directly
276276
if(temperature <= 1.0e-4) {
277277
double bestSelectionValue = POLICY_ILLEGAL_SELECTION_VALUE;
@@ -479,7 +479,18 @@ void Search::selectBestChildToDescend(
479479
assert(policyProbMassVisited <= 1.0001);
480480

481481
//First play urgency
482-
double parentValue = node.nnOutput->whiteValue;
482+
double parentValue;
483+
if(searchParams.fpuUseParentAverage) {
484+
while(node.statsLock.test_and_set(std::memory_order_acquire));
485+
uint64_t parentVisits = node.stats.visits;
486+
double parentValueSum = node.stats.getCombinedValueSum(searchParams);
487+
node.statsLock.clear(std::memory_order_release);
488+
assert(parentVisits > 0);
489+
parentValue = parentValueSum / parentVisits;
490+
}
491+
else
492+
parentValue = node.nnOutput->whiteValue;
493+
483494
double fpuValue;
484495
if(isRoot && searchParams.rootNoiseEnabled)
485496
fpuValue = parentValue;
@@ -557,7 +568,7 @@ void Search::initNodeNNOutput(
557568
//Values in the search are from the perspective of white positive always
558569
double value = (double)node.nnOutput->whiteValue;
559570
retWinLossValue = value;
560-
retScoreValue = 0.0;
571+
retScoreValue = 0.0;
561572
}
562573

563574
void Search::playoutDescend(

cpp/search/searchparams.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ SearchParams::SearchParams()
77
drawUtilityForWhite(0.0),
88
cpuctExploration(1.6),
99
fpuReductionMax(0.5),
10+
fpuUseParentAverage(false),
1011
rootNoiseEnabled(false),
1112
rootDirichletNoiseTotalConcentration(10.0),
1213
rootDirichletNoiseWeight(0.25),

cpp/search/searchparams.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct SearchParams {
1313
//Search tree exploration parameters
1414
double cpuctExploration; //Constant factor on exploration, should also scale up linearly with magnitude of utility
1515
double fpuReductionMax; //Max amount to reduce fpu value for unexplore children
16+
bool fpuUseParentAverage; //Use parent average value for fpu rather than parent nn value.
1617

1718
//Root noise parameters
1819
bool rootNoiseEnabled;

0 commit comments

Comments
 (0)