Created
November 22, 2017 20:47
-
-
Save colesbury/5cea3070aa1944f80e298aef42f703c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/torch/csrc/autograd/functions/convolution.cpp b/torch/csrc/autograd/functions/convolution.cpp | |
index 465283c..991648c 100644 | |
--- a/torch/csrc/autograd/functions/convolution.cpp | |
+++ b/torch/csrc/autograd/functions/convolution.cpp | |
@@ -578,6 +578,16 @@ auto ConvBackwardBackward::apply(const variable_list& grad_grad_inputs) -> varia | |
gI = Transpose(0, 1).apply({gIt})[0]; | |
} | |
+ auto zeros_like = [](const Variable& var) -> std::shared_ptr<Variable> { | |
+ auto data = var.data->newTensor(); | |
+ data->resizeAs(*var.data).zero(); | |
+ return std::make_shared<Variable>(std::move(data), false, false); | |
+ }; | |
+ | |
+ if (should_compute_output(0) && !ggO) ggO = zeros_like(*gO); | |
+ if (should_compute_output(1) && !gI) gI = zeros_like(*input); | |
+ if (should_compute_output(2) && !gW) gW = zeros_like(*weight); | |
+ | |
return {ggO, gI, gW}; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment