Skip to content

Replace async with non_blocking for Python 3.7#4999

Merged
soumith merged 6 commits intopytorch:masterfrom
goldsborough:async
Feb 2, 2018
Merged

Replace async with non_blocking for Python 3.7#4999
soumith merged 6 commits intopytorch:masterfrom
goldsborough:async

Conversation

@goldsborough
Copy link
Contributor

@goldsborough goldsborough commented Feb 1, 2018

Since async will become a keyword in Python 3.7, I replaced all occurences of the word async with non_blocking in our Python files. Proof:

$ find . -name '*.py' | xargs grep 'async\b'
./aten/src/ATen/copy_wrapper.py:if (async) {
./aten/src/ATen/copy_wrapper.py:if (async) {
./aten/src/ATen/copy_wrapper.py:Tensor & ${Type}::s_copy_(Tensor & self, const Tensor & src, bool async) const {
./torch/cuda/comm.py:    # TODO: if copying to CPU, allocate a pinned buffer, do async copies to it,

copy_wrapper.py generates C++ code, so the async will not be a problem. I also did not modify mentions of async in any other C++ files.

@ezyang @colesbury

Fixes #3431

@goldsborough goldsborough changed the title Replace async with non_blocking for Python 3.7 upgrade Replace async with non_blocking for Python 3.7 Feb 1, 2018
@ezyang
Copy link
Contributor

ezyang commented Feb 1, 2018

One question for the BC police: should we employ the following idiom to make legacy use of foo.cuda(async=True) keep working?

def _cuda(self, device=None, non_blocking=False, **kwargs):
    if 'async' in kwargs:
       assert not non_blocking
       non_blocking = kwargs['async']

EDIT: Actually, we should probably also check that async is the only member of kwargs, to guard against mispellings. dict.pop is a decent way to do this; then check if the dictionary is empty at the end.

@ezyang
Copy link
Contributor

ezyang commented Feb 1, 2018

Thanks for undoing the C++ changes! The rest looks good.

@goldsborough
Copy link
Contributor Author

Good point, I will add those compatibility fixes.

@goldsborough
Copy link
Contributor Author

There's some trouble with CUDA tests, I am investigating.

@goldsborough
Copy link
Contributor Author

@ezyang I had to rename async to non_blocking in torch/csrc/copy_utils.h because functions in there get wrapped and called from Python, which was causing errors. I then also renamed all other occurrences thereof in the C++ code so that:

  1. Naming is consistent,
  2. We don't run into similar trouble in the future.

I also don't know if some of the C++ code gets wrapped and exposed but just isn't called in the tests. Code also might get wrapped in the future, so I believe using non_blocking everywhere is better?

HANDLE_TH_ERRORS
static PythonArgParser parser({
"copy_(Tensor other, bool async=False)"
"copy_(Tensor other, bool non_blocking=False)"

This comment was marked as off-topic.

This comment was marked as off-topic.

torch/_utils.py Outdated
"""
if kwargs:
if len(kwargs) != 1 or 'async' not in kwargs:
raise ValueError("kwargs may only contain the key 'async'")

This comment was marked as off-topic.

This comment was marked as off-topic.

Copy link
Contributor

@ezyang ezyang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YES!

@goldsborough
Copy link
Contributor Author

goldsborough commented Feb 2, 2018

I believe onnx-fb-universe tests are currently broken, so @ezyang if you are happy, let's merge it (assuming other tests will not fail)

@soumith soumith merged commit 86fd5fd into pytorch:master Feb 2, 2018
cclauss pushed a commit to cclauss/pytorch that referenced this pull request Jul 27, 2018
Flake8 will produce different results on Python 2 and 3.  Python 3.7 has __async__ as a reserved word pytorch#4999.
facebook-github-bot pushed a commit that referenced this pull request Jul 27, 2018
Summary:
Flake8 will produce different results on Python 2 and 3.  Python 3.7 has __async__ as a reserved word #4999.
Pull Request resolved: #9953

Differential Revision: D9035415

Pulled By: soumith

fbshipit-source-id: 8a46e028a2e20a7e3f6d90137020268d65a7cc64
cclauss pushed a commit to cclauss/IBN-Net that referenced this pull request Jul 28, 2018
jramseyer pushed a commit to jramseyer/pytorch that referenced this pull request Jul 30, 2018
Summary:
Flake8 will produce different results on Python 2 and 3.  Python 3.7 has __async__ as a reserved word pytorch#4999.
Pull Request resolved: pytorch#9953

Differential Revision: D9035415

Pulled By: soumith

fbshipit-source-id: 8a46e028a2e20a7e3f6d90137020268d65a7cc64
goodlux pushed a commit to goodlux/pytorch that referenced this pull request Aug 15, 2018
Summary:
Flake8 will produce different results on Python 2 and 3.  Python 3.7 has __async__ as a reserved word pytorch#4999.
Pull Request resolved: pytorch#9953

Differential Revision: D9035415

Pulled By: soumith

fbshipit-source-id: 8a46e028a2e20a7e3f6d90137020268d65a7cc64
cclauss pushed a commit to cclauss/prometheus that referenced this pull request Sep 28, 2018
Fixes catalyst-team#3 The Dockerfiles are pip installing PyTorch=0.41 so this change is appropriate to match with pytorch/pytorch#4999
cclauss pushed a commit to cclauss/pytorch that referenced this pull request Sep 28, 2018
Modify the docs to match the changes made in pytorch#4999
facebook-github-bot pushed a commit that referenced this pull request Sep 28, 2018
Summary:
goldsborough Modify the docs to match the changes made in #4999
Pull Request resolved: #12158

Differential Revision: D10103964

Pulled By: SsnL

fbshipit-source-id: 1b8692da86aca1a52e8d2e6cea76a5ad1f71e058
cclauss pushed a commit to cclauss/IBD that referenced this pull request Nov 28, 2018
__async__ is now a reserved word in Python 3.7 and later.  To fix this pytorch/pytorch#4999 changed __cuda(async)__ to __cuda(non_blocking)__ so this PR tracks with that change.  That fix landed in PyTourch 0.4.1.
cclauss pushed a commit to cclauss/semantic-segmentation-pytorch that referenced this pull request Nov 30, 2018
Fixes CSAILVision#125 

__async__ is a reserved word in Python 3.7 and later.  To fix this pytorch/pytorch#4999 changed __cuda(async=True)__ to __cuda(non_blocking=True)__ so this PR tracks with that change which landed in PyTourch 0.4.1.
cclauss added a commit to cclauss/DenseDepth that referenced this pull request May 4, 2019
Fixes a __syntax error__ when running on Python >= 3.7 in alignment with pytorch/pytorch#4999

[flake8](http://flake8.pycqa.org) testing of https://github.com/ialhashim/DenseDepth on Python 3.7.1

$ __flake8 . --count --select=E9,F63,F72,F82 --show-source --statistics__
```
./PyTorch/train.py:58:78: E999 SyntaxError: invalid syntax
            depth = torch.autograd.Variable(sample_batched['depth'].cuda(async=True))
                                                                             ^
1     E999 SyntaxError: invalid syntax
1
```
__E901,E999,F821,F822,F823__ are the "_showstopper_" [flake8](http://flake8.pycqa.org) issues that can halt the runtime with a SyntaxError, NameError, etc. These 5 are different from most other flake8 issues which are merely "style violations" -- useful for readability but they do not effect runtime safety.
* F821: undefined name `name`
* F822: undefined name `name` in `__all__`
* F823: local variable name referenced before assignment
* E901: SyntaxError or IndentationError
* E999: SyntaxError -- failed to compile a file into an Abstract Syntax Tree
cclauss added a commit to cclauss/craves.ai that referenced this pull request Jun 16, 2019
__async__ is now a reserved word in Python 3.7 and later.  To fix this pytorch/pytorch#4999 changed __cuda(async=True)__ to __cuda(non_blocking=True)__ so this PR tracks with that change.  That fix landed in PyTourch 0.4.1.
cclauss added a commit to cclauss/BatchAI that referenced this pull request Jun 18, 2019
__async__ is a reserved word in Python 3.7 and later.  To fix this pytorch/pytorch#4999 changed __cuda(async=True)__ to __cuda(non_blocking=True)__ so this PR tracks with that change.  That fix landed in PyTourch 0.4.1.
cclauss added a commit to cclauss/OmniNet that referenced this pull request Jul 24, 2019
Using __async__ in this way is a Syntax Error in Python >= 3.7.  This change tracks with the changes made in pytorch/pytorch#4999
JPlin pushed a commit to JPlin/semantic-segmentation-pytorch that referenced this pull request Oct 31, 2019
Fixes CSAILVision#125 

__async__ is a reserved word in Python 3.7 and later.  To fix this pytorch/pytorch#4999 changed __cuda(async=True)__ to __cuda(non_blocking=True)__ so this PR tracks with that change which landed in PyTourch 0.4.1.
LovelyRobert added a commit to LovelyRobert/DenseDepth that referenced this pull request Apr 2, 2024
Fixes a __syntax error__ when running on Python >= 3.7 in alignment with pytorch/pytorch#4999

[flake8](http://flake8.pycqa.org) testing of https://github.com/ialhashim/DenseDepth on Python 3.7.1

$ __flake8 . --count --select=E9,F63,F72,F82 --show-source --statistics__
```
./PyTorch/train.py:58:78: E999 SyntaxError: invalid syntax
            depth = torch.autograd.Variable(sample_batched['depth'].cuda(async=True))
                                                                             ^
1     E999 SyntaxError: invalid syntax
1
```
__E901,E999,F821,F822,F823__ are the "_showstopper_" [flake8](http://flake8.pycqa.org) issues that can halt the runtime with a SyntaxError, NameError, etc. These 5 are different from most other flake8 issues which are merely "style violations" -- useful for readability but they do not effect runtime safety.
* F821: undefined name `name`
* F822: undefined name `name` in `__all__`
* F823: local variable name referenced before assignment
* E901: SyntaxError or IndentationError
* E999: SyntaxError -- failed to compile a file into an Abstract Syntax Tree
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants