def run_with_num_hosts(self, num_hosts): _, guest, *hosts = self.run_results(num_hosts) expert = OrderDictWeights(guest[1]) * guest[2] total_weights = guest[2] aggregated = [guest[0]] for host in hosts: expert += OrderDictWeights(host[1]) * host[2] total_weights += host[2] aggregated.append(host[0]) expert /= total_weights expert = expert.unboxed aggregated = [w.unboxed for w in aggregated] for k in expert: for w in aggregated: self.assertAlmostEqual(np.linalg.norm(expert[k] - w[k]), 0.0)
def secure_aggregator_call(job_id, role, ind, *args): if role == consts.ARBITER: agg = secure_mean_aggregator.Server() model = agg.weighted_mean_model() agg.send_aggregated_model(model) else: agg = secure_mean_aggregator.Client() # disorder dit order = list(range(5)) np.random.seed(random.SystemRandom().randint(1, 100)) np.random.shuffle(order) raw = {k: np.random.rand(10, 10) for k in order} w = OrderDictWeights(copy.deepcopy(raw)) d = random.random() agg.send_weighted_model(w, weight=d) aggregated = agg.get_aggregated_model() return aggregated, raw, d
def call(cls, role, transfer_variable, ind, *args): agg = aggregator.with_role(role, transfer_variable, enable_secure_aggregate=True) if role == consts.ARBITER: agg.aggregate_and_broadcast() print(agg.aggregate_loss()) else: # disorder dit order = list(range(5)) np.random.seed(random.SystemRandom().randint(1, 100)) np.random.shuffle(order) raw = {k: np.random.rand(10, 10) for k in order} w = OrderDictWeights(copy.deepcopy(raw)) d = random.random() aggregated = agg.aggregate_then_get(w, degree=d) agg.send_loss(2.0) return aggregated, raw, d
def get_model_weights(self) -> OrderDictWeights: return OrderDictWeights(self._model.state_dict())
def get_model_weights(self) -> OrderDictWeights: return OrderDictWeights(self._sess.run(self._trainable_weights))
def get_model_weights(self) -> OrderDictWeights: """ Return model's weights as OrderDictWeights. :return: model's weights. """ return OrderDictWeights(self.session.run(self._aggregate_weights))
def get_model_weights(self) -> OrderDictWeights: return OrderDictWeights(self.session.run(self._aggregate_weights))