Repository navigation
fix: cap automatic thread counts by OMP_NUM_THREADS - #208
Merged
Merged
Conversation
num_threads=0 resolved to every available CPU and ignored the OpenMP thread limit. Since 0.8.0 defaults add() to 0, txtai's 0.7-style add(x) started an OpenMP worker team on macOS even though txtai sets OMP_NUM_THREADS=1 there. With Faiss and PyTorch loaded, each bundling its own libomp, starting those workers crashes (OMP Error #179, then SIGSEGV). Resolve 0 to min(available CPUs, omp_get_max_threads()) like Faiss does; explicit positive requests are still capped only by the CPU count. Document the limit and the macOS mixed-runtime caveat. Fixes #207
Bump the version to 0.8.1, update install pins and version text, and add the 0.8.1 release notes with their navigation entry and a README news entry. The Python sample README now requires 0.8.1 because the clustering example uses the new _default_thread_count helper.
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.
Summary
Fixes #207 and prepares the 0.8.1 release (txtai's macOS CI segfaults with 0.8.0, neuml/txtai#1494).
Cause. 0.8.0 changed the default of
addtonum_threads=0, and0resolved to every available CPU, ignoring the OpenMP thread limit. txtai's 0.7-styleadd(embeddings)therefore started an OpenMP worker team. On macOS, Faiss, PyTorch and rabitqlib each bundle their own libomp. When Faiss and PyTorch are loaded in the same process, starting rabitqlib's workers crashes withOMP: Error #179: Function pthread_mutex_init failed, followed by SIGSEGV. txtai already setsOMP_NUM_THREADS=1on macOS for Faiss, but rabitqlib ignored it.Change.
num_threads=0now resolves tomin(available CPUs, omp_get_max_threads()), which respectsOMP_NUM_THREADSandomp_set_num_threads, like Faiss. This happens in a new compileddefault_threads()called byresolve_num_threads(0), so the installedutils/tools.hppdoes not pull inomp.h.OMP_NUM_THREADS, defaults still use every available CPU._default_thread_countfor tests and the clustering example, next to_available_cpu_count..pyiand runtime kept in sync).No API signature, saved-index format or dependency changes.
Release (second commit,
chore(release): prepare v0.8.1).pyproject.tomlandCMakeLists.txt._default_thread_count.docs/docs/releases/0.8.1.mdwith its navigation entry, and a README news entry.Merging this into
maintriggers the automatic release: onceTestandPython Wheelsucceed for the merge commit,Release wheelstagsv0.8.1, publishes to PyPI and creates the GitHub Release.Testing
Local (Linux x86-64, GCC 14, native optimization OFF):
./scripts/check-format.sh; full./scripts/check-tidy.sh(clang-tidy 23): passOMP_NUM_THREADS=2 ctest --no-tests=error: 486 pass, 1 skipped (OpenMP binding test, not applicable on this runtime). The newThreadCount.AutomaticRequestsRespectOpenMpThreadLimitand the updated assertions fail against the 0.8.0 resolution (96 instead of 1 or 2).pytest tests/python: 976 passed, 18 skipped (C++ example binaries not built; ARM64 and macOS wheel-only tests). Editor, mypy and Pyright checks: pass.check-python.sh: pass.mkdocs build --strict: pass.macOS arm64 (GitHub macos-15, temporary branch since deleted). A cp311 wheel was built with the release cibuildwheel config, including bundled libomp. Then txtai e5d8d43 was installed as its macOS CI does, and
unittest discover -k testannwas run:IvfIndex.addduringtestRabitQOMP_NUM_THREADS=1; still crashes when the variable is unset. That case is documented: setOMP_NUM_THREADS=1or passnum_threads=1.mkdocs build --strict,git diff --check,python -m unittest discover -s .github/scripts -p 'test_*.py'(60 tests): passDownstream compatibility
Platform: Intel Xeon Gold 6418H, Ubuntu 22.04.5 (kernel 6.8.0), GCC 14.3. The candidate is a wheel built from
7c74258(this branch) withRABITQ_ENABLE_NATIVE_OPTIMIZATION=OFF.txtai
masterat379b5a3(its RaBitQ backend last changed in4d5e05f), Python 3.13, run in a temporary virtual environment:DeprecationWarningfrom txtai's 0.7-style calls (same as 0.8.0)This covers the backend's IVF and HNSW build, query, save and load, and IVF append and delete. The macOS arm64 run of txtai's
testannsuite is listed under Testing.zvec: not run yet. zvec builds core and FastScan with OpenMP off; this release changes only
src/utils/thread_count.cppin those components (a new function whose OpenMP query is compiled out when OpenMP is off) plus the version. CI's "Core and FastScan consumers (OpenMP OFF)" jobs on Linux, macOS and Windows build those components in zvec's configuration. zvec still needs the one-line test change from the 0.8.0 release (kbxsumq→g_kbxsumq).Not tested: zvec's own build and tests, txtai outside its ANN tests, and native-optimized builds downstream.