Skip to content
Merged
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
7 changes: 6 additions & 1 deletion backends/qualcomm/_passes/decompose_cdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,19 @@ class DecomposeCDist(ExportPass):
Decompose for math equivalent op.
"""

cdist_targets = {
torch.ops.aten.cdist.default,
torch.ops.aten._cdist_forward.default,
}

def __init__(self) -> None:
super().__init__()

def call(self, graph_module: torch.fx.GraphModule) -> PassResult:
graph = graph_module.graph
for node in graph.nodes:
model = CDist()
if torch.ops.aten.cdist.default == node.target:
if node.target in self.cdist_targets:
if len(node.args) > 2:
assert (
node.args[2] == 2
Expand Down
2 changes: 2 additions & 0 deletions backends/qualcomm/_passes/qnn_pass_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def get_default_pass_activations(cls):
(DecomposeAny, True),
(DecomposeAtan2, True),
(DecomposeColIm, True),
(DecomposeCDist, True),
(DecomposeFill, True),
(DecomposeLogVariants, True),
(DecomposeMaxPool3d, True),
Expand Down Expand Up @@ -278,6 +279,7 @@ def get_passes_dependency_for_capture_program(cls):
DecomposeAny: [RemoveRedundancy],
DecomposeAtan2: [RemoveRedundancy],
DecomposeColIm: [FoldQDQ],
DecomposeCDist: [RemoveRedundancy],
Comment thread
qti-horodnic marked this conversation as resolved.
DecomposeFill: [RemoveRedundancy],
DecomposeLinalgVectorNorm: [RemoveRedundancy],
DecomposeLogVariants: [RemoveRedundancy],
Expand Down
2 changes: 1 addition & 1 deletion backends/qualcomm/builders/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ The following PyTorch operators are supported through decomposition or annotatio
| `aten.any` | `DecomposeAny` |
| `aten.atan2.default`, `aten.atan2.out` | `DecomposeAtan2` |
| `aten.add` (with alpha), `aten.sub` (with alpha) | `DecomposeBinaryAlpha` |
| `aten.cdist` | `DecomposeCDist` |
| `aten.cdist`, `aten._cdist_forward` | `DecomposeCDist` |
| `aten.im2col`, `aten.col2im` | `DecomposeColIm` |
| `aten.einsum` | `DecomposeEinsum` |
| `aten.special_expm1` | `DecomposeExpM1` |
Expand Down
8 changes: 8 additions & 0 deletions backends/qualcomm/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,14 @@ def forward(self, x, y):
return torch.cdist(x, y, p=2)


class CDistForward(torch.nn.Module):
def __init__(self):
super().__init__()

def forward(self, x, y):
return torch.ops.aten._cdist_forward.default(x, y, 2.0, None)


class Ceil(torch.nn.Module):
def __init__(self):
super().__init__()
Expand Down
17 changes: 17 additions & 0 deletions backends/qualcomm/tests/test_qnn_delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,14 @@ def test_qnn_backend_cdist(self):
)
self.lower_module_and_test_output(module, sample_input)

def test_qnn_backend_cdist_forward(self):
module = CDistForward() # noqa: F405
sample_input = (
torch.randn(1, 125, 256),
torch.randn(1, 2048, 256),
)
self.lower_module_and_test_output(module, sample_input)

def test_qnn_backend_channel_shuffle(self):
module = ChannelShuffle(2) # noqa: F405
sample_input = (torch.randn(1, 4, 3, 3),)
Expand Down Expand Up @@ -3159,6 +3167,15 @@ def test_qnn_backend_cdist(self):
module = self.get_qdq_module(module, sample_input)
self.lower_module_and_test_output(module, sample_input)

def test_qnn_backend_cdist_forward(self):
module = CDistForward() # noqa: F405
sample_input = (
torch.randn(1, 125, 256),
torch.randn(1, 2048, 256),
)
module = self.get_qdq_module(module, sample_input)
self.lower_module_and_test_output(module, sample_input)

def test_qnn_backend_channel_shuffle(self):
module = ChannelShuffle(2) # noqa: F405
sample_input = (torch.randn(1, 4, 3, 3),)
Expand Down
Loading