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] move evaluation to trainer.step() such that the result is properly logged #12708

Merged
merged 2 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
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
8 changes: 0 additions & 8 deletions rllib/agents/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,14 +535,6 @@ def train(self) -> ResultDict:
if hasattr(self, "workers") and isinstance(self.workers, WorkerSet):
self._sync_filters_if_needed(self.workers)

if self.config["evaluation_interval"] == 1 or (
self._iteration > 0 and self.config["evaluation_interval"]
and self._iteration % self.config["evaluation_interval"] == 0):
evaluation_metrics = self._evaluate()
assert isinstance(evaluation_metrics, dict), \
"_evaluate() needs to return a dict."
result.update(evaluation_metrics)

return result

def _sync_filters_if_needed(self, workers: WorkerSet):
Expand Down
12 changes: 12 additions & 0 deletions rllib/agents/trainer_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ def _init(self, config: TrainerConfigDict,
@override(Trainer)
def step(self):
res = next(self.train_exec_impl)

# self._iteration gets incremented after this function returns,
# meaning that e. g. the first time this function is called,
# self._iteration will be 0. We add 1 to self._iteration in the
# if-statement below to reflect that the first training iteration
# is over.
sven1977 marked this conversation as resolved.
Show resolved Hide resolved
if (self.config["evaluation_interval"] and (self._iteration + 1) %
self.config["evaluation_interval"] == 0):
evaluation_metrics = self._evaluate()
assert isinstance(evaluation_metrics, dict), \
"_evaluate() needs to return a dict."
res.update(evaluation_metrics)
return res

@override(Trainer)
Expand Down