Skip to content

collecting latest step as a stat #5264

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

Merged
merged 19 commits into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
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
13 changes: 11 additions & 2 deletions ml-agents/mlagents/trainers/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from torch.utils.tensorboard import SummaryWriter
from mlagents.torch_utils.globals import get_rank


logger = get_logger(__name__)


Expand Down Expand Up @@ -212,7 +211,12 @@ def add_property(


class TensorboardWriter(StatsWriter):
def __init__(self, base_dir: str, clear_past_data: bool = False):
def __init__(
self,
base_dir: str,
clear_past_data: bool = False,
hidden_keys: List[str] = None,
):
"""
A StatsWriter that writes to a Tensorboard summary.

Expand All @@ -224,12 +228,17 @@ def __init__(self, base_dir: str, clear_past_data: bool = False):
self.summary_writers: Dict[str, SummaryWriter] = {}
self.base_dir: str = base_dir
self._clear_past_data = clear_past_data
if hidden_keys is None:
hidden_keys = ["Is Training", "Step"]
self.hidden_keys: List[str] = hidden_keys

def write_stats(
self, category: str, values: Dict[str, StatsSummary], step: int
) -> None:
self._maybe_create_summary_writer(category)
for key, value in values.items():
if key in self.hidden_keys:
continue
self.summary_writers[category].add_scalar(
f"{key}", value.aggregated_value, step
)
Expand Down
1 change: 1 addition & 0 deletions ml-agents/mlagents/trainers/trainer/rl_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ def _increment_step(self, n_steps: int, name_behavior_id: str) -> None:
p = self.get_policy(name_behavior_id)
if p:
p.increment_step(n_steps)
self.stats_reporter.set_stat("Step", float(self.get_step))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ervteng Is there a place that I can collect more granular/frequent step updates?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is the right place if we care about synchronizing with the other metrics.

The other place would be in the AgentProcessor, but that is a bit decoupled from the other metrics as it would be added pre-trajectory assembly.

Copy link
Contributor

Choose a reason for hiding this comment

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

At some point (e.g. if the inference and training are separate processes) it might be useful to emit both as different stats (e.g. steps_executed and steps_processed)


def _get_next_interval_step(self, interval: int) -> int:
"""
Expand Down