Repository navigation
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
At the depth cutoff, simulate() can return an edge whose child already exists, and expand() evaluates it again. With a stochastic recurrent_fn each evaluation is a new sample, but expand() overwrote the edge's reward and discount and the child's value with it, so Tree.qvalues() reported the last sample while the visit count kept growing. A two-armed bandit searched with max_depth=1 could therefore select the worse arm. backward() still uses the new sample, so ancestor values are unchanged. After it, the edge's reward, discount and child value become running means of all samples. Fixes google-deepmind#135
salma2vec
force-pushed
the
fix/average-depth-limited-leaf-samples
branch
from
October 22, 2026 21:18
c780a1e to
3cac043
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #135
At the depth cutoff,
simulatecan return an edge whose child already exists, andexpandevaluates it again. With a stochasticrecurrent_fn(the max_depth=1 stochastic-bandit setup recommended in #33), every evaluation is a new sample.expandoverwrote the edge'schildren_rewardsandchildren_discountsand the child'snode_valueswith it, soTree.qvalues()reported the last sample whilechildren_visitskept counting all of them. In the issue's bandit, arm 0 has sample mean 0.648 over 32 visits but reported Q = 0.25, and the search picks arm 1 (constant 0.5).Change
search.body_funnow:expand(_leaf_statistics);expandandbackwardunchanged, sobackwardstill propagates the newest sampled return and ancestor values stay averages of sampled returns;node_valuesandchildren_values) with running means of all samples (_average_revisited_leaf).First expansions and deterministic environments are unaffected. The incremental mean
m + (x - m) / nreturnsmexactly whenx == m, so the existing golden-tree tests, which usemax_depthwith deterministic rewards, reproduce unchanged.Averaging reward, discount and value separately is exact when the discount is the same across samples. With a stochastic discount,
Tree.qvalues()usesE[r] + E[γ]E[v], which approximatesE[r + γv]. Keeping an exact per-edge return sum would need a newTreefield, which seemed too large a change for this fix.Tests
test_depth_limited_search_averages_stochastic_samples: one valid action, uniform random reward and value, constant discount,max_depth=1. It checks that the edge's Q-value equals the mean sampled return implied by the root value. Onmain: 0.736 vs 0.442.test_depth_limited_search_selects_better_stochastic_arm: the issue's bandit. Q-values equal the per-arm sample means and arm 0 is selected. Onmain, arm 0's Q is its last sample (1.0) instead of its mean (0.672).pytest mctx/_src/tests(run frommctx/, JAX 0.12.0, CPU): 26 passed, including the four golden trees intree_test.py. 24 pass onmainand the two new tests fail there.[0] [32. 32.] [[0.64843744 0.5]]with this change and[1] [32. 32.] [[0.25 0.5]]onmain.