def validate(self, params, server_stamp, unblock): """ Optionally run validation policy. This may include all sorts of logging etc. """ if unblock and (server_stamp) % self.validate_frequency == 0: # Make sure that we run validation with the server parameters param_copy(params, self.classifier.params) validation_losses = [ self.validate_model(i) for i in xrange(self.n_valid_batches) ] this_validation_loss = np.mean(validation_losses) logging.info('server_stamp %i, validation error %f %%' % (server_stamp, this_validation_loss * 100.)) self.validation_timestamps.append(server_stamp) self.validation_results.append(this_validation_loss)
def validate(self, params, server_stamp, unblock): """ Optionally run validation policy. This may include all sorts of logging etc. """ if unblock and (server_stamp) % self.validate_frequency == 0: # Make sure that we run validation with the server parameters param_copy(params, self.classifier.params) validation_losses = [self.validate_model(i) for i in xrange(self.n_valid_batches)] this_validation_loss = np.mean(validation_losses) logging.info('server_stamp %i, validation error %f %%' % ( server_stamp, this_validation_loss * 100.) ) self.validation_timestamps.append(server_stamp) self.validation_results.append(this_validation_loss)
def fetch_update(self, iteration): """ Decide where the next grad update will come from. Also decides whether to drop the grad """ client_id = sample(self.client_priorities, self.blocking) self.update_priorities() # overwrite the models params with client params param_copy(self.client_params[client_id], self.classifier.params) minibatch_index = iteration % self.n_train_batches grads, parameter_timestamp = self.pusher(self, minibatch_index, client_id, j=self.j) return (grads, parameter_timestamp, client_id)
def update_parameters(self, params, client, server_stamp, unblock, v): """ Give new parameters to a client. """ # update grad magnitude mean self.v = v # add client to blocking set no matter what if client not in self.blocking: self.blocking.append(client) if unblock: # update params of all blocking clients for client_id in self.blocking: if self.fetcher(self, self.k, client): # we've decided to pull updates param_copy(params, self.client_params[client_id]) else: # we're going to ignore that (we could have not copied it) pass self.parameter_stamps[client_id] = server_stamp self.blocking = [] # nothing is blocking now