Skip to content

Commit a309d3d

Browse files
authored
Merge branch 'main' into gh/swolchok/136/head
2 parents 4561c6b + 1a6b7a6 commit a309d3d

File tree

5 files changed

+54
-24
lines changed

5 files changed

+54
-24
lines changed

examples/cadence/operators/TARGETS

+2-23
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,5 @@
1-
# Copyright (c) Meta Platforms, Inc. and affiliates.
2-
# All rights reserved.
3-
#
4-
# This source code is licensed under the BSD-style license found in the
5-
# LICENSE file in the root directory of this source tree.
6-
7-
load("@fbcode_macros//build_defs:python_unittest.bzl", "python_unittest")
1+
load("targets.bzl", "define_common_targets")
82

93
oncall("odai_jarvis")
104

11-
12-
python_unittest(
13-
name = "test_add_op",
14-
srcs = [
15-
"test_add_op.py",
16-
],
17-
typing = True,
18-
supports_static_listing = False,
19-
deps = [
20-
"fbsource//third-party/pypi/parameterized:parameterized",
21-
"//caffe2:torch",
22-
"//executorch/backends/cadence/aot:ops_registrations",
23-
"//executorch/backends/cadence/aot:export_example",
24-
"//executorch/backends/cadence/aot:compiler",
25-
],
26-
)
5+
define_common_targets()
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
load("@fbcode_macros//build_defs:python_unittest.bzl", "python_unittest")
8+
9+
TESTS_LIST = [
10+
"add_op",
11+
"quantized_conv1d_op",
12+
"quantized_linear_op",
13+
]
14+
15+
def define_common_targets():
16+
for op in TESTS_LIST:
17+
_define_test_target(op)
18+
19+
20+
def _define_test_target(test_name):
21+
file_name = "test_{}".format(test_name)
22+
python_unittest(
23+
name = file_name,
24+
srcs = [
25+
"{}.py".format(file_name),
26+
],
27+
typing = True,
28+
supports_static_listing = False,
29+
deps = [
30+
"fbsource//third-party/pypi/parameterized:parameterized",
31+
"fbcode//caffe2:torch",
32+
"fbcode//executorch/backends/cadence/aot:ops_registrations",
33+
"fbcode//executorch/backends/cadence/aot:export_example",
34+
"fbcode//executorch/backends/cadence/aot:compiler",
35+
],
36+
)

examples/cadence/operators/quantized_conv1d_op.py renamed to examples/cadence/operators/test_quantized_conv1d_op.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import logging
1010

11+
from typing import cast, Sequence
12+
1113
import torch
1214

1315
from executorch.backends.cadence.aot.ops_registrations import * # noqa
@@ -53,6 +55,6 @@ def forward(self, x: torch.Tensor):
5355
model = QuantizedConv()
5456
model.eval()
5557

56-
example_inputs = (torch.randn(shape),)
58+
example_inputs = (torch.randn(cast(Sequence[int], shape)),)
5759

5860
export_model(model, example_inputs)

runtime/executor/tensor_parser_portable.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,19 @@ Result<Tensor> parseTensor(
101101
sizes = const_cast<exec_aten::SizesType*>(serialized_sizes);
102102
dim_order = const_cast<exec_aten::DimOrderType*>(serialized_dim_order);
103103
}
104+
// Validate sizes before using them in case the PTE data is bad. We can't
105+
// detect bad positive values, but we can reject negative values, which would
106+
// otherwise panic in the TensorImpl ctor. dim_order_to_stride() will validate
107+
// dim_order.
108+
for (int i = 0; i < dim; i++) {
109+
ET_CHECK_OR_RETURN_ERROR(
110+
sizes[i] >= 0,
111+
InvalidProgram,
112+
"Negative size[%d] %" PRId32,
113+
i,
114+
sizes[i]);
115+
}
116+
104117
// We will remove strides from schema.
105118
// Allocating strides buffer here and populating it.
106119
// In subsequent diffs we can remove strides accessor, however this

0 commit comments

Comments
 (0)