Skip to content

Conversation

@sgonorov
Copy link
Contributor

Fix update from release branch

@sgonorov sgonorov self-assigned this Nov 25, 2025
@github-actions github-actions bot added the category: Python API Python API for GenAI label Nov 25, 2025
@sgonorov sgonorov force-pushed the fix_deadlock_update_from_release branch from 4b7cd4f to 6d3fa90 Compare November 26, 2025 12:56
@Wovchena Wovchena requested a review from Copilot November 26, 2025 13:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a deadlock issue in Python callbacks by ensuring proper GIL (Global Interpreter Lock) management during callback lifecycle. The fix addresses the problem of Python objects being destroyed without holding the GIL, which can cause deadlocks in multi-threaded scenarios.

Key changes:

  • Updated callback signature to use py::str instead of std::string for better Python integration
  • Added custom deleters to shared pointers that acquire GIL before destroying Python objects
  • Improved error handling in UTF-8 string decoding with null pointer checks

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/python/py_utils.hpp Changed callback signature from std::string to py::str parameter
src/python/py_utils.cpp Added GIL-aware custom deleters for Python callbacks and improved UTF-8 decoding error handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sgonorov sgonorov force-pushed the fix_deadlock_update_from_release branch 2 times, most recently from 4ffbb64 to 06d0693 Compare November 27, 2025 22:02
@github-actions github-actions bot added category: image generation Image generation pipelines category: GHA CI based on Github actions category: GGUF GGUF file reader labels Nov 27, 2025
@Wovchena Wovchena requested a review from Copilot November 28, 2025 07:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@sgonorov sgonorov requested a review from Wovchena November 28, 2025 09:16
@Wovchena Wovchena requested a review from Copilot November 28, 2025 10:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

m_total_size(total_size), m_mutable_data(mutable_data), m_torch_tensor(torch_tensor) { }

~TorchTensorAllocator() {
if (m_torch_tensor && Py_IsInitialized()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_torch_tensor is always set in constructor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but when we're using move it may be an empty Python object as far as i understand. So it's a little bit defensive here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is TorchTensorAllocator movable? It defines a constructor which should disable default move constructot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it was movable before i've added destructor (constructor doesn't disable generation of default move methods). When i've added destructor it became unmovable, so i've had to specify default move constructor and copy/assign methods.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess copy constructor copies a ref to m_torch_generator. Copy methods should be deleted to avoid this problem

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but that's the old behaviour so i haven't touched it. Also all python objects have ref counter, so it's okay to copy them if needed. The only potential problem i see here is that we have to explicitly get GIL lock before calling copy methods.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have to explicitly get GIL lock before calling copy methods.

Good catch! Apply that

@sgonorov sgonorov force-pushed the fix_deadlock_update_from_release branch from f6d86e1 to 12877e4 Compare December 3, 2025 10:14
@Wovchena Wovchena requested a review from Copilot December 3, 2025 10:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sgonorov sgonorov added this pull request to the merge queue Dec 3, 2025
Merged via the queue into openvinotoolkit:master with commit 22a6979 Dec 3, 2025
148 of 152 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: GGUF GGUF file reader category: GHA CI based on Github actions category: image generation Image generation pipelines category: Python API Python API for GenAI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants