MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / conv1d

Function conv1d

imperative/python/megengine/functional/nn.py:153–221  ·  view source on GitHub ↗

r"""1D convolution operation. Refer to :class:`~.Conv1d` for more information. Args: inp: The feature map of the convolution operation weight: The convolution kernel. bias: The bias added to the result of convolution (if given) stride: Stride of the 1D convo

(
    inp: Tensor,
    weight: Tensor,
    bias: Optional[Tensor] = None,
    stride: int = 1,
    padding: int = 0,
    dilation: int = 1,
    groups: int = 1,
    conv_mode="cross_correlation",
    compute_mode="default",
)

Source from the content-addressed store, hash-verified

151
152
153def conv1d(
154 inp: Tensor,
155 weight: Tensor,
156 bias: Optional[Tensor] = None,
157 stride: int = 1,
158 padding: int = 0,
159 dilation: int = 1,
160 groups: int = 1,
161 conv_mode="cross_correlation",
162 compute_mode="default",
163) -> Tensor:
164 r"""1D convolution operation.
165
166 Refer to :class:`~.Conv1d` for more information.
167
168 Args:
169 inp: The feature map of the convolution operation
170 weight: The convolution kernel.
171 bias: The bias added to the result of convolution (if given)
172 stride: Stride of the 1D convolution operation. Default: 1
173 padding: Size of the paddings added to the input on both sides of its
174 spatial dimensions. Only zero-padding is supported. Default: 0
175 dilation: Dilation of the 1D convolution operation. Default: 1
176 groups: number of groups to divide input and output channels into,
177 so as to perform a "grouped convolution". When ``groups`` is not 1,
178 ``in_channels`` and ``out_channels`` must be divisible by ``groups``,
179 and the shape of weight should be ``(groups, out_channel // groups,
180 in_channels // groups, kernel_size)``. Default: 1
181 conv_mode: Supports 'cross_correlation'. Default:
182 'cross_correlation'.
183 compute_mode: When set to 'default', no special requirements will be
184 placed on the precision of intermediate results. When set to 'float32',
185 float32 would be used for accumulator and intermediate result, but only
186 effective when input and output are of float16 dtype.
187 """
188 assert (
189 conv_mode.lower() == "cross_correlation"
190 or conv_mode.name == "CROSS_CORRELATION"
191 )
192 assert compute_mode.lower() == "default" or compute_mode.name == "DEFAULT"
193 assert inp.ndim == 3, "the input dimension of conv1d should be 3"
194 assert weight.ndim == 3, "the weight dimension of conv1d should be 3"
195 if bias is not None:
196 assert bias.ndim == 3, "the bias dimension of conv1d should be 3"
197
198 stride_h = stride
199 pad_h = padding
200 dilate_h = dilation
201
202 compute_mode = _config._get_actual_op_param(compute_mode, _config.__compute_mode)
203 sparse_type = "dense" if groups == 1 else "group"
204 op = builtin.Convolution(
205 stride_h=stride_h,
206 stride_w=1,
207 pad_h=pad_h,
208 pad_w=0,
209 dilate_h=dilate_h,
210 dilate_w=1,

Callers 1

calc_convMethod · 0.85

Calls 3

cast_tensorsFunction · 0.85
get_execution_strategyFunction · 0.70
applyFunction · 0.50

Tested by

no test coverage detected