push/pull -> put/get

This commit is contained in:
Robert Nishihara
2016-06-23 12:58:48 -07:00
parent fe918a9f8b
commit 188569be37
22 changed files with 203 additions and 203 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ if __name__ == "__main__":
x = imagenet.load_tarfiles_from_s3(args.s3_bucket, map(str, images), [256, 256]) # TODO(pcm): implement unicode serialization
mean_image = functions.compute_mean_image(x)
mean_image = ray.pull(mean_image)
mean_image = ray.get(mean_image)
print "The mean image is:"
print mean_image
+3 -3
View File
@@ -6,13 +6,13 @@ import ray.arrays.remote as ra
@ray.remote([List[ray.ObjRef]], [int])
def num_images(batches):
shape_refs = [ra.shape(batch) for batch in batches]
return sum([ray.pull(shape_ref)[0] for shape_ref in shape_refs])
return sum([ray.get(shape_ref)[0] for shape_ref in shape_refs])
@ray.remote([List[ray.ObjRef]], [np.ndarray])
def compute_mean_image(batches):
if len(batches) == 0:
raise Exception("No images were passed into `compute_mean_image`.")
sum_image_refs = [ra.sum(batch, axis=0) for batch in batches]
sum_images = [ray.pull(ref) for ref in sum_image_refs]
sum_images = [ray.get(ref) for ref in sum_image_refs]
n_images = num_images(batches)
return np.sum(sum_images, axis=0).astype("float64") / ray.pull(n_images)
return np.sum(sum_images, axis=0).astype("float64") / ray.get(n_images)
+6 -6
View File
@@ -22,8 +22,8 @@ if __name__ == "__main__":
worker_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "worker.py")
services.start_singlenode_cluster(return_drivers=False, num_workers_per_objstore=16, worker_path=worker_path)
x_batches = [ray.push(batches[i][0]) for i in range(num_batches)]
y_batches = [ray.push(batches[i][1]) for i in range(num_batches)]
x_batches = [ray.put(batches[i][0]) for i in range(num_batches)]
y_batches = [ray.put(batches[i][1]) for i in range(num_batches)]
# From the perspective of scipy.optimize.fmin_l_bfgs_b, full_loss is simply a
# function which takes some parameters theta, and computes a loss. Similarly,
@@ -35,14 +35,14 @@ if __name__ == "__main__":
# from scipy.optimize.fmin_l_bfgs_b, which simply uses it to run the L-BFGS
# algorithm.
def full_loss(theta):
theta_ref = ray.push(theta)
theta_ref = ray.put(theta)
val_ref = ra.sum_list(*[functions.loss(theta_ref, x_batches[i], y_batches[i]) for i in range(num_batches)])
return ray.pull(val_ref)
return ray.get(val_ref)
def full_grad(theta):
theta_ref = ray.push(theta)
theta_ref = ray.put(theta)
grad_ref = ra.sum_list(*[functions.grad(theta_ref, x_batches[i], y_batches[i]) for i in range(num_batches)])
return ray.pull(grad_ref).astype("float64") # This conversion is necessary for use with fmin_l_bfgs_b.
return ray.get(grad_ref).astype("float64") # This conversion is necessary for use with fmin_l_bfgs_b.
theta_init = np.zeros(functions.dim)
+2 -2
View File
@@ -34,12 +34,12 @@ grad_buffer = {k: np.zeros_like(v) for k, v in model.iteritems()} # update buffe
rmsprop_cache = {k: np.zeros_like(v) for k, v in model.iteritems()} # rmsprop memory
while True:
modelref = ray.push(model)
modelref = ray.put(model)
grads = []
for i in range(batch_size):
grads.append(functions.compgrad(modelref))
for i in range(batch_size):
grad = ray.pull(grads[i])
grad = ray.get(grads[i])
for k in model: grad_buffer[k] += grad[0][k] # accumulate grad over batch
running_reward = grad[1] if running_reward is None else running_reward * 0.99 + grad[1] * 0.01
print "Batch {}. episode reward total was {}. running mean: {}".format(batch_num, grad[1], running_reward)