def from_tensors(self, tensors): flat_dists = [ d.from_tensors(t) for d, t in zip(nest.flatten(self.dists), tensors) ] return ProductDistribution( nest.pack_sequence_as(flat_dists, nest.get_structure(self.dists)))
def save(self): """Save.""" state_dict = { 'pi': self.pi.state_dict(), 'qf1': self.qf1.state_dict(), 'qf2': self.qf2.state_dict(), 'vf': self.vf.state_dict(), 'opt_pi': self.opt_pi.state_dict(), 'opt_qf1': self.opt_qf1.state_dict(), 'opt_qf2': self.opt_qf2.state_dict(), 'opt_vf': self.opt_vf.state_dict(), 'log_alpha': (self.log_alpha if self.automatic_entropy_tuning else None), 'opt_alpha': (self.opt_alpha.state_dict() if self.automatic_entropy_tuning else None), 'env': misc.env_state_dict(self.env), 't': self.t } buffer_dict = self.buffer.state_dict() state_dict['buffer_format'] = nest.get_structure(buffer_dict) self.ckptr.save(state_dict, self.t) # save buffer seperately and only once (because it can be huge) np.savez(os.path.join(self.ckptr.ckptdir, 'buffer.npz'), **{f'{i:04d}': x for i, x in enumerate(nest.flatten(buffer_dict))})
def save(self): """State dict.""" state_dict = { 'pi': self.pi.state_dict(), 'opt': self.opt.state_dict(), 't': self.t } buffer_dict = self.buffer.state_dict() state_dict['buffer_format'] = nest.get_structure(buffer_dict) self.ckptr.save(state_dict, self.t) # save buffer seperately and only once (because it can be huge) np.savez( os.path.join(self.ckptr.ckptdir, 'buffer.npz'), **{f'{i:04d}': x for i, x in enumerate(nest.flatten(buffer_dict))})
def save(self): """Save.""" state_dict = { 'qf': self.qf.state_dict(), 'qf_targ': self.qf.state_dict(), 'opt': self.opt.state_dict(), '_actor': self._actor.state_dict(), 'env': misc.env_state_dict(self.env), 't': self.t } buffer_dict = self.buffer.state_dict() state_dict['buffer_format'] = nest.get_structure(buffer_dict) self.ckptr.save(state_dict, self.t) # save buffer seperately and only once (because it can be huge) np.savez(os.path.join(self.ckptr.ckptdir, 'buffer.npz'), **{f'{i:04d}': x for i, x in enumerate(nest.flatten(buffer_dict))})