Skip to content

Commit

Permalink
Avoid overwriting y and dy in the backward pass
Browse files Browse the repository at this point in the history
  • Loading branch information
ducksoup committed Jan 7, 2020
1 parent 826d7c9 commit fd332f2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ To install PyTorch, please refer to https://github.com/pytorch/pytorch#installat

To install the package containing the iABN layers:
```bash
pip install git+https://github.com/mapillary/[email protected].8
pip install git+https://github.com/mapillary/[email protected].9
```
Note that some parts of InPlace-ABN have native C++/CUDA implementations, meaning that the command above will need to
compile them.
Expand Down
3 changes: 3 additions & 0 deletions inplace_abn/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ def forward(ctx, x, weight, bias, running_mean, running_var,
def backward(ctx, dy_act):
y_act, var, count, weight, bias = ctx.saved_tensors

# Create clones of y_act and dy_act, as the backend will modify them in-place
y_act, dy_act = y_act.clone(), dy_act.clone()

# Call backward_reduce if we need to compute at least one of the gradients
if any(ctx.needs_input_grad):
sum_dy_local, sum_xhat_dy_local = _backend.backward_reduce(
Expand Down

0 comments on commit fd332f2

Please sign in to comment.