Skip to content

Allow pattern replacement to ignore literals #2519

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

Open
wants to merge 2 commits into
base: gh/kimishpatel/6/base
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions torchao/quantization/pt2e/reference_representation_rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from torch._higher_order_ops.out_dtype import out_dtype
from torch.ao.quantization.fx._decomposed import quantized_decomposed_lib # noqa: F401
from torch.fx import GraphModule
from torch.fx.subgraph_rewriter import replace_pattern
from torch.fx.subgraph_rewriter import replace_pattern_with_filters

from torchao.quantization.pt2e.export_utils import WrapperModule
from torchao.quantization.pt2e.utils import (
Expand Down Expand Up @@ -627,6 +627,7 @@ class _RewriteInfo:
# post transformation on the exported pattern and replacement GraphModule
pattern_post_trans: Optional[Callable[[GraphModule], GraphModule]] = None
replacement_post_trans: Optional[Callable[[GraphModule], GraphModule]] = None
ignore_literals: bool = False


def reference_representation_rewrite(model: GraphModule) -> GraphModule:
Expand Down Expand Up @@ -830,6 +831,12 @@ def reference_representation_rewrite(model: GraphModule) -> GraphModule:
replacement = replacement_post_trans(replacement)
pattern.recompile() # type: ignore[attr-defined]
replacement.recompile() # type: ignore[attr-defined]
replace_pattern(model, pattern, replacement)
replace_pattern_with_filters(
model,
pattern,
replacement,
match_filters=None,
ignore_literals=rewrite_info.ignore_literals,
) # type: ignore[arg-type]

return model
Loading