-
Notifications
You must be signed in to change notification settings - Fork 38
exception guarding cuda extension import #71
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
base: main
Are you sure you want to change the base?
Conversation
@@ -459,7 +501,13 @@ def _generate(self, | |||
bsz = input_size[0] | |||
src_len = input_size[1] | |||
beam_size = self.beam_size | |||
self.no_repeat_ngram_op = NGramRepeatBlock() | |||
cuda_ngram_op_import = True |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log warning msg
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.