def main_sync(): iterations = 200 num_workers = 2 actors.start() ps = ParameterServer.remote(1e-2) workers = [DataWorker.remote() for i in range(num_workers)] model = ConvNet() test_loader = get_data_loader()[1] print("Running synchronous parameter server training.") current_weights = ps.get_weights.remote() for i in range(iterations): gradients = [ worker.compute_gradients.remote(current_weights) for worker in workers ] # Calculate update after all gradients are available. current_weights = ps.apply_gradients.remote(*gradients) if i % 10 == 0: # Evaluate the current model. model.set_weights(actors.get(current_weights)) accuracy = evaluate(model, test_loader) print("Iter {}: \taccuracy is {:.1f}".format(i, accuracy)) print("Final accuracy is {:.1f}.".format(accuracy)) # Clean up Ray resources and processes before the next example. actors.shutdown()
def main_sync(): iterations = 200 num_workers = 2 actors.start() trainer = TrainSupervisor.remote() ps = ParameterServer.remote(1e-2, trainer) workers = [DataWorker.remote(trainer) for _ in range(num_workers)] trainer.set_up.remote(ps, workers, iterations) import time time.sleep(120) # Clean up resources and processes. actors.shutdown()
def main(): actors.start() # counter_actor = actors.role(Counter).remote() counter_actor = Counter.remote() [counter_actor.increment.remote() for _ in range(10)] # counter_actor.pls_stop() count = counter_actor.get_counter.future.remote() # Returns do not work yet print(f"Count: {count}") # This will be count.get(), since it's a future counter_actor.set_self.remote(counter_actor) counter_actor.check_proxy.remote() time.sleep(5) actors.shutdown()
def pong_ready(self): self.pong_ok = True self.run() def run(self): if self.ping_ok and self.pong_ok: self.init = time.time() self.pinger.pong.remote() print("First sent") def finish(self): self.end = time.time() total = (self.end - self.init) print(f"Did {self.pings} pings in {total} s") print(f"{self.pings / total} pings per second") def print(self): print(f"Printing Judge {self.key}") if __name__ == '__main__': actors.start() judge = Judge.remote() pinger = Pinger.remote() ponger = Ponger.remote() judge.set_up.remote(100, pinger, ponger) time.sleep(10) actors.shutdown()