Skip to content

Commit ce243b2

Browse files
committed
Acquire the GIL in lazy init_extension
Bindings declared with call_guard<gil_scoped_release> (e.g. fp8_transpose) can be the first transformer_engine_torch call in a process. init_extension() then runs py::module_::import without holding the GIL and segfaults inside PyImport_ImportModule. Reacquire the GIL inside the one-time initializer. Signed-off-by: zhihaow6 <zhihaow6@illinois.edu>
1 parent ea41e08 commit ce243b2

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

  • transformer_engine/pytorch/csrc/extensions

transformer_engine/pytorch/csrc/extensions/pybind.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ void init_grouped_tensor_extension() {
121121

122122
void init_extension() {
123123
std::call_once(extension_init_flag, []() {
124+
pybind11::gil_scoped_acquire gil;
124125
init_float8_extension();
125126
init_mxfp8_extension();
126127
init_float8blockwise_extension();

0 commit comments

Comments
 (0)