Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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.

@@ -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
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