L i&dZddlZddlmZmZmZ d dZ d dZ d dZ d dZ d dZ d d Z y) zGradient interface.N)_pair_single_triplec |jdj|}tjjj |||dt |t |t |ddg|d dS)aCompute the gradient of conv1d with respect to the input of the convolution. This is same as the 1D transposed convolution operator under the hood but requires the shape of the gradient w.r.t. input to be specified explicitly. Args: input_size : Shape of the input gradient tensor weight: weight tensor (out_channels x in_channels/groups x kW) grad_output : output gradient tensor (minibatch x out_channels x oW) stride (int or tuple, optional): Stride of the convolution. Default: 1 padding (int or tuple, optional): Zero-padding added to both sides of the input. Default: 0 dilation (int or tuple, optional): Spacing between kernel elements. Default: 1 groups (int, optional): Number of blocked connections from input channels to output channels. Default: 1 Examples:: >>> input = torch.randn(1, 1, 3, requires_grad=True) >>> weight = torch.randn(1, 1, 1, requires_grad=True) >>> output = F.conv1d(input, weight) >>> grad_output = torch.randn(output.shape) >>> grad_input = torch.autograd.grad(output, input, grad_output) >>> F.grad.conv1d_input(input.shape, weight, grad_output) NFrTFF new_emptyexpandtorchopsatenconvolution_backwardr input_sizeweight grad_outputstridepaddingdilationgroupsinputs S/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/torch/nn/grad.py conv1d_inputrvB  ! !! $ + +J 7E 99>> . .      c |jdj|}tjjj |||dt |t |t |ddg|d dS)a=Compute the gradient of conv1d with respect to the weight of the convolution. Args: input: input tensor of shape (minibatch x in_channels x iW) weight_size : Shape of the weight gradient tensor grad_output : output gradient tensor (minibatch x out_channels x oW) stride (int or tuple, optional): Stride of the convolution. Default: 1 padding (int or tuple, optional): Zero-padding added to both sides of the input. Default: 0 dilation (int or tuple, optional): Spacing between kernel elements. Default: 1 groups (int, optional): Number of blocked connections from input channels to output channels. Default: 1 Examples:: >>> input = torch.randn(1, 1, 3, requires_grad=True) >>> weight = torch.randn(1, 1, 1, requires_grad=True) >>> output = F.conv1d(input, weight) >>> grad_output = torch.randn(output.shape) >>> # xdoctest: +SKIP >>> grad_weight = torch.autograd.grad(output, filter, grad_output) >>> F.grad.conv1d_weight(input, weight.shape, grad_output) rNFrFTFr r weight_sizerrrrrrs r conv1d_weightr!:su> " "1 % , ,[ 9F 99>> . .      rc |jdj|}tjjj |||dt |t |t |ddg|d dS)aCompute the gradient of conv2d with respect to the input of the convolution. This is same as the 2D transposed convolution operator under the hood but requires the shape of the gradient w.r.t. input to be specified explicitly. Args: input_size : Shape of the input gradient tensor weight: weight tensor (out_channels x in_channels/groups x kH x kW) grad_output : output gradient tensor (minibatch x out_channels x oH x oW) stride (int or tuple, optional): Stride of the convolution. Default: 1 padding (int or tuple, optional): Zero-padding added to both sides of the input. Default: 0 dilation (int or tuple, optional): Spacing between kernel elements. Default: 1 groups (int, optional): Number of blocked connections from input channels to output channels. Default: 1 Examples:: >>> input = torch.randn(1, 1, 3, 3, requires_grad=True) >>> weight = torch.randn(1, 1, 1, 2, requires_grad=True) >>> output = F.conv2d(input, weight) >>> grad_output = torch.randn(output.shape) >>> grad_input = torch.autograd.grad(output, input, grad_output) >>> F.grad.conv2d_input(input.shape, weight, grad_output) rNFrrr r r r rrrrs r conv2d_inputr$jstB  ! !! $ + +J 7E 99>> . .   f  g h    rc |jdj|}tjjj |||dt |t |t |ddg|d dS)aMCompute the gradient of conv2d with respect to the weight of the convolution. Args: input: input tensor of shape (minibatch x in_channels x iH x iW) weight_size : Shape of the weight gradient tensor grad_output : output gradient tensor (minibatch x out_channels x oH x oW) stride (int or tuple, optional): Stride of the convolution. Default: 1 padding (int or tuple, optional): Zero-padding added to both sides of the input. Default: 0 dilation (int or tuple, optional): Spacing between kernel elements. Default: 1 groups (int, optional): Number of blocked connections from input channels to output channels. Default: 1 Examples:: >>> input = torch.randn(1, 1, 3, 3, requires_grad=True) >>> weight = torch.randn(1, 1, 1, 2, requires_grad=True) >>> output = F.conv2d(input, weight) >>> grad_output = torch.randn(output.shape) >>> # xdoctest: +SKIP >>> grad_weight = torch.autograd.grad(output, filter, grad_output) >>> F.grad.conv2d_weight(input, weight.shape, grad_output) rNFrrr#rs r conv2d_weightr&ss> " "1 % , ,[ 9F 99>> . .   f  g h    rc |jdj|}tjjj |||dt |t |t |ddg|d dS)aCompute the gradient of conv3d with respect to the input of the convolution. This is same as the 3D transposed convolution operator under the hood but requires the shape of the gradient w.r.t. input to be specified explicitly. Args: input_size : Shape of the input gradient tensor weight: weights tensor (out_channels x in_channels/groups x kT x kH x kW) grad_output : output gradient tensor (minibatch x out_channels x oT x oH x oW) stride (int or tuple, optional): Stride of the convolution. Default: 1 padding (int or tuple, optional): Zero-padding added to both sides of the input. Default: 0 dilation (int or tuple, optional): Spacing between kernel elements. Default: 1 groups (int, optional): Number of blocked connections from input channels to output channels. Default: 1 Examples:: >>> input = torch.randn(2, 8, 10, 10, 20, requires_grad=True) >>> weight = torch.randn(4, 8, 2, 3, 3, requires_grad=True) >>> output = F.conv3d(input, weight) >>> grad_output = torch.randn(output.shape) >>> grad_input = torch.autograd.grad(output, input, grad_output) >>> F.grad.conv3d_input(input.shape, weight, grad_output) rNFrrr r r r rrrrs r conv3d_inputr)rrc |jdj|}tjjj |||dt |t |t |ddg|d dS)aBCompute the gradient of conv3d with respect to the weight of the convolution. Args: input: input tensor of shape (minibatch x in_channels x iT x iH x iW) weight_size : Shape of the weight gradient tensor grad_output : output gradient tensor (minibatch x out_channels x oT x oH x oW) stride (int or tuple, optional): Stride of the convolution. Default: 1 padding (int or tuple, optional): Zero-padding added to both sides of the input. Default: 0 dilation (int or tuple, optional): Spacing between kernel elements. Default: 1 groups (int, optional): Number of blocked connections from input channels to output channels. Default: 1 Examples:: >>> input = torch.randn(2, 8, 10, 10, 20, requires_grad=True) >>> weight = torch.randn(4, 8, 2, 3, 3, requires_grad=True) >>> output = F.conv3d(input, weight) >>> grad_output = torch.randn(output.shape) >>> grad_weight = torch.autograd.grad(output, weight, grad_output) >>> F.grad.conv3d_weight(input, weight.shape, grad_output) rNFrrr(rs r conv3d_weightr+su< " "1 % , ,[ 9F 99>> . .      r)rrrr) __doc__r torch.nn.modules.utilsrrrrr!r$r&r)r+rrr/s ::  / l  - h  / l  - h  / l  , r