303217b34070dc47a86622b62764098999b0d7f5,gpytorch/lazy/lazy_tensor.py,LazyTensor,_quad_form_derivative,#LazyTensor#Any#Any#,378

Before Change


        toggled = [False] * len(args)

        for i, arg in enumerate(args):
            if not arg.requires_grad:
                arg.requires_grad = True
                toggled[i] = True

        loss = (left_vecs * self._matmul(right_vecs)).sum()
        loss.requires_grad_(True)
        grads = torch.autograd.grad(loss, args, allow_unused=True)

After Change


        from collections import deque

        args = tuple(self.representation())
        args_with_grads = tuple(arg for arg in args if arg.requires_grad)

        // Easy case: if we don"t require any gradients, then just return!
        if not len(args_with_grads):
            return tuple(None for _ in args)

        // Normal case: we"ll use the autograd to get us a derivative
        with torch.autograd.enable_grad():
            loss = (left_vecs * self._matmul(right_vecs)).sum()
            loss.requires_grad_(True)
            actual_grads = deque(torch.autograd.grad(loss, args_with_grads, allow_unused=True))

        // Now make sure that the object we return has one entry for every item in args
        grads = []
        for arg in args:
            if arg.requires_grad:
                grads.append(actual_grads.popleft())
            else:
                grads.append(None)
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 3

Instances


Project Name: cornellius-gp/gpytorch
Commit Name: 303217b34070dc47a86622b62764098999b0d7f5
Time: 2018-12-12
Author: gpleiss@gmail.com
File Name: gpytorch/lazy/lazy_tensor.py
Class Name: LazyTensor
Method Name: _quad_form_derivative


Project Name: deepgram/kur
Commit Name: b2d8ee42f12c7d033bdeb929c9f38b3c90e48582
Time: 2017-03-23
Author: ajsyp@syptech.net
File Name: kur/kurfile.py
Class Name: Kurfile
Method Name: _parse_model


Project Name: Theano/Theano
Commit Name: 996d737eaad2a85cda13954efa5b066ade1e678d
Time: 2017-02-09
Author: nouiz@nouiz.org
File Name: theano/scan_module/scan_utils.py
Class Name:
Method Name: forced_replace