def copyReceiver(self): oldbot = models.Receiver(self.args).to(self.device) oldbot.load_state_dict(self.rbot.state_dict()) print('\nParameters in the old Receiver are copied') oldrOptimizer = optim.Adam(oldbot.parameters(), lr=self.rLearnRate) oldrOptimizer.load_state_dict(self.rOptimizer.state_dict()) return oldbot, oldrOptimizer
def __init__(self, args): self.args = args for key, value in args.items(): setattr(self, key, value) self.sbot = models.Sender(args).to(self.device) print('sbot', self.sbot) self.rbot = models.Receiver(args).to(self.device) print('rbot', self.rbot) self.sOptimizer = optim.Adam(self.sbot.parameters(), lr=self.sLearnRate) self.rOptimizer = optim.Adam(self.rbot.parameters(), lr=self.rLearnRate)
def __init__(self, args): self.args = args for key, value in args.items(): setattr(self, key, value) self.sbot = models.Sender(args).to(self.device) print('sbot', self.sbot) self.sOptimizer = optim.Adam(self.sbot.parameters(), lr=self.sLearnRate) self.rbotGroup = [ models.Receiver(args).to(self.device) for _ in range(self.receiverNum) ] print('group size', len(self.rbotGroup)) self.rOptimizerGroup = [ optim.Adam(r.parameters(), lr=self.rLearnRate) for r in self.rbotGroup ] self.oldest = 0
def renewOneReceiver(self): self.rbotGroup.pop(self.oldest) self.rOptimizerGroup.pop(self.oldest) self.rbotGroup.insert(self.oldest, models.Receiver(self.args).to(self.device)) self.rOptimizerGroup.insert( self.oldest, optim.Adam(self.rbotGroup[self.oldest].parameters(), lr=self.rLearnRate)) print('Kickoff ', str(self.oldest), ' th receiver and get a newbie') if self.oldest < self.receiverNum - 1: self.oldest += 1 else: self.oldest = 0 # update sender optimizer self.sOptimizer = optim.Adam(self.sbot.parameters(), lr=self.sLearnRate)
def evalReceiver(self): rbot = models.Receiver(self.args).to(self.device) rOptimizer = optim.Adam(rbot.parameters(), lr=self.rLearnRate) return rbot, rOptimizer