exception guarding cuda extension import#71
Open
NickNickGo wants to merge 1 commit intomicrosoft:mainfrom
Open
exception guarding cuda extension import#71NickNickGo wants to merge 1 commit intomicrosoft:mainfrom
NickNickGo wants to merge 1 commit intomicrosoft:mainfrom
Conversation
JiushengChen
approved these changes
Dec 15, 2020
| src_len = input_size[1] | ||
| beam_size = self.beam_size | ||
| self.no_repeat_ngram_op = NGramRepeatBlock() | ||
| cuda_ngram_op_import = True |
Contributor
There was a problem hiding this comment.
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.
Contributor
There was a problem hiding this comment.
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 |
| from fastseq.ops.ngram_repeat_block import NGramRepeatBlock | ||
| self.no_repeat_ngram_op = NGramRepeatBlock() | ||
| except: | ||
| self.cuda_ngram_op_import = False |
yuyan2do
approved these changes
Dec 18, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.