Skip to content

Preserve recurrent critic state during bootstrap queries - #405

Merged
Denys88 merged 1 commit into
Denys88:masterfrom
Afloat16:fix/central-value-bootstrap-state-20261116
Nov 19, 2026
Merged

Denys88 merged 1 commit into
Denys88:masterfrom
Afloat16:fix/central-value-bootstrap-state-20261116

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Problem

At the end of each PPO rollout, A2CBase.get_values() evaluates the next observation to bootstrap GAE. With a recurrent central value network, CentralValueTrain.get_value() also stores the returned hidden state. The next rollout then evaluates the same observation again from that advanced state.

As a result, the critic consumes the horizon endpoint twice. Its subsequent values and GAE targets differ from a continuous observation stream even when there is no training or change to the model weights between rollouts. This also affects an episode ending at the horizon: the rollout has already cleared the terminated environment's critic state, but the bootstrap query fills it again before the next episode's first real query.

Changes

  • Make committing the returned central critic state optional, retaining the existing default for normal rollout queries.
  • Disable that state update only for get_values() bootstrap queries. The value is still evaluated with the current state; the rollout's existing done handling remains responsible for clearing terminated environments.
  • Add regression tests using the actual GRU/LSTM central value networks and continuous/discrete PPO rollout paths. Two successive rollouts are compared with a direct, step-by-step model reference and independently calculated GAE returns, without optimizer updates between them.

This is separate from #391's multi-agent done reordering and single-sequence reset fixes. It concerns the extra state advance caused by an endpoint value query.

Validation

  • New regression module on the unchanged base: 12 failed, 4 passed. All recurrent cases fail; the four MLP controls pass.
  • With the fix: 16 passed. Coverage includes repeated bootstrap reads, normal rollout state advancement, a termination at the horizon, a termination inside the next rollout, GRU/LSTM critics, continuous/discrete policies, and MLP controls.
  • Related regression suite: 131 passed, 4 skipped. The skipped cases require CUDA; validation here used PyTorch on CPU.
  • Both CI Flake8 commands completed successfully. The critical syntax/undefined-name check reports 0 errors; the advisory style check retains existing repository warnings.
  • git diff --check passed.

The related suite includes test_central_value_bootstrap, test_ppo_masking, test_release_correctness, test_perf_fixes, test_critical_fixes, test_mixed_precision, test_value_normalization_targets, test_ppo_dataset_sequences, and test_multidiscrete.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (master@9c0b3a0). Learn more about missing BASE report.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #405   +/-   ##
=========================================
  Coverage          ?   58.42%           
=========================================
  Files             ?       70           
  Lines             ?     8868           
  Branches          ?        0           
=========================================
  Hits              ?     5181           
  Misses            ?     3687           
  Partials          ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Denys88 Denys88 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified the asymmetry: the policy's get_values passes rnn_states without storing them, but CentralValueTrain.get_value stored them on the bootstrap query, so a recurrent central value consumed the horizon endpoint twice. Opt-out flag on the bootstrap call is the minimal fix.

@Denys88
Denys88 merged commit e895a2d into Denys88:master Nov 19, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants