Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cpp/configs/gtp_human5k_example.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ humanSLChosenMoveIgnorePass = true
# Therefore, to use humanSLChosenMovePiklLambda, it is STRONGLY recommended that you also use something
# like humanSLRootExploreProbWeightless to ensure most human moves including bad moves get searched,
# and ALSO use at least hundreds and ideally thousands of maxVisits, to ensure enough visits.
#
# NEGATIVE values run the same knob in reverse, "suppressing" the human-like moves that KataGo APPROVES
# of, so that the bot deliberately plays worse rather than better. The magnitude means the same thing,
# just in the other direction: at -0.4, a move that KataGo judges to GAIN 0.4 utility over the worst
# move it searched gets suppressed by a factor of exp(1). So the whole range reads:
# a small positive number (0.01) - always play the best move that KataGo searched
# a large positive number (1e9) - play purely from the human SL model
# a large negative number (-1e9) - play purely from the human SL model, same as a large positive one
# a small negative number (-0.01) - always play the WORST move that KataGo searched
# The permitted range is -1000000000 to 1000000000. Exactly 0 is not a useful setting - it disables the
# human SL move selection entirely rather than meaning "always the best move", so use a small positive
# number like 0.01 for that.
# The WARNING above matters even more for negative values, since they need KataGo to have actually
# searched the bad moves in order to be able to pick them.
humanSLChosenMovePiklLambda = 100000000

# These parameters tell KataGo to use the human SL policy for exploration during search.
Expand Down
4 changes: 4 additions & 0 deletions cpp/configs/gtp_human9d_search_example.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ humanSLChosenMoveIgnorePass = true
# In addition to increasing this value a lot, e.g. (0.2, 0.5, 1.0, 2.0,...)
# you can also try using old/small KataGo nets (e.g. b6c96, b10c128), reducing visits (though reducing below about 30-40
# is NOT recommended), or using the humanSLModel itself as the main "-model".
# If increasing it all the way to a large value is still not weak enough, NEGATIVE values keep going
# in that direction: they downweight the moves KataGo APPROVES of instead, so that -0.08 prefers moves
# that lose about 0.08 utility and -0.01 always plays the worst move that got searched. A large negative
# value like -1e9 is the same as a large positive one, i.e. purely the human SL policy.
humanSLChosenMovePiklLambda = 0.08 # was 100000000 in gtp_human5k_example.cfg.

# Spend 80% of visits to explore humanSL moves to ensure they get evaluations to use with humanSLChosenMovePiklLambda
Expand Down
4 changes: 2 additions & 2 deletions cpp/program/setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,8 +872,8 @@ vector<SearchParams> Setup::loadParams(
else params.humanSLChosenMoveIgnorePass = false;
if(!hasHumanModel && cfg.contains("humanSLChosenMovePiklLambda"+idxStr)) throwHumanParsingError("humanSLChosenMovePiklLambda"+idxStr);
else if(!hasHumanModel && cfg.contains("humanSLChosenMovePiklLambda")) throwHumanParsingError("humanSLChosenMovePiklLambda");
else if(cfg.contains("humanSLChosenMovePiklLambda"+idxStr)) params.humanSLChosenMovePiklLambda = cfg.getDouble("humanSLChosenMovePiklLambda"+idxStr, 0.0, 1000000000.0);
else if(cfg.contains("humanSLChosenMovePiklLambda")) params.humanSLChosenMovePiklLambda = cfg.getDouble("humanSLChosenMovePiklLambda", 0.0, 1000000000.0);
else if(cfg.contains("humanSLChosenMovePiklLambda"+idxStr)) params.humanSLChosenMovePiklLambda = cfg.getDouble("humanSLChosenMovePiklLambda"+idxStr, -1000000000.0, 1000000000.0);
else if(cfg.contains("humanSLChosenMovePiklLambda")) params.humanSLChosenMovePiklLambda = cfg.getDouble("humanSLChosenMovePiklLambda", -1000000000.0, 1000000000.0);
else params.humanSLChosenMovePiklLambda = 1000000000.0;

//On distributed, tolerate reading mutexPoolSize since older version configs use it.
Expand Down
2 changes: 1 addition & 1 deletion cpp/search/searchparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ struct SearchParams {
//These three are PRIOR to the normal chosenMoveTemperature.
double humanSLChosenMoveProp; //Proportion of final move selection probability using human SL policy
bool humanSLChosenMoveIgnorePass; //If true, ignore human SL pass probability and use KataGo's passing logic
double humanSLChosenMovePiklLambda; //Shift the final move selection significantly in response to utility differences this large.
double humanSLChosenMovePiklLambda; //Shift the final move selection significantly in response to utility differences this large. Negative shifts toward worse moves instead of better ones.

SearchParams();
~SearchParams();
Expand Down
30 changes: 28 additions & 2 deletions cpp/search/searchresults.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,34 @@ bool Search::getPlaySelectionValues(
}
}
// Perform shift
for(Loc loc: locs)
shiftedPolicy[loc] *= exp((selfUtilities[loc] - selfUtilityMax)/searchParams.humanSLChosenMovePiklLambda);
const double piklLambda = searchParams.humanSLChosenMovePiklLambda;
if(!std::signbit(piklLambda)) {
for(Loc loc: locs)
shiftedPolicy[loc] *= exp((selfUtilities[loc] - selfUtilityMax)/piklLambda);
}
else {
// A negative lambda runs the shift the other way, boosting the moves that KataGo likes least
// instead of the ones it likes most, so that a lambda approaching -0.0 picks the worst move and
// a lambda approaching -infinity leaves the human SL policy alone, just like +infinity does.
// Subtracting the minimum utility rather than the maximum is what keeps the exponent <= 0 so
// that exp can never overflow no matter how small the lambda gets. The subtracted utility is
// only a constant factor that cancels out when we renormalize below.
// Moves that can't be chosen anyways must not set that reference, or every other move could
// underflow to zero at once. Pass is one of them when humanSLChosenMoveIgnorePass is leaving
// passing up to KataGo, since the renormalization below overwrites pass's weight in that case.
double selfUtilityMin = selfUtilityMax;
for(Loc loc: locs) {
if(shiftedPolicy[loc] <= 0.0 || (searchParams.humanSLChosenMoveIgnorePass && loc == Board::PASS_LOC))
continue;
selfUtilityMin = std::min(selfUtilityMin, selfUtilities[loc]);
}
for(Loc loc: locs) {
double utilityDiff = selfUtilities[loc] - selfUtilityMin;
// Zero at the reference move itself, where dividing by a lambda of -0.0 would give 0/0,
// and negative for the moves skipped just above, which this caps instead of overflowing.
shiftedPolicy[loc] *= utilityDiff <= 0.0 ? 1.0 : exp(utilityDiff/piklLambda);
}
}

double shiftedPolicySum = 0.0;
for(Loc loc: locs)
Expand Down
1 change: 1 addition & 0 deletions docs/Analysis_Engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ If you want to obtain human *style* moves, but play stronger than a given human

Note: For GTP users, the parameter `humanSLChosenMovePiklLambda` does precisely this exp-based probability scaling.
An example set of parameters is given in [gtp_human9d_search_example.cfg](../cpp/configs/gtp_human9d_search_example.cfg), some of which may also be instructive to read even if you're using the analysis engine mode rather than GTP.
It also accepts negative values, which correspond to a negative divisor in the formula above: instead of attenuating the moves that lose utility, they attenuate the moves that gain it, so that a small negative value like `-0.01` always plays the worst move that was searched, and a large negative value is the same as a large positive one (purely the human policy). This is a way to play *weaker* than the human SL model rather than stronger.

#### Heavily bias the search to anticipate human-like sequences rather than KataGo sequences.

Expand Down
Loading