ray icon indicating copy to clipboard operation
ray copied to clipboard

[RLlib] 'MeanStdFilter' connector is broken.

Open duburcqa opened this issue 1 year ago • 1 comments

What happened + What you expected to happen

'merge_states' is used to aggregate the statistics collected over all the parallel environments, then broadcast the result back to all remote workers.

This design is problematic for 'MeanStdFilter', because it means that, after the first iteration, all the local workers store not only the statistic collected at the current iteration, but also all one that were aggregated at previous iteration. Only the statistics collected at the current iteration should be considered when merging, which is not the case at the moment.

This issue is blocking and not just nice-to-have because it causes the number of "pushes" to grow exponentially, causing int64 overflow after a few iterations (more precisely, 304 iterations with 80000 samples each). Then 'nan' appears everywhere after this point, which is not surprising.

Versions / Dependencies

I checked that the issue is present for "ray[rllib]>=2.38,<=2.40".

Reproduction script

Any script specifying algo_config.env_runners(env_to_module_connector=lambda env: MeanStdFilter()) would face this issue.

Issue Severity

High: It blocks me from completing my task.

duburcqa avatar Jan 08 '25 13:01 duburcqa

Hi @pseudo-rnd-thoughts, I'd like to pick this up. Plan: in python/ray/rllib/connectors/env_to_module/mean_std_filter.py, have merge_states merge only each EnvRunner's per-iteration buffer delta rather than its cumulative running_stats, which already contain the previously broadcast global stats and get counted again on every sync. After the sync, the buffers would be cleared, and running_stats stays in get_state so checkpoints don't change. I'll add a unit test with two filter instances that syncs three times and asserts the merged count equals the true number of observations and the mean and std match numpy. Is adding a separate buffer entry to the state dict acceptable, or would you rather keep the state format and pass deltas another way? Could you assign it to me?

rahulsjha avatar Nov 17 '26 17:11 rahulsjha