又比如:
./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
原因:
- python3.7已经移除了async关键字,而用non_blocking代替。(导致apache-airflow也出了问题)
-
cuda()
本身也没有async
. 构造函数如下:cuda(device=None, non_blocking=False) → Tensor
参考:
https://github.com/facebookresearch/ParlAI/issues/1141
**kwargs: For compatibility, may contain the key ``async`` in place of the ``non_blocking`` argument. The ``async`` arg is deprecated. |
解决办法:
直接用cuda()
- 用
async_ 代替
- 用non_blocking代替。ps:两个关键字(
device
andnon_blocking
)可以用来调用cuda( ) ,device是选取显卡序列号的。
-
non_blocking
(bool):
IfTrue
and the source is in pinned memory, the copy will be asynchronous with respect to the host. Otherwise, the argument has no effect. Default:False
.- 如果为True且源位于锁定内存中,则副本将与主机异步。 否则,参数无效。 默认值:False。Always good to take a look at the Documentation:
- 更新 Pipenv。
pip install pipenv
https://github.com/quark0/darts/pull/25
https://pytorch.org/docs/stable/tensors.html#torch.Tensor.cuda