@@ -23,25 +23,35 @@ class ConformerConvolutionV1Config(ModelConfiguration):
2323 norm : Union [nn .Module , Callable [[torch .Tensor ], torch .Tensor ]]
2424 """normalization layer with input of shape [N,C,T]"""
2525
26+ def check_valid (self ):
27+ assert self .kernel_size % 2 == 1 , "ConformerConvolutionV1 only supports odd kernel sizes"
28+
29+ def __post_init__ (self ):
30+ super ().__post_init__ ()
31+ self .check_valid ()
32+
2633
2734class ConformerConvolutionV1 (nn .Module ):
2835 """
2936 Conformer convolution module.
3037 see also: https://github.com/espnet/espnet/blob/713e784c0815ebba2053131307db5f00af5159ea/espnet/nets/pytorch_backend/conformer/convolution.py#L13
38+
39+ Uses explicit padding for ONNX exportability, see:
40+ https://github.com/pytorch/pytorch/issues/68880
3141 """
3242
3343 def __init__ (self , model_cfg : ConformerConvolutionV1Config ):
3444 """
3545 :param model_cfg: model configuration for this module
3646 """
3747 super ().__init__ ()
38-
48+ model_cfg . check_valid ()
3949 self .pointwise_conv1 = nn .Linear (in_features = model_cfg .channels , out_features = 2 * model_cfg .channels )
4050 self .depthwise_conv = nn .Conv1d (
4151 in_channels = model_cfg .channels ,
4252 out_channels = model_cfg .channels ,
4353 kernel_size = model_cfg .kernel_size ,
44- padding = "same" ,
54+ padding = ( model_cfg . kernel_size - 1 ) // 2 ,
4555 groups = model_cfg .channels ,
4656 )
4757 self .pointwise_conv2 = nn .Linear (in_features = model_cfg .channels , out_features = model_cfg .channels )
0 commit comments