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] Add time between sample metric to MultiAgentEnvRunner. #49687

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions rllib/env/multi_agent_env_runner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections import defaultdict
from functools import partial
import logging
import time
from typing import Collection, DefaultDict, Dict, List, Optional, Union

import gymnasium as gym
Expand Down Expand Up @@ -40,6 +41,7 @@
NUM_EPISODES_LIFETIME,
NUM_MODULE_STEPS_SAMPLED,
NUM_MODULE_STEPS_SAMPLED_LIFETIME,
TIME_BETWEEN_SAMPLING,
WEIGHTS_SEQ_NO,
)
from ray.rllib.utils.metrics.metrics_logger import MetricsLogger
Expand Down Expand Up @@ -128,6 +130,8 @@ def __init__(self, config: AlgorithmConfig, **kwargs):

self._weights_seq_no: int = 0

self._time_after_sampling = None
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 leave a comment about what this attribute is for?

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


@override(EnvRunner)
def sample(
self,
Expand Down Expand Up @@ -164,6 +168,12 @@ def sample(
"""
assert not (num_timesteps is not None and num_episodes is not None)

if self._time_after_sampling is not None:
self.metrics.log_value(
key=TIME_BETWEEN_SAMPLING,
value=time.perf_counter() - self._time_after_sampling,
)

# If no execution details are provided, use the config to try to infer the
# desired timesteps/episodes to sample and the exploration behavior.
if explore is None:
Expand Down Expand Up @@ -204,6 +214,8 @@ def sample(
),
)

self._time_after_sampling = time.perf_counter()

return samples

def _sample_timesteps(
Expand Down