Repository: pytorch
Issue: checkpoint_sequential breaks backpropagation
Labels: module: checkpoint,module: autograd,triaged

## 🐛 Bug

checkpoint_sequential breaks backpropagation when applied, making nn.Sequential models impossible to train.

## To Reproduce

Steps to reproduce the behavior:

```
torch.manual_seed(42)
input = torch.randn(1, 10)
label = torch.randn(1,1)
model = nn.Sequential(*[nn.Linear(10,10),nn.Linear(10,1)])
optimizer = optim.Adam(model.parameters())
weights_beforeTraining=list(model[0].parameters())[0][0].clone().detach().numpy()
weights_beforeTraining # -0.24962077, -0.14578427, -0.08929473

out = checkpoint_sequential(model,2,input)
#out = model(input) # bp works if I disable checkpointing or set input.requires_grad=True
criterion = nn.MSELoss()
loss = criterion(out, label)
loss.backward()   # Backprop
optimizer.step()  # update Weights
weights_afterTraining=list(model[0].parameters())[0][0].clone().detach().numpy() 
weights_afterTraining # -0.24962077, -0.14578427, -0.08929473 
sum(weights_beforeTraining != weights_afterTraining) # 0, weights have not changed!
```


## Expected behavior

checkpoint_sequential should work without breaking backpropagation.  It should just work without hacks, like having to set input.requires_grad=True, which is an expensive calculation with a large memory footprint which may offset any gains offered by checkpointing in the first place.

## Environment
```
PyTorch version: 1.6.0
Is debug build: No
CUDA used to build PyTorch: 10.2

OS: Microsoft Windows 10 Enterprise
GCC version: Could not collect
CMake version: Could not collect

Python version: 3.6
Is CUDA available: No
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA

Versions of relevant libraries:
[pip] numpy==1.19.1
[pip] numpydoc==0.7.0
[pip] torch==1.6.0
[pip] torchvision==0.7.0
[conda] blas                      1.0                         mkl  
[conda] mkl                       2018.0.0             h36b65af_4  
[conda] mkl-service               1.1.2            py36h57e144c_4  
[conda] mkl_fft                   1.0.1            py36h452e1ab_0  
[conda] numpy                     1.19.1                    <pip>
[conda] numpy                     1.14.2           py36h5c71026_0  
[conda] numpydoc                  0.7.0            py36ha25429e_0  
[conda] pytorch-cpu               0.4.1           py36_cpuhe774522_1    pytorch
[conda] torch                     1.6.0                     <pip>
[conda] torchvision               0.7.0                     <pip>
```
But it also manifests on Ubuntu 16.04.4 LTS / Python 3.8.5 / PyTorch / 1.6.0 with CUDA 10.1

## Additional context
- The problem seems to be that the function tries to checkpoint the input which ordinarily does not have gradients (nor should it need to). This produces the warning 
> "None of the inputs have requires_grad=True. Gradients will be None"

- but then it proceeds without further errors. The memory usage will be nice and low as well, but that is because backprop won't reach back to update the weights and hence the model cannot be fully trained.  There are many tutorials that advocate the usage of checkpoint_sequential, but in its current form this will lead naive researchers to believe that they have saved on memory, not realizing that their model is actually broken.

- The fix should be relatively easy, if the checkpoint_sequential was smart enough to realise not to try to checkpoint the input?


cc @ezyang @SsnL @albanD @zou3519 @gqchen