def begin_update(self, x_data, drop=0.0):
        """Return the output of the wrapped PyTorch model for the given input,
        along with a callback to handle the backward pass.
        """
        x_var = torch.autograd.Variable(xp2torch(x_data), requires_grad=True)
        # Make prediction

        y_var = self._model(x_var)

        def backward_pytorch(dy_data, sgd=None):
            dy_var = xp2torch(dy_data)
            torch.autograd.backward((y_var,), grad_tensors=(dy_var,))
            if sgd is not None:
                if self._optimizer is None:
                    self._optimizer = self._create_optimizer(sgd)
                self._optimizer.step()
                self._optimizer.zero_grad()
            return torch2xp(x_var.grad)

        return torch2xp(y_var), backward_pytorch
def begin_update ( self , x_data , drop = 0.0 ) : x_var = torch . autograd . Variable ( xp2torch ( x_data ) , requires_grad = True ) y_var = self . _model ( x_var ) def backward_pytorch ( dy_data , sgd = None ) : dy_var = xp2torch ( dy_data ) torch . autograd . backward ( ( y_var , ) , grad_tensors = ( dy_var , ) ) if sgd is not None : if self . _optimizer is None : self . _optimizer = self . _create_optimizer ( sgd ) self . _optimizer . step ( ) self . _optimizer . zero_grad ( ) return torch2xp ( x_var . grad ) return torch2xp ( y_var ) , backward_pytorch
Return the output of the wrapped PyTorch model for the given input,
        along with a callback to handle the backward pass.