for x in ctx.input_tensors: if isinstance(x, int): print('-----------------', ctx.run_function)
(ctx, *output_grads)
| 118 | @staticmethod |
| 119 | @torch.cuda.amp.custom_bwd # add this |
| 120 | def backward(ctx, *output_grads): |
| 121 | ''' |
| 122 | for x in ctx.input_tensors: |
| 123 | if isinstance(x, int): |
| 124 | print('-----------------', ctx.run_function) |
| 125 | ''' |
| 126 | ctx.input_tensors = [x.detach().requires_grad_(True) for x in ctx.input_tensors] |
| 127 | with torch.enable_grad(): |
| 128 | # Fixes a bug where the first op in run_function modifies the |
| 129 | # Tensor storage in place, which is not allowed for detach()'d |
| 130 | # Tensors. |
| 131 | shallow_copies = [x.view_as(x) for x in ctx.input_tensors] |
| 132 | output_tensors = ctx.run_function(*shallow_copies) |
| 133 | input_grads = torch.autograd.grad( |
| 134 | output_tensors, |
| 135 | ctx.input_tensors + ctx.input_params, |
| 136 | output_grads, |
| 137 | allow_unused=True, |
| 138 | ) |
| 139 | del ctx.input_tensors |
| 140 | del ctx.input_params |
| 141 | del output_tensors |
| 142 | return (None, None) + input_grads |
nothing calls this directly
no outgoing calls
no test coverage detected