-
Notifications
You must be signed in to change notification settings - Fork 100
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
[Bug] Random Segmentation Faults During OneDiff (OneFlow) Inference in Multi-threaded Python Program #1080
Comments
Additional Debugging When running the test program with
The captured stack trace is as follows:
This reveals that the Python memory allocator is being called without holding the GIL. |
Hi @yingchingl Were you able to solve it? Would you mind kindly to give some advice about it? |
@strint Would you mind to give a loot at the issue ?
@hjchen2 Would you mind to give a look at the issue |
Hi @bigmover , |
Please don't try to use cuda/python/onediff with Multi-thread because it's usually blocked by the Python GIL or not thread-safe. Using multi-process is recommended. |
GOT IT! Thank you! |
@strint OK Thank you for your kindly reply! Onediff have |
Yes, we are using a customized flash attention. Compileing UNet won't use more GPU memory, but compiling VAE does because VAE has a large output tensor. oneflow compile share model weight memory with torch but doesn't share output tensor memory with torch. |
Hi @bigmover @yingchingl , I have the same problem, I want to ask if you have any solution or idea. |
Your current environment information
Collecting environment information...
PyTorch version: 2.1.1+cu118
Is debug build: False
CUDA used to build PyTorch: 11.8
ROCM used to build PyTorch: N/A
OneFlow version: path: ['/opt/conda/lib/python3.10/site-packages/oneflow'], version: 0.9.1.dev20240515+cu118, git_commit: ec7b682, cmake_build_type: Release, rdma: True, mlir: True, enterprise: False
Nexfort version: none
OneDiff version: 1.2.0.dev202407160130
OneDiffX version: 1.2.0.dev1
OS: Ubuntu 20.04.6 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Clang version: Could not collect
CMake version: version 3.28.1
Libc version: glibc-2.31
Python version: 3.10.13 (main, Sep 11 2023, 13:44:35) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.15.0-97-generic-x86_64-with-glibc2.31
Is CUDA available: True
CUDA runtime version: 11.8.89
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3090
Nvidia driver version: 535.161.07
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.9.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.9.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.9.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.9.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.9.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.9.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.9.0
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
Address sizes: 46 bits physical, 57 bits virtual
CPU(s): 112
On-line CPU(s) list: 0-111
Thread(s) per core: 2
Core(s) per socket: 28
Socket(s): 2
NUMA node(s): 2
Vendor ID: GenuineIntel
CPU family: 6
Model: 106
Model name: Intel(R) Xeon(R) Gold 6330 CPU @ 2.00GHz
Stepping: 6
CPU MHz: 800.000
CPU max MHz: 3100.0000
CPU min MHz: 800.0000
BogoMIPS: 4000.00
Virtualization: VT-x
L1d cache: 2.6 MiB
L1i cache: 1.8 MiB
L2 cache: 70 MiB
L3 cache: 84 MiB
NUMA node0 CPU(s): 0-27,56-83
NUMA node1 CPU(s): 28-55,84-111
Vulnerability Gather data sampling: Mitigation; Microcode
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 invpcid_single intel_ppin ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect wbnoinvd dtherm ida arat pln pts avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid fsrm md_clear pconfig flush_l1d arch_capabilities
Versions of relevant libraries:
[pip3] diffusers==0.21.0
[pip3] numpy==1.26.0
[pip3] onnx==1.15.0
[pip3] onnxruntime-gpu==1.17.0
[pip3] torch==2.1.1+cu118
[pip3] torchaudio==2.1.1+cu118
[pip3] torchelastic==0.2.2
[pip3] torchsde==0.2.6
[pip3] torchvision==0.16.1+cu118
[pip3] transformers==4.35.2
[pip3] triton==2.1.0
[conda] blas 1.0 mkl
[conda] ffmpeg 4.3 hf484d3e_0 pytorch
[conda] libjpeg-turbo 2.0.0 h9bf148f_0 pytorch
[conda] mkl 2023.1.0 h213fc3f_46343
[conda] mkl-service 2.4.0 py310h5eee18b_1
[conda] mkl_fft 1.3.8 py310h5eee18b_0
[conda] mkl_random 1.2.4 py310hdb19cb5_0
[conda] numpy 1.26.0 py310h5f9d8c6_0
[conda] numpy-base 1.26.0 py310hb5e798b_0
[conda] pytorch-cuda 11.8 h7e8668a_5 pytorch
[conda] pytorch-mutex 1.0 cuda pytorch
[conda] torch 2.1.1+cu118 pypi_0 pypi
[conda] torchaudio 2.1.1+cu118 pypi_0 pypi
[conda] torchelastic 0.2.2 pypi_0 pypi
[conda] torchsde 0.2.6 pypi_0 pypi
[conda] torchtriton 2.1.0 py310 pytorch
[conda] torchvision 0.16.1+cu118 pypi_0 pypi
🐛 Describe the bug
I'm experiencing random segmentation faults when using OneDiff to accelerate SDXL inference in a multi-threaded Python environment. The issue appears to be related to memory allocation and deallocation without properly handling the Python Global Interpreter Lock (GIL).
When the issue occurs, the command window outputs one of the following messages:
Since there isn't much information, I used GDB to debug and captured the following stack trace when the segmentation fault occurs:
The program consistently crashes in the
pymalloc_alloc
function, trying to access an invalid memory address.I suspect the issue may be related to the handling of the Python Global Interpreter Lock (GIL) during memory allocation and deallocation processes.
To verify this hypothesis, I've created a test program (
sdxl_onediff_test.py
) based on the examples of Diffusers and OneDiffX that simulates using OneFlow for accelerated inference while another thread performs Python memory allocation and deallocation:To reproduce:
python sdxl_onediff_test.py --compile_and_save
to compile and save the compiled pipe.python sdxl_onediff_test.py
to start the test.The segmentation fault typically occurs within a few seconds to minutes.
The text was updated successfully, but these errors were encountered: