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

Limit input string to 512 characters to avoid CUDA crash #58

Open
ulf1 opened this issue Aug 30, 2022 · 1 comment
Open

Limit input string to 512 characters to avoid CUDA crash #58

ulf1 opened this issue Aug 30, 2022 · 1 comment

Comments

@ulf1
Copy link

ulf1 commented Aug 30, 2022

Problem

# If
assert len(sentence) > 512
# then
annotated = model_trankit(sentence, is_sent=True)
# result in CUDA error, e.g.
../aten/src/ATen/native/cuda/ScatterGatherKernel.cu:144: operator(): block: [19635,0,0], thread: [112,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.

Cause
XLM-Roberta can only process 512 characters.

Possible fix

ori_text = deepcopy(input)

Change

...

                ori_text = deepcopy(input)
                tagged_sent = self._posdep_sent(input)
...

to

...

                ori_text = deepcopy(input)
                ori_text = ori_text[:512]   # <<< TRIM STRING TO MAX 512
                tagged_sent = self._posdep_sent(input)
...
@ulf1
Copy link
Author

ulf1 commented Aug 30, 2022

A quick fix for other trankit users would be

annotated = model_trankit(sentence[:512], is_sent=True)

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

No branches or pull requests

1 participant