question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CUDA error for long sentences?

See original GitHub issue

Hello, I am using Sentence Transformers, specifically distiluse-base-multilingual-cased, to compute semantic similarity for a list of sentences. I have been getting CUDA errors (last of which was CUDA error: CUBLAS_STATUS_ALLOC_FAILED when calling `cublasCreate(handle)` ) on a specific dataset, and after some investigation I realized this was due to a specific sentence of 2115 characters, which gets tokenized to 580 tokens. I am aware this is longer than the model max_seq_length (which I set to 512), but I was expecting the sentence to be automatically truncated to the maximum length with no error arising. Am I doing something wrong? I am running version 0.3.2 (transformers version 3.0.2).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
nreimerscommented, Sep 30, 2020

Try

model._first_module().max_seq_length = 509

Transformer models add up to 3 special tokens like [CLS] and/or [SEP] to your input sentence. So if your sentence is 512 tokens, and 3 special tokens are added, this would result in too many tokens passed to the transformers model.

0reactions
thesbycommented, Dec 10, 2020

I fix it by modify the Transformer class

    def tokenize(self, text: Union[str, List[str]]) -> List[int]:
        """
        Tokenizes a text and maps tokens to token-ids
        """
        if isinstance(text, str):
            return self.tokenizer.convert_tokens_to_ids(self.tokenizer.tokenize(text, max_length=self.max_seq_length-3))
        else:
            return [self.tokenizer.convert_tokens_to_ids(self.tokenizer.tokenize(t, max_length=self.max_seq_length-3)) for t in text]
Read more comments on GitHub >

github_iconTop Results From Across the Web

CUDA shared memory writes incur unexplainable long latency
The compiler is smart enough to determine that code which has no effect on a global or shared memory output is unneeded and...
Read more >
6.33. Data types used by CUDA Runtime
This error indicates that a grid launch did not occur because the kernel uses file-scoped textures which are unsupported by the device runtime....
Read more >
NVIDIA CUDA Library: cudaError
Common causes include dereferencing an invalid device pointer and accessing out of bounds shared memory. The device cannot be used until cudaThreadExit() is ......
Read more >
Frequently Asked Questions - 5KK73 GPU Assignment 2012
1.1.1 Check Whether GPU Is Busy Using CUDA Error Code; 1.1.2 Autostart CUDA Kernel When ... 1.4 What If the GPU Is Occupied...
Read more >
Cuda out of memory error - Intermediate - Hugging Face Forums
As @kkumari06 says, reduce batch size. I recommend restarting the kernel any time you get this error, to make sure you have a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found