DataLoader worker is killed by signal: Segmentation fault

I am using 3090ti for training. I have chosen lmdb for reading the data. but during the training phase the dataloader is randomly interrupted by signals and generates segment errors.

Traceback (most recent call last):
  File "train.py", line 138, in <module>
    train()
  File "train.py", line 109, in train
    train_loss, train_top1_acc, train_topk_acc, global_iter = trainer.train()
  File "/home/chem/rsmiles/utils/train_utils.py", line 101, in train
    loss_token = self.criterion_tokens(pred_token_logit, gt_token_label)
  File "/home/chem/.miniconda3/envs/py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/chem/rsmiles/utils/loss_utils.py", line 24, in forward
    indices = torch.Tensor([[torch.arange(len(label))[i].item(),
  File "/home/chem/.miniconda3/envs/py38/lib/python3.8/site-packages/torch/utils/data/_utils/signal_handling.py", line 66, in handler
    _error_if_any_worker_fails()
RuntimeError: DataLoader worker (pid 21706) is killed by signal: Segmentation fault.

Sometimes the computer will just shut down.But the strange thing is that if I remove the code for training and iterate only the dataset, it will not generate any error. Also if I open two processes, one to iterate only the dataset and one to train, both processes will run normally.

Check the stacktrace via:

gdb --args python script.py args
...
run
...
bt

to narrow down which code causes the segfault.