Fix forked test-suite segfaults (OpenMP after fork) - #4
Closed
sbryngelson wants to merge 1 commit into
Closed
sbryngelson wants to merge 1 commit into
sbryngelson wants to merge 1 commit into
Conversation
The two grad-vs-torch CIFAR tests segfaulted (SIGSEGV) only late in the full pytest run, while passing in isolation. The crash report pinned the fault entirely in libomp.dylib (__kmp_fork_barrier / __kmp_suspend_initialize_thread), not the ANE stack: --forked calls os.fork() in a process where numpy/torch have started an OpenMP worker-thread pool, fork() does not copy those threads, and the child's next OpenMP op (torch CPU autograd) faults on the broken pool. Setting OMP/MKL/OPENBLAS/ VECLIB thread counts to 1 in conftest (before any import) removes the pool, so the fork is safe. Full forked suite now 527 passed, 0 crashes (was 2 SIGSEGV).
Owner
Author
|
Folded into #3 (squashed into a single commit with the test/bench cleanup, per request). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The two grad-vs-torch CIFAR tests (
test_conv2d_pad_grad_matches_torch,test_group_norm_train_grad_matches_torch) crashed with SIGSEGV only late in the fullpytest tests/run, yet passed in isolation — so it looked environmental.Root cause
The macOS crash report pinned the faulting thread entirely in
libomp.dylib— not the ANE/Espresso/Metal stack:This is the classic OpenMP-thread-pool-after-
fork()failure:pytest-forkedcallsos.fork();fork()does not copy the worker threads, so the child inherits a pool with dead thread descriptors.libomp(__kmp_fork_barrier), dereferences a dead descriptor, and segfaults.That explains both symptoms: it only triggers once enough preceding tests have initialized the pool in the parent, and it's about threads, not test size (the tests are tiny).
Fix
Force OpenMP/BLAS single-threaded in
tests/conftest.py, before any test imports numpy/torch:With one OpenMP thread there is no worker pool to break across
fork(), so the child is fork-safe.setdefaultlets a caller override. These tiny test ops gain nothing from OpenMP parallelism, so there's no meaningful slowdown.Verification
527 passed in 497.78s, 0 crashes / 0 failures (was 2 SIGSEGV), with the env set only byconftest.py.Independent of the cleanup in #3.