Skip to content

Commit 43a1064

Browse files
mcremon-metafacebook-github-bot
authored andcommitted
Add channel-last unit test for conv1d (#14337)
Summary: As titled. Differential Revision: D82552951
1 parent 42e8746 commit 43a1064

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

backends/cadence/aot/export_example.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
def export_model(
4040
model: nn.Module,
4141
example_inputs: Tuple[Any, ...],
42+
opt_level: int = 1,
4243
file_name: str = "CadenceDemoModel",
4344
working_dir: Optional[str] = None,
4445
):
@@ -99,14 +100,15 @@ def export_model(
99100
def export_and_run_model(
100101
model: nn.Module,
101102
example_inputs: Tuple[Any, ...],
103+
opt_level: int = 1,
102104
file_name: str = "CadenceDemoModel",
103105
eps_error: float = 1e-1,
104106
eps_warn: float = 1e-5,
105107
):
106108
# create work directory for outputs and model binary
107109
working_dir = tempfile.mkdtemp(dir="/tmp")
108110
logging.debug(f"Created work directory {working_dir}")
109-
exec_prog = export_model(model, example_inputs, file_name, working_dir)
111+
exec_prog = export_model(model, example_inputs, opt_level, file_name, working_dir)
110112
ref_outputs = model(*example_inputs)
111113
runtime.run_and_compare(
112114
executorch_prog=exec_prog,

examples/cadence/operators/test_quantized_conv1d_op.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
depthwise,
3636
bias,
3737
channel_last,
38-
) = [(1, 8, 33), 8, 16, 3, 2, 4, 3, False, True, False]
38+
) = [(1, 2, 4), 2, 8, 1, 1, 0, 1, False, False, False]
3939

4040
class QuantizedConv(torch.nn.Module):
4141
def __init__(self):
@@ -60,3 +60,10 @@ def forward(self, x: torch.Tensor):
6060
example_inputs = (torch.randn(cast(Sequence[int], shape)),)
6161

6262
export_and_run_model(model, example_inputs)
63+
64+
model = QuantizedConv()
65+
model.eval()
66+
67+
example_inputs = (torch.randn(cast(Sequence[int], shape)),)
68+
69+
export_and_run_model(model, example_inputs, opt_level=3)

0 commit comments

Comments
 (0)