joint-disfluency-detector-and-parser icon indicating copy to clipboard operation
joint-disfluency-detector-and-parser copied to clipboard

Calling cuda() with async results in SyntaxError

Open samarth12 opened this issue 4 years ago • 1 comments

The error occurs in this line.

if use_cuda:
    torch_t = torch.cuda
    def from_numpy(ndarray):
        return torch.from_numpy(ndarray).pin_memory().cuda(async=True)

The reason for this error is that async has become a reserved keyword from python 3.7. The cuda() constructor arguments have changed as well. This is how the new constructor looks -

cuda(device=None, non_blocking=False)

async=True can be replaced by non_blocking=True.

non_blocking (bool): If True 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.

samarth12 avatar Oct 25 '20 22:10 samarth12

The error occurs in this line.

if use_cuda:
    torch_t = torch.cuda
    def from_numpy(ndarray):
        return torch.from_numpy(ndarray).pin_memory().cuda(async=True)

The reason for this error is that async has become a reserved keyword from python 3.7. The cuda() constructor arguments have changed as well. This is how the new constructor looks -

cuda(device=None, non_blocking=False)

async=True can be replaced by non_blocking=True.

non_blocking (bool): If True 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.

Thanks! I updated parse_nk.py

pariajm avatar May 02 '21 06:05 pariajm