Repository: facebookresearch/ParlAI

Issue:
Shift from 'async' to 'non_blocking' in cuda
__async__ is a reserved word in Python 3.7 so cuda is deprecating the function parameter __async__ in favor of __non_blocking__.

https://github.com/pytorch/pytorch/blob/4d28b65fb8978f1c34765d56f18c07042e70a43a/torch/_utils.py#L20-L21


[flake8](http://flake8.pycqa.org) testing of https://github.com/facebookresearch/ParlAI on Python 3.7.0

$ __flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics__
```
./projects/personachat/persona_seq2seq.py:2220:43: E999 SyntaxError: invalid syntax
                    self.zs.copy_(zs, async=True)
                                          ^
./parlai/agents/vsepp_caption/vsepp_caption.py:160:38: E999 SyntaxError: invalid syntax
            images = images.cuda(async=True)
                                     ^
./parlai/agents/drqa/model.py:89:43: E999 SyntaxError: invalid syntax
            inputs = [Variable(e.cuda(async=True)) for e in ex[:5]]
                                          ^
3     E999 SyntaxError: invalid syntax
3
```



Discussion:
test our product and tell friends

Resolving patch:
diff --git a/parlai/agents/drqa/model.py b/parlai/agents/drqa/model.py
--- a/parlai/agents/drqa/model.py
+++ b/parlai/agents/drqa/model.py
@@ -88,9 +88,9 @@ def update(self, ex):
 
         # Transfer to GPU
         if self.opt['cuda']:
-            inputs = [Variable(e.cuda(async=True)) for e in ex[:5]]
-            target_s = Variable(ex[5].cuda(async=True))
-            target_e = Variable(ex[6].cuda(async=True))
+            inputs = [Variable(e.cuda(non_blocking=True)) for e in ex[:5]]
+            target_s = Variable(ex[5].cuda(non_blocking=True))
+            target_e = Variable(ex[6].cuda(non_blocking=True))
         else:
             inputs = [Variable(e) for e in ex[:5]]
             target_s = Variable(ex[5])
@@ -124,7 +124,7 @@ def predict(self, ex):
 
         # Transfer to GPU
         if self.opt['cuda']:
-            inputs = [Variable(e.cuda(async=True), volatile=True)
+            inputs = [Variable(e.cuda(non_blocking=True), volatile=True)
                       for e in ex[:5]]
         else:
             inputs = [Variable(e, volatile=True) for e in ex[:5]]
diff --git a/parlai/agents/vsepp_caption/vsepp_caption.py b/parlai/agents/vsepp_caption/vsepp_caption.py
--- a/parlai/agents/vsepp_caption/vsepp_caption.py
+++ b/parlai/agents/vsepp_caption/vsepp_caption.py
@@ -159,7 +159,7 @@ def batchify(self, *args, **kwargs):
     def train_step(self, batch):
         images = torch.stack([self.transform(img) for img in batch.image])
         if self.use_cuda:
-            images = images.cuda(async=True)
+            images = images.cuda(non_blocking=True)
 
         text_lengths = torch.LongTensor(batch.label_lengths)
         if self.use_cuda:
@@ -181,7 +181,7 @@ def train_step(self, batch):
     def eval_step(self, batch):
         images = torch.stack([self.transform(img) for img in batch.image])
         if self.use_cuda:
-            images = images.cuda(async=True)
+            images = images.cuda(non_blocking=True)
 
         # Need to collate then sort the captions by length
         cands = [self.candidate_helper(label_cands_vec, label_cands, self.mode == 'test')
diff --git a/projects/personachat/persona_seq2seq.py b/projects/personachat/persona_seq2seq.py
--- a/projects/personachat/persona_seq2seq.py
+++ b/projects/personachat/persona_seq2seq.py
@@ -2219,7 +2219,7 @@ def valid(obs):
                 if self.use_cuda:
                     # copy to gpu
                     self.zs.resize_(zs.size())
-                    self.zs.copy_(zs, async=True)
+                    self.zs.copy_(zs, non_blocking=True)
                     zs = Variable(self.zs)
                 else:
                     zs = Variable(zs)


Test patch: