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

Using bert-base-chinese causes CUDA error: device-side assert triggered #129

Open
hinneslung opened this issue Jun 27, 2020 · 1 comment

Comments

@hinneslung
Copy link

hinneslung commented Jun 27, 2020

I am following the
Text Classification of MultiNLI Sentences using BERT notebook to interpret BERT classification work. When I changed the line LANGUAGE = Language.ENGLISH to LANGUAGE = Language.CHINESE, indicating to use the bert-base-chinese pre-trained model, the following error occured:

interpreter_unified.explain_local('', 'fiction')
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
~/Projects/interpret-text/notebooks/text_classification/unified_info_explainer_sample.py in 
----> 1 interpreter_unified.explain_local('', 'fiction')

~/miniconda3/envs/interpret_gpu/lib/python3.7/site-packages/interpret_text/experimental/unified_information.py in explain_local(self, X, y, name, num_iteration)
     95         X = _validate_X(X)
     96 
---> 97         embedded_input, parsed_sentence = _get_single_embedding(self.model, X, self.device)
     98         self.input_embeddings = embedded_input
     99         self.parsed_sentence = parsed_sentence

~/miniconda3/envs/interpret_gpu/lib/python3.7/site-packages/interpret_text/experimental/common/utils_unified.py in _get_single_embedding(model, text, device)
     33     words = [BertTokens.CLS] + tokenizer.tokenize(text) + [BertTokens.SEP]
     34     tokenized_ids = tokenizer.convert_tokens_to_ids(words)
---> 35     token_tensor = torch.tensor([tokenized_ids], device=device)
     36     embedding = model.bert.embeddings(token_tensor)[0]
     37     return embedding, words

I tried with the original dataset as used in the example notebook, and also tried with my own dataset with Chinese texts. Both resulted in the above error. There was no issue when using multilingual model.

@newman1234
Copy link

newman1234 commented Nov 16, 2020

it may be vocal size which not matches embedding shape.
you can try to modify raw unified_information.py as below.

def explain_local(...)
       # ...
       if self.regular is None:
            assert self.train_dataset is not None, "Training dataset is required"

            # sample the training dataset
            if len(self.train_dataset) <= self.max_points:
                sampled_train_dataset = self.train_dataset
            else:
                sampled_train_dataset = random.sample(self.train_dataset, k=self.max_points)

            training_embeddings = make_bert_embeddings(
                # ======================================
                # MODIFIED HERE, LANGUAGE param are now added
                # ======================================
                sampled_train_dataset, self.model, self.device, LANGUAGE=Language.CHINESE  
            )
       # ...

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

No branches or pull requests

2 participants