The mask inversion changed in the new pytorch version:
1 - (torch.tensor([1, 2, 3]) < torch.tensor([3, 1, 2]))
RuntimeError: Subtraction, the-operator, with a bool tensor is not supported.
If you are trying to invert a mask, use the~orbitwise_not()operator instead.
~(torch.tensor([1, 2, 3]) < torch.tensor([3, 1, 2]))
tensor([False, True, True])
It seems that this change leads to a runtime error:
Traceback (most recent call last):
File "translate.py", line 48, in <module>
main(opt)
File "translate.py", line 32, in main
attn_debug=opt.attn_debug
File "/home/kalle/workspaces/openNMT/OpenNMT-py-master/onmt/translate/translator.py", line 330, in translate
batch, data.src_vocabs, attn_debug
File "/home/kalle/workspaces/openNMT/OpenNMT-py-master/onmt/translate/translator.py", line 523, in translate_batch
return_attention=attn_debug or self.replace_unk)
File "/home/kalle/workspaces/openNMT/OpenNMT-py-master/onmt/translate/translator.py", line 672, in _translate_batch
batch_offset=beam._batch_offset)
File "/home/kalle/workspaces/openNMT/OpenNMT-py-master/onmt/translate/translator.py", line 561, in _decode_and_generate
decoder_in, memory_bank, memory_lengths=memory_lengths, step=step
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 547, in __call__
result = self.forward(*input, **kwargs)
File "/home/kalle/workspaces/openNMT/OpenNMT-py-master/onmt/decoders/decoder.py", line 213, in forward
tgt, memory_bank, memory_lengths=memory_lengths)
File "/home/kalle/workspaces/openNMT/OpenNMT-py-master/onmt/decoders/decoder.py", line 395, in _run_forward_pass
memory_lengths=memory_lengths)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 547, in __call__
result = self.forward(*input, **kwargs)
File "/home/kalle/workspaces/openNMT/OpenNMT-py-master/onmt/modules/global_attention.py", line 183, in forward
align.masked_fill_(1 - mask, -float('inf'))
File "/usr/local/lib/python3.6/dist-packages/torch/tensor.py", line 325, in __rsub__
return _C._VariableFunctions.rsub(self, other)
RuntimeError: Subtraction, the `-` operator, with a bool tensor is not supported. If you are trying to invert a mask, use the `~` or `bitwise_not()` operator instead.
Hi @Bachstelze
Thanks for pointing this one out. There are a few other things that need to be adapted to support pytorch release 1.2. You may remain with version 1.1.0 of pytorch until those are fixed.
i know the solution.
please visit pytorch 1.2.0 release documents .
Version 1.2:
>>> 1 - (torch.tensor([1, 2, 3]) < torch.tensor([3, 1, 2]))
RuntimeError: Subtraction, the `-` operator, with a bool tensor is not supported.
If you are trying to invert a mask, use the `~` or `bitwise_not()` operator instead.
>>> ~(torch.tensor([1, 2, 3]) < torch.tensor([3, 1, 2]))
tensor([False, True, True])
align.masked_fill_(1 - mask, -float('inf'))
simply change it.
align.masked_fill_(~mask, -float('inf'))
@MuruganR96 pending PR #1527 is already including this change. Should be merged soon.
Most helpful comment
i know the solution.
please visit pytorch 1.2.0 release documents .
align.masked_fill_(1 - mask, -float('inf'))simply change it.
align.masked_fill_(~mask, -float('inf'))