Skip to content

Pybind11 free threading - #3158

Merged
davisking merged 3 commits into
masterfrom
pybind11-free-threading
Aug 10, 2026
Merged

Pybind11 free threading#3158
davisking merged 3 commits into
masterfrom
pybind11-free-threading

Conversation

@davisking

Copy link
Copy Markdown
Owner

Updates to pybind11 v3.0.4 and declares that the gil doesn't need to be locked when python calls into dlib.

This is a copy of #3155 but with some issues fixed

Some stuff wasn't actually thread safe:

  • Made the jitter RNG thread_local in tools/python/src/numpy_returns.cpp:97.
  • Serialized concurrent inference on the same face-recognition or CNN detector instance in tools/python/src/face_recognition.cpp:72 and tools/python/src/ cnn_face_detector.cpp:52.

I also pulled the official pybind11 release. What was here looks like one of their alpha snapshots. We should use an official pybind11 release
In particular, I replaced the mixed development pybind11 snapshot with exact upstream pybind11 v3.0.4, commit d03662f0984f652b60e7ddce53d3868002275197. Also added provenance/update instructions in dlib/external/pybind11/README.dlib.

Then some other minor related cleanup

yokomichikt and others added 2 commits July 29, 2026 10:54
Some stuff wasn't actually thread safe:
  - Made the jitter RNG thread_local in tools/python/src/numpy_returns.cpp:97.
  - Serialized concurrent inference on the same face-recognition or CNN detector instance in tools/python/src/face_recognition.cpp:72 and tools/python/src/ cnn_face_detector.cpp:52.

I also pulled the official pybind11 release.  What was here looks like one of their alpha snapshots.  We should use an official pybind11 release
In particular, I replaced the mixed development pybind11 snapshot with exact upstream pybind11 v3.0.4, commit d03662f0984f652b60e7ddce53d3868002275197. Also added provenance/update instructions in dlib/external/pybind11/README.dlib.

Then some other minor related cleanup
@davisking

Copy link
Copy Markdown
Owner Author

All the tests are passing now @yokomichikt. You want to try this out in your setup before I land it? I'm pretty sure it works but you want to give it a test drive first? :D

@yokomichikt

Copy link
Copy Markdown
Contributor

I've verified pybind11-free-threading branch and it works very well. Thanks for quick response.

@davisking

Copy link
Copy Markdown
Owner Author

No problem. Thanks for the PR :D

@davisking
davisking merged commit e5b7afe into master Aug 10, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants