Repository: pytorch
Issue: Quantization fails when padding parameter given as string
Labels: oncall: quantization,low priority,triaged

### 🐛 Describe the bug

When applying quantization to a model having a convolutional layer (e.g. conv2d), setting the `padding` parameter as "valid" or "same" raises an error.

Code to replicate:
```python
class test_model(nn.Module):
    def __init__(self,):
        super().__init__()
        self.conv = nn.Conv1d(in_channels=1, 
                    out_channels=128, 
                    kernel_size=80, 
                    stride=4,
                    padding="valid")
        self.relu = nn.ReLU()
        self.bn = nn.BatchNorm1d(num_features=128)

    def forward(self, x):
        x = self.conv(x)
        x = self.relu(x)
        x = self.bn(x)
        return x
    
    
def calibrate(model):
    x = torch.rand(7, 1, 8000)
    with torch.no_grad():
        model(x)

# create model
myModel = test_model()
myModel.eval()

# calibrate model with random tensors
myModel.qconfig = torch.quantization.default_qconfig
torch.quantization.prepare(myModel, inplace=True)
calibrate(myModel)

# quantize model
qmodel = torch.quantization.convert(myModel, inplace=False)
```

Raises the following error
```
RuntimeError: quantized::conv1d_prepack() Expected a value of type 'List[int]' for argument 'padding' but instead found type 'str'.
Position: 3
Value: 'valid'
Declaration: quantized::conv1d_prepack(Tensor weight, Tensor? bias, int[] stride, int[] padding, int[] dilation, int groups) -> (__torch__.torch.classes.quantized.Conv2dPackedParamsBase)
Cast error details: Unable to cast Python instance to C++ type (compile in debug mode for details)
```
And Traceback:

```
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [41], in <module>
     35 calibrate(myModel)
     37 # quantize model
---> 38 qmodel = torch.quantization.convert(myModel, inplace=False)

File ~/.pyenv/versions/3.8.11/envs/torch-commands/lib/python3.8/site-packages/torch/ao/quantization/quantize.py:505, in convert(module, mapping, inplace, remove_qconfig, convert_custom_config_dict)
    503 if not inplace:
    504     module = copy.deepcopy(module)
--> 505 _convert(
    506     module, mapping, inplace=True,
    507     convert_custom_config_dict=convert_custom_config_dict)
    508 if remove_qconfig:
    509     _remove_qconfig(module)

File ~/.pyenv/versions/3.8.11/envs/torch-commands/lib/python3.8/site-packages/torch/ao/quantization/quantize.py:543, in _convert(module, mapping, inplace, convert_custom_config_dict)
    539     if not isinstance(mod, _FusedModule) and \
    540        type(mod) not in custom_module_class_mapping:
    541         _convert(mod, mapping, True,  # inplace
    542                  convert_custom_config_dict)
--> 543     reassign[name] = swap_module(mod, mapping, custom_module_class_mapping)
    545 for key, value in reassign.items():
    546     module._modules[key] = value

File ~/.pyenv/versions/3.8.11/envs/torch-commands/lib/python3.8/site-packages/torch/ao/quantization/quantize.py:568, in swap_module(mod, mapping, custom_module_class_mapping)
    566     swapped = True
    567 elif type(mod) in mapping:
--> 568     new_mod = mapping[type(mod)].from_float(mod)
    569     swapped = True
    571 if swapped:
    572     # Preserve module's pre forward hooks. They'll be called on quantized input

File ~/.pyenv/versions/3.8.11/envs/torch-commands/lib/python3.8/site-packages/torch/nn/quantized/modules/conv.py:370, in Conv1d.from_float(cls, mod)
    362 @classmethod
    363 def from_float(cls, mod):
    364     r"""Creates a quantized module from a float module or qparams_dict.
    365 
    366     Args:
    367         mod (Module): a float module, either produced by torch.ao.quantization
    368           utilities or provided by the user
    369     """
--> 370     return _ConvNd.from_float(cls, mod)

File ~/.pyenv/versions/3.8.11/envs/torch-commands/lib/python3.8/site-packages/torch/nn/quantized/modules/conv.py:238, in _ConvNd.from_float(cls, mod)
    236         mod = mod[0]
    237     weight_post_process = mod.qconfig.weight()
--> 238 return cls.get_qconv(mod, activation_post_process, weight_post_process)

File ~/.pyenv/versions/3.8.11/envs/torch-commands/lib/python3.8/site-packages/torch/nn/quantized/modules/conv.py:202, in _ConvNd.get_qconv(cls, mod, activation_post_process, weight_post_process)
    200 qweight = _quantize_weight(mod.weight.float(), weight_post_process)
    201 # the __init__ call used is the one from derived classes and not the one from _ConvNd
--> 202 qconv = cls(mod.in_channels, mod.out_channels, mod.kernel_size,
    203             mod.stride, mod.padding, mod.dilation, mod.groups,
    204             mod.bias is not None, mod.padding_mode)
    205 qconv.set_weight_bias(qweight, mod.bias)
    206 if activation_post_process is None or activation_post_process.dtype == torch.float:

File ~/.pyenv/versions/3.8.11/envs/torch-commands/lib/python3.8/site-packages/torch/nn/quantized/modules/conv.py:324, in Conv1d.__init__(self, in_channels, out_channels, kernel_size, stride, padding, dilation, groups, bias, padding_mode, device, dtype)
    320 dilation = _single(dilation)
    322 # Subclasses of _ConvNd needs to call _init rather than __init__. See
    323 # discussion on PR #49702
--> 324 super(Conv1d, self)._init(
    325     in_channels, out_channels, kernel_size, stride, padding, dilation,
    326     False, _single(0), groups, bias, padding_mode, **factory_kwargs)

File ~/.pyenv/versions/3.8.11/envs/torch-commands/lib/python3.8/site-packages/torch/nn/quantized/modules/conv.py:78, in _ConvNd._init(self, in_channels, out_channels, kernel_size, stride, padding, dilation, transposed, output_padding, groups, bias, padding_mode, device, dtype)
     70 qweight = torch._empty_affine_quantized(
     71     weight_shape + list(kernel_size),
     72     scale=1, zero_point=0, dtype=torch.qint8,
     73     **{k: v for k, v in factory_kwargs.items() if k != 'dtype'})
     74 bias_float = (
     75     torch.zeros(out_channels, dtype=torch.float,
     76                 **{k: v for k, v in factory_kwargs.items() if k != 'dtype'}) if bias else None)
---> 78 self.set_weight_bias(qweight, bias_float)
     79 self.scale = 1.0
     80 self.zero_point = 0

File ~/.pyenv/versions/3.8.11/envs/torch-commands/lib/python3.8/site-packages/torch/nn/quantized/modules/conv.py:333, in Conv1d.set_weight_bias(self, w, b)
    331 def set_weight_bias(self, w: torch.Tensor, b: Optional[torch.Tensor]) -> None:
    332     if self.padding_mode == 'zeros':
--> 333         self._packed_params = torch.ops.quantized.conv1d_prepack(
    334             w, b, self.stride, self.padding, self.dilation, self.groups)
    335     else:
    336         self._packed_params = torch.ops.quantized.conv1d_prepack(
    337             w, b, self.stride, _pair(0), self.dilation,
    338             self.groups)
```

### Versions

PyTorch version: 1.11.0
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: macOS 12.0.1 (x86_64)
GCC version: Could not collect
Clang version: 13.0.0 (clang-1300.0.29.3)
CMake version: version 3.22.1
Libc version: N/A

Python version: 3.8.11 (default, Jan 12 2022, 11:42:46)  [Clang 13.0.0 (clang-1300.0.29.3)] (64-bit runtime)
Python platform: macOS-12.0.1-x86_64-i386-64bit
Is CUDA available: False
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.21.5
[pip3] torch==1.11.0
[pip3] torchaudio==0.11.0
[pip3] torchvision==0.12.0
[conda] Could not collect

cc @jerryzh168 @jianyuh @raghuramank100 @jamesr66a @vkuzo @jgong5 @Xia-Weiwen @leslie-fang-intel