Repository navigation
Fix backward probabilities and gradients for resumed trajectories - #535
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #535 +/- ##
==========================================
- Coverage 75.62% 75.62% -0.01%
==========================================
Files 62 62
Lines 11329 11327 -2
Branches 1670 1669 -1
==========================================
- Hits 8568 8566 -2
Misses 2234 2234
Partials 527 527
🚀 New features to boost your workflow:
|
|
on it |
…formula - get_trajectory_pbs: restore the per-step PB mask formula in the docstring. - test_trajectory_pb_vectorized_vs_nonvectorized_parity: also cover trajectories resumed from interior states, and check that the vectorized and per-step paths give the same gradients. - test_resumed_trajectory_pb_probabilities_and_gradients: also check the weight gradient analytically, and that per-step and vectorized gradients match. - test_local_search_metropolis_hastings_acceptance_ratio: check that LocalSearchSampler's Metropolis-Hastings step accepts with the correct ratio, for vectorized and per-step PB, on HyperGrid and DiscreteEBM. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the fix! I pushed one commit on top (5a58b4d) w tests and a docstring touch-up. Docstring: restored the per-step PB mask formula in get_trajectory_pbs. |
|
Rechecked your head 5a58b4d locally: the resumed-trajectory gradient-parity, analytic-gradient and local-search MH cases all pass (7 passed), so I'm not changing the branch. The failed Claude review run dies before reviewing anything ("Unable to get ACTIONS_ID_TOKEN_REQUEST_URL env variable", then the missing id-token: write error). I left workflow permissions alone so this fix stays code-only. This check was AI-assisted. |
Problem
Sampler.sample_trajectories(..., states=...)can start at interior states. The stepwiseget_trajectory_pbspath nevertheless masked the entire first transition, assuming every trajectory began at the unique root. This silently changes resumed trajectory-balance objectives and removes the first backward-policy gradient.On an actual two-dimensional HyperGrid rollout with an interior start and uniform backward logits, the vectorized path gives first-step
log P_B = -0.69314718and bias gradient[-0.5, 0.5]; the previous stepwise path gave zero for both. A root-start control correctly has log probability zero.Change
Remove the timestep-zero override. Use the existing successor-state/action masks at every step, preserving root, sink, exit and padding handling. Document interior-start support in the existing docstring.
The regression combines an interior start, a root start, immediate exit and padding. It checks probabilities against the analytic categorical distribution and checks the backward-policy gradient against
[-0.25, 0.25], not merely a second implementation.Verification
python -m pytest testing/test_probability_calculations.py -q: 10 passed.pre-commit run --all-files: autoflake, isort, black, flake8 and pyright passed. The full pytest hook is not green: 2,062 passed, 709 skipped, 2 failed, 35 errors. Every listed failure/error is in chip-design integration and reachessocket.AF_UNIX, unavailable on this Windows Python runtime. No skips, platform shims or unrelated test changes were added to hide this.SubTBGFlowNet: vectorized and stepwise losses/gradients agree; losses8.55848026 -> 8.07797337 -> 7.63690805, maximum observed parameter-gradient difference7.153e-7.No GPU or research-quality/benchmark improvement claim. This corrects probability accounting, not the underlying model design.
Fixes #534.
Review and assistance
I supervised and checked the AI-assisted work as it progressed. AI assistance was used for investigation, implementation and verification. No maintainer review or approval is claimed. Verification was CPU-only; no GPU validation is claimed.