Created
February 1, 2020 14:22
-
-
Save hartikainen/c1f477e395a42cd0c354d193c6e7b9f0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import random | |
import time | |
import tensorflow as tf | |
from ray import tune | |
class ExperimentRunner(tune.Trainable): | |
def _setup(self, variant): | |
self.timestep = 0 | |
def _train(self): | |
self.timestep += 1 | |
v = tf.tanh(float(self.timestep) / self.config.get("width", 1)).numpy() | |
v *= self.config.get("height", 1) | |
time.sleep(tf.random.uniform((), minval=0.1, maxval=2.0)) | |
if self.config['width'] == 10 and 2 < self.timestep: | |
raise ValueError("Intentional exception to see if tune fails.") | |
return {"episode_reward_mean": v} | |
def main(): | |
tune.run( | |
ExperimentRunner, | |
resources_per_trial={'cpu': 2}, | |
num_samples=1, | |
stop={"training_iteration": 10}, | |
config={ | |
"width": tune.grid_search([10, 20, 30]), | |
"height": tune.sample_from(lambda spec: int(100 * random.random())), | |
}, | |
local_dir='/tmp/wandb-test', | |
) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment