Skip to content

NXP backend: Improve cifarnet speed by removing the initial pading. #13279

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 1 commit into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ def test_remove_io_quant_ops_pass__cifarnet():
)

nodes = list(exec_prog.exported_program().graph.nodes)
assert len(nodes) == 17
assert len(nodes) == 11
assert (
nodes[0].meta["val"].dtype == torch.int8
), "Input tensor doesn't have type INT8."
assert (
nodes[16].meta["val"][0].dtype == torch.int8
nodes[10].meta["val"][0].dtype == torch.int8
), "Output tensor doesn't have type INT8."

assert (
Expand Down
6 changes: 3 additions & 3 deletions backends/nxp/tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 NXP
# Copyright 2024-2025 NXP
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -43,8 +43,8 @@ def test_cifarnet():

delegation_info = get_delegation_info(exec_prog.exported_program().graph_module)
assert delegation_info.num_delegated_subgraphs == 1
assert delegation_info.num_non_delegated_nodes == 17
assert delegation_info.num_delegated_nodes == 42
assert delegation_info.num_non_delegated_nodes == 11
assert delegation_info.num_delegated_nodes == 45

nodes = list(exec_prog.exported_program().graph.nodes)
assert nodes[2].name == "quantized_decomposed_quantize_per_tensor_default"
Binary file modified examples/nxp/experimental/cifar_net/cifar_net.pth
Binary file not shown.
9 changes: 3 additions & 6 deletions examples/nxp/experimental/cifar_net/cifar_net.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 NXP
# Copyright 2024-2025 NXP
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -57,7 +57,7 @@ class CifarNetModel(nn.Module):
def __init__(self):
super().__init__()

self.conv1 = nn.Conv2d(8, 32, 5)
self.conv1 = nn.Conv2d(3, 32, 5)
self.conv2 = nn.Conv2d(32, 32, 5)
self.conv3 = nn.Conv2d(32, 64, 5)
self.pool1 = nn.MaxPool2d(2, 2)
Expand All @@ -66,10 +66,7 @@ def __init__(self):
self.softmax = nn.Softmax(1)

def forward(self, x):

# Neutron Backend does not yet have passses for automated padding if number of channels does not
# fit to Neutron constrains (#channels == #MAC units). So define the model explicitly tailored for Neutron-C-64.
x = F.pad(x, (2, 2, 2, 2, 0, 5))
x = F.pad(x, (2, 2, 2, 2))
x = self.conv1(x)
x = self.pool1(x)

Expand Down
Loading