Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytorch_fairseq.py - changed needed to run on GPU #9

Open
wjbyrne opened this issue Dec 6, 2020 · 3 comments
Open

pytorch_fairseq.py - changed needed to run on GPU #9

wjbyrne opened this issue Dec 6, 2020 · 3 comments

Comments

@wjbyrne
Copy link

wjbyrne commented Dec 6, 2020

Something like the following seems to be needed to run on GPU.

def predict_next(self):
"""Call the fairseq model."""
if self.use_cuda:
lprobs, _ = self.model.forward_decoder(
torch.cuda.LongTensor([self.consumed]), self.encoder_outs
)
lprobs[0, self.pad_id] = utils.NEG_INF
return np.array(lprobs[0].cpu())
else:
lprobs, _ = self.model.forward_decoder(
torch.LongTensor([self.consumed]), self.encoder_outs
)
lprobs[0, self.pad_id] = utils.NEG_INF
return np.array(lprobs[0])

@fstahlberg
Copy link
Contributor

is this code tested? If yes I'm happy to update the code, or you can also make a PR / push it directly if you like.

@wjbyrne
Copy link
Author

wjbyrne commented Dec 7, 2020 via email

@fstahlberg
Copy link
Contributor

fstahlberg commented Dec 7, 2020

that's enough testing for now - I'll have a go at updating it to 1.10.x in a few weeks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants