Skip to content

Conversation

@NickNickGo
Copy link
Contributor

This PR fixes the error in cuda extension import due to torch version change/ gpu change.
If import results in exception, cpu implementation for Ngram blocking is used.

src_len = input_size[1]
beam_size = self.beam_size
self.no_repeat_ngram_op = NGramRepeatBlock()
cuda_ngram_op_import = True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initialize no_repeat_ngram_op as None. In case of import exception, just pass. When no_repeat_ngram_op is None, use cpu code. Otherwise, use gpu code. So we don't need to create new var cuda_ngram_op_import.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we do this kind of checking (which kind of ops (e.g., cpu v.s. gpu) to use) inside the ops implementation? So that we do not need to do the similar check twice for fairseq and transformers. It will be easier for us to maintain and change the code in the future.

from fastseq.ops.ngram_repeat_block import NGramRepeatBlock
self.no_repeat_ngram_op = NGramRepeatBlock()
except:
cuda_ngram_op_import = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log warning msg

from fastseq.ops.ngram_repeat_block import NGramRepeatBlock
self.no_repeat_ngram_op = NGramRepeatBlock()
except:
self.cuda_ngram_op_import = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log warning msg

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

Successfully merging this pull request may close these issues.

4 participants