# Buggy code
def forward(self, x):
    return super().forward(x)


# Traceback (RuntimeError)
Using cache found in /home/vlad/.cache/torch/hub/pytorch_fairseq_master
Loading codes from /home/vlad/.cache/torch/pytorch_fairseq/0695ef328ddefcb8cbcfabc3196182f59c0e41e0468b10cc0db2ae9c91881fcc.bb1be17de4233e13870bd7d6065bfdb03fca0a51dd0f5d0b7edf5c188eda71f1/bpecodes ...
Read 30000 codes from the codes file.
Traceback (most recent call last):
File "/home/vlad/Documents/coding/experiments/paper-analyzer-Tretyak_Internship/papers/experiments/scientific_generation/scripts/paraphrase.py", line 46, in <module>
en2de.translate(['hello'])
File "/home/vlad/.cache/torch/hub/pytorch_fairseq_master/fairseq/hub_utils.py", line 126, in translate
return self.sample(sentences, beam, verbose, **kwargs)
File "/home/vlad/.cache/torch/hub/pytorch_fairseq_master/fairseq/hub_utils.py", line 132, in sample
batched_hypos = self.generate(tokenized_sentences, beam, verbose, **kwargs)
File "/home/vlad/.cache/torch/hub/pytorch_fairseq_master/fairseq/hub_utils.py", line 165, in generate
translations = self.task.inference_step(generator, self.models, batch)
File "/home/vlad/.cache/torch/hub/pytorch_fairseq_master/fairseq/tasks/fairseq_task.py", line 351, in inference_step
return generator.generate(models, sample, prefix_tokens=prefix_tokens)
File "/home/vlad/Documents/envs/p3.6/lib/python3.6/site-packages/torch/autograd/grad_mode.py", line 49, in decorate_no_grad
return func(*args, **kwargs)
File "/home/vlad/.cache/torch/hub/pytorch_fairseq_master/fairseq/sequence_generator.py", line 93, in generate
return self._generate(model, sample, **kwargs)
File "/home/vlad/Documents/envs/p3.6/lib/python3.6/site-packages/torch/autograd/grad_mode.py", line 49, in decorate_no_grad
return func(*args, **kwargs)
File "/home/vlad/.cache/torch/hub/pytorch_fairseq_master/fairseq/sequence_generator.py", line 276, in _generate
tokens[:, :step + 1], encoder_outs, temperature=self.temperature,
File "/home/vlad/Documents/envs/p3.6/lib/python3.6/site-packages/torch/autograd/grad_mode.py", line 49, in decorate_no_grad
return func(*args, **kwargs)
File "/home/vlad/.cache/torch/hub/pytorch_fairseq_master/fairseq/sequence_generator.py", line 549, in forward_decoder
temperature=temperature,
File "/home/vlad/.cache/torch/hub/pytorch_fairseq_master/fairseq/sequence_generator.py", line 568, in _decode_one
tokens, encoder_out=encoder_out, incremental_state=self.incremental_states[model],
File "/home/vlad/.cache/torch/hub/pytorch_fairseq_master/fairseq/models/fairseq_model.py", line 274, in forward_decoder
return self.decoder(prev_output_tokens, **kwargs)
File "/home/vlad/Documents/envs/p3.6/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in __call__
result = self.forward(*input, **kwargs)
File "/home/vlad/.cache/torch/hub/pytorch_fairseq_master/fairseq/models/transformer.py", line 704, in forward
alignment_heads=alignment_heads,
File "/home/vlad/.cache/torch/hub/pytorch_fairseq_master/fairseq/models/transformer.py", line 807, in extract_features
need_head_weights=bool((idx == alignment_layer)),
File "/home/vlad/Documents/envs/p3.6/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in __call__
result = self.forward(*input, **kwargs)
File "/home/vlad/.cache/torch/hub/pytorch_fairseq_master/fairseq/modules/transformer_layer.py", line 297, in forward
need_head_weights=need_head_weights,
File "/home/vlad/Documents/envs/p3.6/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in __call__
result = self.forward(*input, **kwargs)
File "/home/vlad/.cache/torch/hub/pytorch_fairseq_master/fairseq/modules/multihead_attention.py", line 325, in forward
key_padding_mask.unsqueeze(1).unsqueeze(2).to(torch.bool), float("-inf")
RuntimeError: arguments are located on different GPUs at /pytorch/aten/src/THC/generic/THCTensorMasked.cu:28

Process finished with exit code 1

# Fixed code
def forward(self, x):
    with torch.cuda.device(x.device):
        return super().forward(x)