/usr/local/lib64/python3.6/site-packages/torch/nn/__pycache__
Edit: /usr/local/lib64/python3.6/site-packages/torch/nn/__pycache__/grad.cpython-36.pyc (11840B)
3
Eg6 @ sr d Z ddlZddlmZmZmZ ddlZdddZdddZdd d
Z dddZ
dd
dZdddZdddZ
dS )zGradient interface N )_single_pair_triplec s d kr t jd dgt tj d }t|d krR| d t|krvtdj|d t fddfddt|D fd dt|D }xJt|D ]:\}} }
|| k s||
krtd
j|j dd qW t
fddt|D S )
NzK_grad_input_padding 'dilation' argument not provided. Default of 1 is used.r z)input_size must have {} elements (got {})c s> j | d d | d| d | | d S )Nr r )size)d)dilationgrad_outputkernel_sizepaddingstride 9/usr/local/lib64/python3.6/site-packages/torch/nn/grad.pydim_size s z%_grad_input_padding.
.dim_sizec s g | ]} |qS r r ).0r )r r r
s z'_grad_input_padding..c s g | ]} | | d qS )r r )r r ) min_sizesr
r r r s zarequested an input grad size of {}, but valid sizes range from {} to {} (for a grad_output of {})c 3 s | ]} | | V qd S )Nr )r r )
input_sizer r r % s z&_grad_input_padding..)warningswarnlenlistdim
ValueErrorformatrangezipr tuple)r
r r
r r r kZ max_sizesr Zmin_sizemax_sizer )r r r
r r r r r
r _grad_input_padding s(
r" c C s^ t |}t |}t |}|jd g}| dkr4tdt|| ||||}tj||d|||||S )a
Computes 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)
r Nz3grad.conv1d_input requires specifying an input_size)r shaper r" torchZconv_transpose1d) r weightr
r
r r groupsr grad_input_paddingr r r conv1d_input( s
r( c C s t |}t |}t |}| jd }|jd }| jd } |j jd|| d}|j j|jd |jd d|jd }| j jd| jd | jd | jd } tj| |d||||| }
|
j j| |
jd | |
jd }
|
jddj|| ||
jd jddj dd|d S )a!
Computes 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)
>>> grad_weight = torch.autograd.grad(output, filter, grad_output)
>>> F.grad.conv1d_weight(input, weight.shape, grad_output)
r r r N)r )
r r#
contiguousrepeatviewr$ Zconv1dsum transposenarrow)inputweight_sizer
r
r r r&