Skip to content
Open
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions backends/cadence/aot/quantizer/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,3 +721,18 @@ def __init__(self, args, meta):

def replacement_op(self) -> OpOverload:
return torch.ops.cadence.quantized_w8a32_gru.default


class _RmsNormPattern(QuantizationPattern):
"""Pattern that preserves rms_norm from decomposition without matching anything."""

def partition_types(self) -> list[torch._ops.OpOverload]:
return [torch.ops.aten.rms_norm.default]

def get_anchors(
self, gm: torch.fx.GraphModule, fused_partition: List[fx.GraphModule]
) -> Tuple[PartitionAnchors, fx.Node]:
return PartitionAnchors(empty=True), None # pyre-ignore[7]

def replacement_op(self) -> torch._ops.OpOverload:
return torch.ops.aten.rms_norm.default
12 changes: 10 additions & 2 deletions backends/cadence/aot/quantizer/quantizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import torch
from executorch.backends.cadence.aot.quantizer.patterns import (
_RmsNormPattern,
AddmmPattern,
AddPattern,
BmmPattern,
Expand All @@ -37,9 +38,7 @@
is_annotated,
no_outside_users,
)

from torch import fx

from torchao.quantization.pt2e import HistogramObserver, MinMaxObserver
from torchao.quantization.pt2e.quantizer import (
ComposableQuantizer,
Expand Down Expand Up @@ -285,6 +284,15 @@ def __init__(
super().__init__([])


class CadenceRmsNormNopQuantizer(CadenceQuantizer):
"""
Nop quantizer that preserves rms_norm from decomposition.
"""

def __init__(self) -> None:
super().__init__([CadenceAtenQuantizer(_RmsNormPattern(), qconfig_A8W8)])


class CadenceWithLayerNormQuantizer(CadenceQuantizer):
"""
Quantizer including layer norm
Expand Down
Loading