LayoutLM SeqLabelling - Device Side Assert Triggered Error on Colab
Model I am using: LayoutLM
The problem arises when using the official example scripts
A clear and concise description of what the bug is: Repo cloned in colab when I run:
!python run_seq_labeling.py --data_dir '/content/gdrive/My Drive/unilm/layoutlm/examples/seq_labeling/data' \
--model_type layoutlm \
--output_dir '/content/gdrive/My Drive/unilm/layoutlm/examples/seq_labeling/output_dir' \
--model_name_or_path 'bert-base-uncased' \
--do_lower_case \
--max_seq_length 512 \
--do_predict \
--labels '/content/gdrive/My Drive/unilm/layoutlm/examples/seq_labeling/data/labels.txt' \
--fp16
on colab, I get the below error:
020-07-21 18:44:16.000263: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
Evaluating: 0% 0/7 [00:00<?, ?it/s]/pytorch/aten/src/THCUNN/ClassNLLCriterion.cu:108: cunn_ClassNLLCriterion_updateOutput_kernel: block: [0,0,0], thread: [1,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/ClassNLLCriterion.cu:108: cunn_ClassNLLCriterion_updateOutput_kernel: block: [0,0,0], thread: [3,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/ClassNLLCriterion.cu:108: cunn_ClassNLLCriterion_updateOutput_kernel: block: [0,0,0], thread: [5,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/ClassNLLCriterion.cu:108: cunn_ClassNLLCriterion_updateOutput_kernel: block: [0,0,0], thread: [7,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/ClassNLLCriterion.cu:108: cunn_ClassNLLCriterion_updateOutput_kernel: block: [0,0,0], thread: [9,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/ClassNLLCriterion.cu:108: cunn_ClassNLLCriterion_updateOutput_kernel: block: [0,0,0], thread: [10,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/ClassNLLCriterion.cu:108: cunn_ClassNLLCriterion_updateOutput_kernel: block: [0,0,0], thread: [13,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/ClassNLLCriterion.cu:108: cunn_ClassNLLCriterion_updateOutput_kernel: block: [0,0,0], thread: [17,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/ClassNLLCriterion.cu:108: cunn_ClassNLLCriterion_updateOutput_kernel: block: [0,0,0], thread: [18,0,0] Assertion `t >= 0 && t < n_classes` failed.
Evaluating: 0% 0/7 [00:00<?, ?it/s]
Traceback (most recent call last):
File "run_seq_labeling.py", line 816, in <module>
main()
File "run_seq_labeling.py", line 777, in main
args, model, tokenizer, labels, pad_token_label_id, mode="test"
File "run_seq_labeling.py", line 358, in evaluate
eval_loss += tmp_eval_loss.item()
RuntimeError: CUDA error: device-side assert triggered
To Reproduce Steps to reproduce the behavior:
- Clone the repo on colab
- run ./preprocess.sh
- run_seq_labeling.py as shown above
- Platform: google colab
- Python version: 3.6.9
- PyTorch version (GPU?): 1.5.1+cu101
check in your train_box.txt and dev_box.txt if any bounding box ( x0,y0,x1,y1)has a value greater than 1000. This is the common issue with this error.
I had the same error when I tried to do_predict on the pretrained model without fine-tuning on own data or FUNDS.
Shouldn't it throw an error in here (unilm/layoutlm/layoutlm/data/funsd.py)? I checked my dataset again and again. even if everything seems ok, I couldn't train due to the error.
@r000bin did you solve it?
class InputFeatures(object):
"""A single set of features of data."""
def __init__(
self,
input_ids,
input_mask,
segment_ids,
label_ids,
boxes,
actual_bboxes,
file_name,
page_size,
):
assert (
0 <= all(boxes) <= 1000
), "Error with input bbox ({}): the coordinate value is not between 0 and 1000".format(
boxes
)
self.input_ids = input_ids
self.input_mask = input_mask
self.segment_ids = segment_ids
self.label_ids = label_ids
self.boxes = boxes
self.actual_bboxes = actual_bboxes
self.file_name = file_name
self.page_size = page_size
@hchintada @r000bin @hasansalimkanmaz hay anyone has solved it?
check in your train_box.txt and dev_box.txt if any bounding box ( x0,y0,x1,y1)has a value greater than 1000. This is the common issue with this error.
Another possibility is negative value.
RuntimeError: CUDA error: device-side assert triggered while running seq_labeling.py for --do_predict
I have meet the same problem when I run the official example scripts.
python run_seq_labeling.py --data_dir data \
--model_type layoutlm \
--model_name_or_path pretrain_model/layoutlm-base-uncased \
--do_lower_case \
--max_seq_length 512 \
--do_eval \
--num_train_epochs 100.0 \
--logging_steps 10 \
--save_steps -1 \
--output_dir pretrain_model/layoutlm-base-uncased \
--labels data/labels.txt \
--per_gpu_train_batch_size 1 \
--per_gpu_eval_batch_size 1