Repository: pytorch
Issue: F.pad will accept 0 and negative values as parameter
Labels: module: nn,module: error checking,triaged,module: padding

### 🐛 Describe the bug

When using interfaces with certain extension functionalities(ZeroPad, ConstantPad, ReflectionPad, ReplicationPad, no matter 1d, 2d, or 3d), setting padding to 0 will result in the input tensor being output as it is. 

##### An example for zero padding here:

run:
```
p = nn.ConstantPad2d(padding=0, value=1.0)
x = torch.randn(3,3,3,3)
print(p(x).shape)
```
output:
```
torch.Size([3, 3, 3, 3])
```
The performance of 0 padding in these four padding layers will be the same.



Also, when padding is set to a negative value, the functionality of the interface will behave as a "**narrowing**" operation on the input tensor. 

##### An example for negative padding here:
run:
```
p = nn.ConstantPad2d(padding=-1, value=1.0)
x = torch.randn(3,3,3,3)
print(p(x).shape)
```
output:
```
torch.Size([3, 3, 1, 1])
```

Furthermore, when this "narrowing" operation is insufficient to be applied on the input tensor, it will lead to an error in a deeper place. 

As below:

run:
```
p_f = nn.ConstantPad2d(padding=-5, value=1.0)
x = torch.randn(3,3,3,3)
print(p_f(x).shape)
```
error message:
```
Traceback (most recent call last):
  File "D:\PythonProjects\venv\lib\site-packages\IPython\core\interactiveshell.py", line 3508, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-12-5f158586f13d>", line 1, in <module>
    print(p_f(x).shape)
  File "D:\PythonProjects\venv\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "D:\PythonProjects\venv\lib\site-packages\torch\nn\modules\padding.py", line 25, in forward
    return F.pad(input, self.padding, 'constant', self.value)
RuntimeError: narrow(): length must be non-negative.

```


This performance appears in several interfaces(4 Pad layers and there 1~3d) because they all call F.pad, and F.pad does not reject padding=0 or negative values. 


### Versions

PS D:\PythonProjects\venv\Lib\site-packages\torch\utils> python collect_env.py
Collecting environment information...
PyTorch version: 2.0.1+cu117
Is debug build: False
CUDA used to build PyTorch: 11.7
ROCM used to build PyTorch: N/A

OS: Microsoft Windows 11 家庭中文版
GCC version: Could not collect
Clang version: Could not collect
CMake version: Could not collect
Libc version: N/A

Python version: 3.10.11 (tags/v3.10.11:7d4cc5a, Apr  5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)] (64-bit runtime)
Python platform: Windows-10-10.0.22621-SP0
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 4070 Laptop GPU
Nvidia driver version: 532.03
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture=9
CurrentClockSpeed=2200
DeviceID=CPU0
Family=207
L2CacheSize=16384
L2CacheSpeed=
Manufacturer=GenuineIntel
MaxClockSpeed=2200
Name=13th Gen Intel(R) Core(TM) i9-13900HX
ProcessorType=3
Revision=

Versions of relevant libraries:
[pip3] numpy==1.24.3
[pip3] torch==2.0.1+cu117
[pip3] torchaudio==2.0.2+cu117
[pip3] torchvision==0.15.2+cu117
[conda] Could not collect

cc @albanD @mruberry @jbschlosser @walterddr @mikaylagawarecki @malfet