b05a4a145bd485c1b988942b033191ca57410f72,slm_lab/agent/net/mlp.py,HydraMLPNet,training_step,#HydraMLPNet#Any#Any#Any#Any#Any#,308

Before Change


        Takes a single training step: one forward and one backwards pass. Both x and y are lists of the same length, one x and y per environment
        """
        self.train()
        self.zero_grad()
        self.optim.zero_grad()
        if loss is None:
            outs = self(xs)
            total_loss = torch.tensor(0.0, device=self.device)
            for out, y in zip(outs, ys):
                loss = self.loss_fn(out, y)
                total_loss += loss
            loss = total_loss
        assert not torch.isnan(loss).any(), loss
        if net_util.to_assert_trained():
            assert_trained = net_util.gen_assert_trained(self)
        loss.backward(retain_graph=retain_graph)
        if self.clip_grad:
            logger.debug(f"Clipping gradient: {self.clip_grad_val}")
            nn.utils.clip_grad_norm_(self.parameters(), self.clip_grad_val)
        if global_net is None:
            self.optim.step()
        else:  // distributed training with global net
            net_util.push_global_grad(self, global_net)
            self.optim.step()
            net_util.pull_global_param(self, global_net)
        if net_util.to_assert_trained():
            assert_trained(self, loss)
            self.store_grad_norms()
        logger.debug(f"Net training_step loss: {loss}")

After Change


        """
        Takes a single training step: one forward and one backwards pass. Both x and y are lists of the same length, one x and y per environment
        """
        self.lr_scheduler.step(epoch=lr_t)
        self.train()
        self.optim.zero_grad()
        if loss is None:
            outs = self(xs)
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 9

Instances


Project Name: kengz/SLM-Lab
Commit Name: b05a4a145bd485c1b988942b033191ca57410f72
Time: 2018-11-14
Author: kengzwl@gmail.com
File Name: slm_lab/agent/net/mlp.py
Class Name: HydraMLPNet
Method Name: training_step


Project Name: kengz/SLM-Lab
Commit Name: 0ac2b33e8c63304a50db7d2b484368299706b58b
Time: 2018-11-14
Author: kengzwl@gmail.com
File Name: slm_lab/agent/net/recurrent.py
Class Name: RecurrentNet
Method Name: training_step


Project Name: kengz/SLM-Lab
Commit Name: 0ac2b33e8c63304a50db7d2b484368299706b58b
Time: 2018-11-14
Author: kengzwl@gmail.com
File Name: slm_lab/agent/net/mlp.py
Class Name: MLPNet
Method Name: training_step