Allow remote decorator to be used with no parentheses.

This commit is contained in:
Robert Nishihara
2016-08-30 16:38:26 -07:00
parent ce4e5ec544
commit fb7ccef493
22 changed files with 193 additions and 175 deletions
+1 -1
View File
@@ -85,7 +85,7 @@ The other parallel component of this application is the training procedure. This
is built on top of the remote function `compute_grad`.
```python
@ray.remote()
@ray.remote
def compute_grad(X, Y, mean, weights):
# Load the weights into the network.
# Subtract the mean and crop the images.
+5 -5
View File
@@ -230,7 +230,7 @@ def net_initialization():
def net_reinitialization(net_vars):
return net_vars
@ray.remote()
@ray.remote
def num_images(batches):
"""Counts number of images in batches.
@@ -243,7 +243,7 @@ def num_images(batches):
shape_ids = [ra.shape.remote(batch) for batch in batches]
return sum([ray.get(shape_id)[0] for shape_id in shape_ids])
@ray.remote()
@ray.remote
def compute_mean_image(batches):
"""Computes the mean image given a list of batches of images.
@@ -305,7 +305,7 @@ def shuffle_pair(first_batch, second_batch):
images1, labels1, images2, labels2 = shuffle_arrays.remote(first_batch[0], first_batch[1], second_batch[0], second_batch[1])
return (images1, labels1), (images2, labels2)
@ray.remote()
@ray.remote
def filenames_to_labels(filenames, filename_label_dict):
"""Converts filename strings to integer labels.
@@ -380,7 +380,7 @@ def shuffle(batches):
new_batches.append(permuted_batches[-1])
return new_batches
@ray.remote()
@ray.remote
def compute_grad(X, Y, mean, weights):
"""Computes the gradient of the network.
@@ -405,7 +405,7 @@ def compute_grad(X, Y, mean, weights):
# Compute the gradients.
return sess.run([g for (g, v) in comp_grads], feed_dict={images: subset_X, y_true: subset_Y, dropout: 0.5})
@ray.remote()
@ray.remote
def compute_accuracy(X, Y, weights):
"""Returns the accuracy of the network
+1 -1
View File
@@ -82,7 +82,7 @@ complicated version of this remote function is defined in
[hyperopt.py](hyperopt.py).
```python
@ray.remote()
@ray.remote
def train_cnn_and_compute_accuracy(hyperparameters, train_images, train_labels, validation_images, validation_labels):
# Actual work omitted.
return validation_accuracy
+1 -1
View File
@@ -51,7 +51,7 @@ def cnn_setup(x, y, keep_prob, lr, stddev):
# Define a remote function that takes a set of hyperparameters as well as the
# data, consructs and trains a network, and returns the validation accuracy.
@ray.remote()
@ray.remote
def train_cnn_and_compute_accuracy(params, steps, train_images, train_labels, validation_images, validation_labels):
# Extract the hyperparameters from the params dictionary.
learning_rate = params["learning_rate"]
+2 -2
View File
@@ -91,12 +91,12 @@ use remote functions to distribute the loading of the data.
Now, lets turn `loss` and `grad` into remote functions.
```python
@ray.remote()
@ray.remote
def loss(theta, xs, ys):
# compute the loss
return loss
@ray.remote()
@ray.remote
def grad(theta, xs, ys):
# compute the gradient
return grad
+2 -2
View File
@@ -74,14 +74,14 @@ if __name__ == "__main__":
sess.run([update_w, update_b], feed_dict={w_new: theta[:w_size].reshape(w_shape), b_new: theta[w_size:]})
# Compute the loss on a batch of data.
@ray.remote()
@ray.remote
def loss(theta, xs, ys):
sess, _, _, cross_entropy, _, x, y_, _, _ = ray.reusables.net_vars
load_weights(theta)
return float(sess.run(cross_entropy, feed_dict={x: xs, y_: ys}))
# Compute the gradient of the loss on a batch of data.
@ray.remote()
@ray.remote
def grad(theta, xs, ys):
sess, _, _, _, cross_entropy_grads, x, y_, _, _ = ray.reusables.net_vars
load_weights(theta)
+1 -1
View File
@@ -79,7 +79,7 @@ we use reusable variables to store the gym environment and the neural network po
then used in the remote `do_rollout` function to do a remote rollout:
```python
@ray.remote()
@ray.remote
def do_rollout(policy, timestep_limit, seed):
# Retrieve the game environment.
env = ray.reusables.env