reduce area of patch_everywhere for avoid unexpected replacements#2237
Merged
IlyasMoutawwakil merged 2 commits intoApr 23, 2025
Conversation
Contributor
Author
|
@echarlaix @IlyasMoutawwakil please take a look |
| if module_name_prefix is not None and not name.startswith(module_name_prefix): | ||
| continue | ||
| if hasattr(module, attribute_name): | ||
| if hasattr(module, attribute_name) and isinstance(getattr(module, attribute_name, None), type(patch)): |
Member
There was a problem hiding this comment.
why is this needed ? isn't simply adding module_name_prefix="transformers" enough ?
Contributor
Author
There was a problem hiding this comment.
yes, that should be enough. I just added for prevent issues with other usages (that is out of my control)
Member
There was a problem hiding this comment.
I think the check adds some caveats/edge cases that are not obvious, for example if some module has the attribute cache_implementation but its set to None in some places and I wanna patch it everywhere with "static", you'll have isinstance(getattr(module, attribute_name, None), type(patch)) False, since the type of patch is str and None is not an instance of str.
eaidova
commented
Apr 23, 2025
Member
|
thansk ! |
AlexanderDokuchaev
pushed a commit
to openvinotoolkit/nncf
that referenced
this pull request
May 6, 2025
### Changes Use Optimum Commit with PR huggingface/optimum#2237 in conformance test. ### Reason for changes This change is necessary because PT WC conformance test in NNCF uses `optimum.exporters.openvino.convert.export_from_model` which corrupts the PT namespace due to patching leading to errors in using torch.export. This issue is resolved in the exact commit used to run the Conformance test resolving the issue with FX backend conformance tests. ### Related tickets Issue 165013 ### Tests Category | Job | Status | Job Number | Notes -- | -- | -- | -- | -- GH WC | WC test on GHA | Pass | <a href="https://github.com/openvinotoolkit/nncf/actions/runs/14705449313">72</a> | Manual | job/manual/job/post_training_quantization/664/ | Pass | 664 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
I observe that patching for
_prepare_4d_causal_attention_mask_for_sdpatrying to override some native pytorch (torch.ops namespace) and unpatching does not return original behaviour back instead of that, it replaces pytorch module by function from transformers.It lead to errors when torch.export used in the same environment, where optimum export called.
For avoid that suggested 2 additional fixes: