Skip to content

Commit fd332f2

Browse files
committed
Avoid overwriting y and dy in the backward pass
1 parent 826d7c9 commit fd332f2

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ To install PyTorch, please refer to https://github.com/pytorch/pytorch#installat
5454

5555
To install the package containing the iABN layers:
5656
```bash
57-
pip install git+https://github.com/mapillary/[email protected].8
57+
pip install git+https://github.com/mapillary/[email protected].9
5858
```
5959
Note that some parts of InPlace-ABN have native C++/CUDA implementations, meaning that the command above will need to
6060
compile them.

inplace_abn/functions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ def forward(ctx, x, weight, bias, running_mean, running_var,
106106
def backward(ctx, dy_act):
107107
y_act, var, count, weight, bias = ctx.saved_tensors
108108

109+
# Create clones of y_act and dy_act, as the backend will modify them in-place
110+
y_act, dy_act = y_act.clone(), dy_act.clone()
111+
109112
# Call backward_reduce if we need to compute at least one of the gradients
110113
if any(ctx.needs_input_grad):
111114
sum_dy_local, sum_xhat_dy_local = _backend.backward_reduce(

0 commit comments

Comments
 (0)