Exemple #1
0
 def populate(self, info):
     self.send(protocol.call_method("populate", info))
     done = wait_until(self.return_method, conf.FUNC_TIMEOUT, 1, "populate")
     if done and self.callbacks['populate']['s']:
         del self.callbacks['populate']
         log('success', f"{self} populated successfully")
     elif done:
         log("error", f"Error populating {self}")
     else:
         log('warning', f"Calling populate() timeout  after {conf.FUNC_TIMEOUT} seconds")
Exemple #2
0
def update_model(peer, w_gar, evaluate=False, t=None):
    peer.set_model_params(w_gar)
    # TODO Review update function
    # peer.take_step()
    if evaluate:
        t_eval = peer.evaluate(peer.inference, one_batch=True)
        peer.params.logs.append(t_eval)
        r = f"ROUND[{t}], val_loss: {t_eval['val_loss']:.4f}, val_acc: {t_eval['val_acc']:.4f}"
        peer.log("success", r, remote=False)
        peer.bridge.send(protocol.call_method("log_results", t_eval))
Exemple #3
0
 def fit(self, inference):
     self.send(protocol.call_method("fit", inference))
     done = wait_until(self.return_method, conf.FUNC_TIMEOUT, 1, "fit")
     if done and self.callbacks['fit']['s']:
         history = self.callbacks['fit']['m']
         del self.callbacks['fit']
         # for i, h in enumerate(history):
         #     log('', f"Epoch [{i}], val_loss: {h['val_loss']:.4f}, val_acc: {h['val_acc']:.4f}")
         return history
     else:
         log('warning', f"Calling fit() timeout  after {conf.FUNC_TIMEOUT} seconds")
         return None
Exemple #4
0
 def connect(self, neighbor):
     self.send(protocol.call_method("connect", neighbor.id, neighbor.host, neighbor.port))
     done = wait_until(self.return_method, conf.FUNC_TIMEOUT, 1, "connect")
     if done and self.callbacks['connect']['s']:
         self.neighbors.append(neighbor.id)
         del self.callbacks["connect"]
         return True
     elif done:
         log("error", self.callbacks['connect']['m'])
         return False
     else:
         log('warning', f"Calling connect() timeout  after {conf.FUNC_TIMEOUT} seconds")
         return False
Exemple #5
0
def train_init(peer):
    peer.log('event',
             f'Starting collaborative training using {name} ...',
             remote=False)
    peer.log("info", f"Initializing Collaborative training...", remote=False)
    r = peer.evaluate(peer.inference, one_batch=True)
    peer.bridge.send(protocol.call_method("log_results", r))
    peer.params.logs = [r]
    peer.params.exchanges = 0
    peer.params.n_accept = 0
    peer.params.n_reject = 0
    peer.params.delta = 0.8
    peer.params.beta = 1
    peer.params.mu = 0.3
    peer.params.Wi = {n.neighbor_id: 0 for n in peer.neighbors}
    peer.params.E = 5
    peer.params.e = peer.params.E
    peer.params.k = int(np.sqrt(len(peer.neighbors)))
    return
Exemple #6
0
 def execute(self, func, *args, **kwargs):
     method = f"execute.{func.__name__}"
     msg = protocol.call_method(method, *args, **kwargs)
     self.send(msg)
     self.current_exec = method