I am encountering a segmentation fault issue while using the Transformers library on my Nvidia Jetson Xavier NX device. The issue occurs when I attempt to encode text with the âparaphrase-mpnet-base-v2â model.
Here are some details about my setup:
Hardware: Nvidia Jetson Xavier NX (15GB GPU, 8GB RAM, Arch)
Software: Numpy version 1.26.0, Sentence Transformer version 2.2.2
The error message I am receiving is as follows:
Could you please provide guidance on how to resolve this issue? Any insights, tips, or information on potential solutions would be greatly appreciated.
TL;DR: Itâs most probably not related to Python or any Python package. The root of the problem may go deeper, like to the OS or even the hardware.
Iâve been occasionally getting segmentation fault errors when running transformers or scikit-learn scripts for over two years now and Iâve never been able to get to the bottom of it. From what Iâve been able to find online, getting segmentation faults from Python scripts is strange and has little to do with the Python-side of things. Itâs sometimes CUDA, sometimes the operating system or even the C-based infrastructure that Python uses. Iâve never bothered to update or reinstall the OS (Ubuntu 18.04 in my case) and segmentation fault from scikit-learn scripts tells me that the cause of the problem is probably not CUDA.
One consistent behavior in my system (and this would most probably be system-dependent) is when I run training or inference of a transformer model in CPU, either segmentation fault happens or the PC freezes and crashes. So, a rule of thumb for me is to run the model always on GPUs and CUDA. Maybe you can also try:
Segmentation fault also occasionally happens in my system even if I run the code on GPU but it doesnât consistently occur. If this doesnât work, I guess your best bet is to reinstall/update parts of the infrastructure. Since it is the CPU that fails in my case, I suspect it might even be a hardware-related defect.
Thank you for your previous suggestions. I tried both running the model on GPU and reduced batch_size, but unfortunately, the segmentation fault issue still persists.
Here are the debug logs I collected during program execution:
I also encountered the similar error and I found that itâs because of the incompatibility between transformers and conda environment, so I changed to a local Python environment and it works. Hope that would help!
I have managed to reproduce the segmentation-fault on a
Macbook air M1 with the current pytorch 2.4 and python 3.12
The segmentation-fault also occurs with python 3.9.
Always when loading the SentenceTransformer.
This also works if mps is avoided, i.e. device = âcpuâ.
The fact that the error does not occur may not mean that the bug
does not exist, but that the segment boundary is somewhere else.
This is probably not directly related to your issue but itâs similar and may help some people.
For me it was a memory issue, more specifically I was trying to allocate more memory to wsl than was available on my system.
If youâre using windows, you can go to your userâs root directory and find or create a â.wslconfigâ file and set the amount of ram you want to allocate â my system has 32gb and I was trying to allocate 16gb which worked fine until it didnât.
The directory for this can be accessed a number of ways, the most straight forward is running %UserProfile% in the windows menu. .wslconfig:
[wsl2]
memory=16GB
processors=2
Conclusion: I just restarted my computer to free up memory, though the alternative would be to reduce the memory allocation.