Fix GIL crash in image generation pipelines on repeated generate() calls#3383
Conversation
7ad558a to
656595e
Compare
656595e to
028a6d3
Compare
There was a problem hiding this comment.
Pull request overview
Fixes a Python GIL-related crash when reusing image generation pipelines with a Python-backed RNG generator across repeated generate() calls, and adds a workaround for an OpenVINO ov::Core::read_model recursion issue in 2026.1.0 when passing non-const AnyMap.
Changes:
- Wrap Python-backed
ov::genai::Generatorinstances in a GIL-safe wrapper to ensure safe destruction whilepy::gil_scoped_releaseis active. - Add multi-call image generation regression tests and wire them into Linux/Windows CI.
- Use
std::as_const()onAnyMappassed tocore.read_model(...)in tokenizer/whisper/RAG to avoid the OpenVINO 2026.1.0 overload recursion.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/python_tests/test_image_generation_multi_call.py | New regression tests covering repeated generate() calls with/without generators and callbacks |
| src/python/py_utils.cpp | Adds GilSafeGeneratorWrapper and wraps Generator conversion in py_object_to_any() |
| src/python/py_image_generation_pipelines.cpp | Adds GIL-safe cleanup in TorchGenerator destructor; removes unused helper |
| src/cpp/src/whisper/pipeline_static.cpp | Uses std::as_const(properties_copy) for read_model(...) |
| src/cpp/src/whisper/pipeline.cpp | Uses std::as_const(properties_copy) for read_model(...) |
| src/cpp/src/whisper/models/statefull_decoder.cpp | Uses std::as_const(properties) for read_model(...) |
| src/cpp/src/tokenizer/tokenizer_impl.cpp | Uses std::as_const(filtered_properties) for tokenizer/detokenizer read_model(...) |
| src/cpp/src/rag/text_embedding_pipeline.cpp | Uses std::as_const(properties) for read_model(...) |
| .github/workflows/windows.yml | Adds the new multi-call test file to the Windows Python test run |
| .github/workflows/linux.yml | Adds the new multi-call test file to the Linux Python test run |
| .github/CODEOWNERS | Assigns code owners for the new test and Python image generation bindings file |
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
You can also share your feedback on Copilot code review. Take the survey.
bee86ba to
b62c949
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
You can also share your feedback on Copilot code review. Take the survey.
b62c949 to
f82e1d7
Compare
f82e1d7 to
18cb8a0
Compare
18cb8a0 to
06ec871
Compare
df2eb49
Fix
pybind11::handle::dec_ref()GIL crash that occurs on the secondgenerate()call in image generation pipelines (Text2Image, Image2Image, Inpainting) when a Python-backed generator (e.g.TorchGenerator) is passed.GilSafeGeneratorWrapperinpy_utils.cppthat acquires the GIL before destroying the underlying Python generator, preventing unsafePy_DECREFwhen the old generator is overwritten during subsequentgenerate()calls withpy::gil_scoped_releaseactiveTorchGeneratoras defense-in-depth for itspy::objectmembersparams_have_torch_generatorhelperov::Core::read_modelinfinite recursion caused by a template overload in OpenVINO 2026.1.0core.hppby usingstd::as_const()on non-constAnyMaparguments across tokenizer, whisper, and RAG pipelinesIssue CVS-181541