Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RLlib] Fix bugs in MultiAgentEpisode class (getters, env_t_to_agent_t system, etc..). #49191

Merged

Conversation

sven1977
Copy link
Contributor

@sven1977 sven1977 commented Dec 10, 2024

Fix bugs in MultiAgentEpisode class:

  • Fix env_t_to_agent_t system.
  • Cleanup some unneeded code.

Why are these changes needed?

Related issue number

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

Signed-off-by: sven1977 <[email protected]>
Copy link
Collaborator

@simonsays1980 simonsays1980 left a comment

Choose a reason for hiding this comment

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

LGTM. Some small nits in regard to commenting.

!= self.SKIP_ENV_TS_TAG
):
len_lookback_buffer = max(len_lookback_buffer, i)
for i in range(orig_len_lb, len(self.env_t_to_agent_t[agent_id].data) + 1):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we access here directly the raw data attribute when we have the InfiniteLookbackBuffer defined as a class with certain length methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great question and yes, this is a little hacky here. The len method returns the length but w/o(!) the lookback buffer.

@@ -2325,6 +2293,8 @@ def _get_data_by_env_steps_as_list(
hanging_val,
filter_for_skip_indices=idxes[i],
)
if what == "extra_model_outputs" and not inf_lookback_buffer:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess inf_lookback_buffer is a bool. Imo the code becomes better readable, if we change the return values of _get_inf_lookback_buffer_or_dict to a indices_to_use only and instead check here for the type.

return {
key: sub_buffer.get(
indices=index_incl_lookback - sub_buffer.lookback,
neg_index_as_lookback=True,
fill=fill,
_add_last_ts_value=hanging_val,
_add_last_ts_value=(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Tricky. How did you find it?

{"a2": 3},
{"a2": 4},

# <- BUT: actual cut here, b/c of hanging action of a2
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we clarify here why this action is hanging? And means "cut" MAE.cut?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 done.

if _add_last_ts_value is not None:
data_to_use = np.append(data_to_use.copy(), _add_last_ts_value)
if self.finalized:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I remember this location to be part of the error output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perfect! Thanks for confirming! This was a pretty common bug you would run into when your multi-agent episode is a little bit more unstructured wrt agents stepping patterns.

Signed-off-by: sven1977 <[email protected]>
@sven1977 sven1977 enabled auto-merge (squash) December 10, 2024 18:39
@github-actions github-actions bot added the go add ONLY when ready to merge, run all tests label Dec 10, 2024
@sven1977 sven1977 merged commit 37c7beb into ray-project:master Dec 10, 2024
6 of 7 checks passed
@sven1977 sven1977 deleted the fix_further_bugs_in_multi_agent_episode branch December 11, 2024 10:38
simonsays1980 pushed a commit to simonsays1980/ray that referenced this pull request Dec 12, 2024
ujjawal-khare pushed a commit to ujjawal-khare-27/ray that referenced this pull request Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go add ONLY when ready to merge, run all tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants