Allow None for checkpoint (#17969)
authorChoongwoo Han <cwhan.tunz@gmail.com>
Fri, 15 Mar 2019 14:33:31 +0000 (07:33 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 15 Mar 2019 14:38:41 +0000 (07:38 -0700)
commit40074d647c3116b3ae97bcbb65ff364038cc8ff9
treebe7363e356b81ebb169b87ac7318c2286b062a41
parent54ef852d7fb1aff2b43cc70207f5bae227158689
Allow None for checkpoint (#17969)

Summary:
Currently, we cannot run a checkpointed function with None argument.

```python
out = torch.utils.checkpoint.checkpoint(run_fn, input_var, None)
```

```
  File "/home/tunz/anaconda3/envs/torchdev/lib/python3.7/site-packages/torch/utils/checkpoint.py", line 14, in detach_variable
    x = inp.detach()
AttributeError: 'NoneType' object has no attribute 'detach'
```

This PR makes checkpoint function to safely handle None argument.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/17969

Differential Revision: D14475148

Pulled By: ezyang

fbshipit-source-id: 9afe9e9aac511a6df1e1620e9ac341536890d451
test/test_utils.py
torch/utils/checkpoint.py