-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The new proposed feature is to have trainers as generators. The usage pattern is: ```python trainer = OnPolicyTrainer(...) for epoch, epoch_stat, info in trainer: print(f"Epoch: {epoch}") print(epoch_stat) print(info) do_something_with_policy() query_something_about_policy() make_a_plot_with(epoch_stat) display(info) ``` - epoch int: the epoch number - epoch_stat dict: a large collection of metrics of the current epoch, including stat - info dict: the usual dict out of the non-generator version of the trainer You can even iterate on several different trainers at the same time: ```python trainer1 = OnPolicyTrainer(...) trainer2 = OnPolicyTrainer(...) for result1, result2, ... in zip(trainer1, trainer2, ...): compare_results(result1, result2, ...) ``` Co-authored-by: Jiayi Weng <[email protected]>
- Loading branch information
1 parent
2336a7d
commit 10d9190
Showing
14 changed files
with
864 additions
and
488 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,49 @@ | ||
tianshou.trainer | ||
================ | ||
|
||
.. automodule:: tianshou.trainer | ||
|
||
On-policy | ||
--------- | ||
|
||
.. autoclass:: tianshou.trainer.OnpolicyTrainer | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
.. autofunction:: tianshou.trainer.onpolicy_trainer | ||
|
||
.. autoclass:: tianshou.trainer.onpolicy_trainer_iter | ||
|
||
|
||
Off-policy | ||
---------- | ||
|
||
.. autoclass:: tianshou.trainer.OffpolicyTrainer | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
.. autofunction:: tianshou.trainer.offpolicy_trainer | ||
|
||
.. autoclass:: tianshou.trainer.offpolicy_trainer_iter | ||
|
||
|
||
Offline | ||
------- | ||
|
||
.. autoclass:: tianshou.trainer.OfflineTrainer | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
.. autofunction:: tianshou.trainer.offline_trainer | ||
|
||
.. autoclass:: tianshou.trainer.offline_trainer_iter | ||
|
||
|
||
utils | ||
----- | ||
|
||
.. autofunction:: tianshou.trainer.test_episode | ||
|
||
.. autofunction:: tianshou.trainer.gather_info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,34 @@ | ||
"""Trainer package.""" | ||
|
||
# isort:skip_file | ||
|
||
from tianshou.trainer.utils import test_episode, gather_info | ||
from tianshou.trainer.onpolicy import onpolicy_trainer | ||
from tianshou.trainer.offpolicy import offpolicy_trainer | ||
from tianshou.trainer.offline import offline_trainer | ||
from tianshou.trainer.base import BaseTrainer | ||
from tianshou.trainer.offline import ( | ||
OfflineTrainer, | ||
offline_trainer, | ||
offline_trainer_iter, | ||
) | ||
from tianshou.trainer.offpolicy import ( | ||
OffpolicyTrainer, | ||
offpolicy_trainer, | ||
offpolicy_trainer_iter, | ||
) | ||
from tianshou.trainer.onpolicy import ( | ||
OnpolicyTrainer, | ||
onpolicy_trainer, | ||
onpolicy_trainer_iter, | ||
) | ||
from tianshou.trainer.utils import gather_info, test_episode | ||
|
||
__all__ = [ | ||
"BaseTrainer", | ||
"offpolicy_trainer", | ||
"offpolicy_trainer_iter", | ||
"OffpolicyTrainer", | ||
"onpolicy_trainer", | ||
"onpolicy_trainer_iter", | ||
"OnpolicyTrainer", | ||
"offline_trainer", | ||
"offline_trainer_iter", | ||
"OfflineTrainer", | ||
"test_episode", | ||
"gather_info", | ||
] |
Oops, something went wrong.