Skip to content
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

49 lines (39 sloc) 1.35 KB
"""Example of a custom training workflow. Run this for a demo.
This example shows:
- using Tune trainable functions to implement custom training workflows
You can visualize experiment results in ~/ray_results using TensorBoard.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import ray
from ray import tune
from ray.rllib.agents.ppo import PPOTrainer
def my_train_fn(config, reporter):
# Train for 100 iterations with high LR
agent1 = PPOTrainer(env="CartPole-v0", config=config)
for _ in range(10):
result = agent1.train()
result["phase"] = 1
phase1_time = result["timesteps_total"]
state =
# Train for 100 iterations with low LR
config["lr"] = 0.0001
agent2 = PPOTrainer(env="CartPole-v0", config=config)
for _ in range(10):
result = agent2.train()
result["phase"] = 2
result["timesteps_total"] += phase1_time # keep time moving forward
if __name__ == "__main__":
config = {
"lr": 0.01,
"num_workers": 0,
resources = PPOTrainer.default_resource_request(config).to_json(), resources_per_trial=resources, config=config)
You can’t perform that action at this time.