Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix torch operator unpatching #2719

Conversation

nikita-savelyevv
Copy link
Collaborator

Changes

Reason for changes

Fix inference of compiled torch models when nncf.torch is imported

Related tickets

140265

Tests

Added test_operator_unpatching

@nikita-savelyevv nikita-savelyevv requested a review from a team as a code owner June 4, 2024 16:20
@github-actions github-actions bot added the NNCF PT Pull requests that updates NNCF PyTorch label Jun 4, 2024
@@ -80,14 +80,24 @@ def test_jit_script_exception_preserves_patching_isolated():


def compile_and_run_test_model() -> torch.Tensor:
from tests.torch.helpers import BasicConvTestModel
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Had to drop BasicConvTestModel because during its import nncf.torch is imported which is not acceptable for this specific test

@nikita-savelyevv nikita-savelyevv requested a review from alexsu52 June 6, 2024 09:10
Copy link
Contributor

@alexsu52 alexsu52 left a comment

Choose a reason for hiding this comment

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

LGTM

@nikita-savelyevv
Copy link
Collaborator Author

torch nightly build 256 is green

@AlexanderDokuchaev AlexanderDokuchaev merged commit 1eec305 into openvinotoolkit:develop Jun 11, 2024
12 checks passed
AlexanderDokuchaev pushed a commit that referenced this pull request Aug 30, 2024
### Changes

Check whether model is compiled based on `"_torchdynamo_orig_callable"`
property of the model forward.

### Reason for changes

`torch.compile` can be applied not only to the model itself, but to
`forward()` method only. For example:
```
model.forward = torch.compile(model.forward)
```
In this case the model itself doesn't change and it won't be an instance
of `torch._dynamo.OptimizedModule`.

### Related tickets

143796

### Tests

Added test when `torch.compile` is applied this way. It does not fail
without the fix though, because the issue is sporadic.


### Relates to
#2665, #2719
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NNCF PT Pull requests that updates NNCF PyTorch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants