Skip to content

Fix EpisodeWrapper metrics accumulation with action_repeat - #676

Open
dafahaha wants to merge 1 commit into
google:mainfrom
dafahaha:fix-episode-metrics
Open

dafahaha wants to merge 1 commit into
google:mainfrom
dafahaha:fix-episode-metrics

Conversation

@dafahaha

Copy link
Copy Markdown

Summary

Fixes #610.

Previously, EpisodeWrapper.step only summed rewards across action_repeat sub-steps, but state.metrics only contained the metrics from the last sub-step. This caused sparse or per-step metrics (e.g., action-change penalties) to only reflect the last sub-step's value, while earlier sub-step metrics were silently dropped.

Changes

  • Modified the lax.scan loop in EpisodeWrapper.step to accumulate both rewards and metrics
  • Sum metrics across all action_repeat sub-steps using jax.tree.map
  • Write the summed metrics back to state.metrics before aggregating into episode_metrics

This matches the existing behavior for rewards and ensures all metrics are correctly aggregated across sub-steps.

Testing

  • The fix follows the same pattern as the existing reward summation
  • jax.tree.map correctly handles the metrics dictionary structure
  • No changes to public API or environment behavior

@google-cla

google-cla Bot commented Sep 16, 2026

Copy link
Copy Markdown

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.

Previously, EpisodeWrapper.step only summed rewards across action_repeat
sub-steps, but state.metrics only contained the metrics from the last
sub-step. This caused sparse or per-step metrics (e.g., action-change
penalties) to only reflect the last sub-step's value.

Fix: accumulate both rewards and metrics in the lax.scan loop, sum both
across sub-steps, and write the summed metrics back to state.metrics.

This matches the existing behavior for rewards and ensures all metrics
are correctly aggregated.

Fixes google#610
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.

EpisodeWrapper only preserves the last sub‑step’s metrics when using action_repeat

1 participant