[Need Discussion] Implement twice backward of ConvNd#1569
[Need Discussion] Implement twice backward of ConvNd#1569caogang wants to merge 7 commits intopytorch:masterfrom
Conversation
|
I don't understand what these ConvForward and ConvBackward sequences mean. I also don't really know where do you want to accumulate the grads -- these functions only compute and return them, there's no accumulation going on. |
|
Also, you're not doing |
|
Ok, I change the test code as follows. it can still pass the test inputs = (autograd.Variable(torch.randn(1, 12, 12).double(), requires_grad=True),
autograd.Variable(torch.randn(10, 12, 5).double(), requires_grad=True,),
autograd.Variable(torch.randn(10).double(), requires_grad=True))
test = gradcheck(lambda i, w, b : F.conv1d(i, w, b), inputs, eps=1e-6, atol=1e-4)
print(test)
inputs = (autograd.Variable(torch.randn(1, 12, 12).double(), requires_grad=True),
autograd.Variable(torch.randn(12, 10, 5).double(), requires_grad=True,),
autograd.Variable(torch.randn(10).double(), requires_grad=True))
test = gradcheck(lambda i, w, b : F.conv1d(i, w, b), inputs, eps=1e-6, atol=1e-4)
print(test) |
|
By the way. Do you have any idea of the first problem that I want to use another function when passing arguments |
|
You need to remove |
|
Ok, the first problem is solved. Now I found there are something wrong with accumulating the |
|
You don't need to accumulate any grads! Just return them from |
There was a problem hiding this comment.
Ok, so @albanD pointed out that grad of grad of ConvNd is not a plain forward convolution, but an expression that has 2x forward convolution and a few additions (I haven't verified that yet though). If that's the case, then you shouldn't create a backward and forward mode in the ConvForward function, but create ConvBackwardBackward which doesn't unpack the Variables in its apply, but uses ConvForward and Add functions to compute it's output. This will be enough to make it infinitely many times differentiable
| outputs[g] = compute_output( | ||
| input_g.get(), weight_g.get(), bias_g.get(), | ||
| columns[g].get(), ones[g].get(), kernel_size, *this); | ||
| std::cout << "ConvForward in grad mode" << std::endl; |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| dilation: the spacing between kernel elements. Default: 1 | ||
| """ | ||
| f = ConvNd(_triple(stride), _triple(padding), _triple(dilation), True, | ||
| f = ConvNdBackward(_triple(stride), _triple(padding), _triple(dilation), True, |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
albanD has implemented this feature. Please refer to #1643 . |
…827566 Summary: Previous import was 7abd834091f1024c11749dcfd25126802db9fdd5 Included changes: - **[84a0441](onnx/onnx@84a0441)**: Clarify namescopes in the presence of nested subgraphs (pytorch#1665) <G. Ramalingam> - **[118fec5](onnx/onnx@118fec5)**: Add Where op. (pytorch#1569) <Sergii Dymchenko> - **[beefa15](onnx/onnx@beefa15)**: Use strings directly for casing as np.object w/o redundant StringHolder. (pytorch#1736) <Dmitri Smirnov> - **[4023bae](onnx/onnx@4023bae)**: Add a capability to input/output unicode strings (pytorch#1734) <Dmitri Smirnov> - **[1a8a7fc](onnx/onnx@1a8a7fc)**: typos fixed: iutput -> input (pytorch#1726) <Beomsoo Kim> - **[0128478](onnx/onnx@0128478)**: Scan test update (pytorch#1732) <G. Ramalingam> - **[c6a24fd](onnx/onnx@c6a24fd)**: turn rtol to 0.002 on densenet121, since AMD and Nvidia GPU's precion difference (pytorch#1733) <Lu Fang> - **[5b7ac72](onnx/onnx@5b7ac72)**: Add Shrink operator (pytorch#1622) <Rui Zhu> Differential Revision: D13676711 fbshipit-source-id: 0b7b8a398afa4a3b54752fb792f19e7efca80f65
…827566 (#16046) Summary: Pull Request resolved: #16046 Previous import was 7abd834091f1024c11749dcfd25126802db9fdd5 Included changes: - **[84a0441](onnx/onnx@84a0441)**: Clarify namescopes in the presence of nested subgraphs (#1665) <G. Ramalingam> - **[118fec5](onnx/onnx@118fec5)**: Add Where op. (#1569) <Sergii Dymchenko> - **[beefa15](onnx/onnx@beefa15)**: Use strings directly for casing as np.object w/o redundant StringHolder. (#1736) <Dmitri Smirnov> - **[4023bae](onnx/onnx@4023bae)**: Add a capability to input/output unicode strings (#1734) <Dmitri Smirnov> - **[1a8a7fc](onnx/onnx@1a8a7fc)**: typos fixed: iutput -> input (#1726) <Beomsoo Kim> - **[0128478](onnx/onnx@0128478)**: Scan test update (#1732) <G. Ramalingam> - **[c6a24fd](onnx/onnx@c6a24fd)**: turn rtol to 0.002 on densenet121, since AMD and Nvidia GPU's precion difference (#1733) <Lu Fang> - **[5b7ac72](onnx/onnx@5b7ac72)**: Add Shrink operator (#1622) <Rui Zhu> Reviewed By: yinghai Differential Revision: D13676711 fbshipit-source-id: 513cc137223469b47af48919432aaecf58006012
* cache_after to cacheAfter * cache_before to cacheBefore * cache_fork to cacheFork
Hi, all.
This PR is following the PR #1555 with cleaner rebase.
@apaszke I have followed your suggestion to modify the
ConvForwarddirectly. And change the implementation methods ofConvTransposeNdto useConvBackwarddirectly instead ofConvForward(transposed). Here is the commit. And I have usedgradcheckto check the two gradient. It passed the following test.However when I use it to perform grad of grad of
ConvForward, it raise error. So for now, do not merge this PR.Assume the forward formula to calculate, is ConvForward(forward_mode) -> ConvForward(forward_mode) -> ConvBackward(grad_mode) ->ConvBackward(grad_mode). And the backward process is ConvForward(grad_mode) -> ConvForward(grad_mode) -> ConvBackward(grad_mode) -> ConvBackward (grad_mode). It raised a
Segment FaultError at the third backward process unit,ConvBackward(grad_mode)I have found the problem is because of the
std::move(convolution)inConvBackward::apply. During the forward process ofConvBackward(grad_mode), it will usestd::move(convolution)to pass arguments, andconvolutionof itself will be zero. When the second time processing this unit in backward process, some parameters likeconvolutionwill cause thisSegment error.convolutionparameters with itself retained not be cleared when usingstd::movein the following place?