Skip to content

Commit cbd66d1

Browse files
authored
Adapt executorch 0.6.0 (#2587)
* Delay installation whl * Pin torch 2.7.0 * Adapt torch 2.7.0 * Add quant::dequantize_affine
1 parent 7e5b37c commit cbd66d1

File tree

5 files changed

+35
-23
lines changed

5 files changed

+35
-23
lines changed

coremltools/converters/mil/frontend/torch/quantization_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ def _weight_int4pack_mm(context, node):
740740

741741

742742
@register_torch_op(
743-
torch_alias=["torchao::dequantize_affine", "torchao.dequantize_affine"],
743+
torch_alias=["torchao::dequantize_affine", "torchao.dequantize_affine", "quant::dequantize_affine"],
744744
)
745745
def dequantize_affine(context, node):
746746
if not _HAS_TORCHAO:

coremltools/converters/mil/frontend/torch/test/test_torch_export_conversion_api.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@
3636
backends = testing_reqs.backends
3737
compute_units = testing_reqs.compute_units
3838

39-
TORCH_EXPORT_DEFAULT_LOWER_BOUND = {TorchFrontend.TORCHEXPORT: 2, TorchFrontend.EXECUTORCH: 2}
40-
if torch.__version__ >= "2.4.0":
41-
TORCH_EXPORT_DEFAULT_LOWER_BOUND[TorchFrontend.TORCHEXPORT] = 0
42-
4339

4440
class TestTorchExportConversionAPI(TorchBaseTest):
4541
@pytest.mark.parametrize("frontend", frontends)
@@ -160,7 +156,10 @@ def forward(self, x):
160156
)[1]
161157
input_proto = coreml_model.input_description._fd_spec[0]
162158
size_ranges = input_proto.type.multiArrayType.shapeRange.sizeRanges
163-
assert size_ranges[0].lowerBound == TORCH_EXPORT_DEFAULT_LOWER_BOUND[frontend]
159+
assert size_ranges[0].lowerBound == {
160+
TorchFrontend.TORCHEXPORT: 0,
161+
TorchFrontend.EXECUTORCH: 2,
162+
}[frontend]
164163
assert size_ranges[0].upperBound == 2147483647
165164
assert size_ranges[1].lowerBound == 3
166165
assert size_ranges[1].upperBound == 3
@@ -351,7 +350,7 @@ def forward(self, input, other):
351350

352351
dynamic_shapes = None
353352
if dynamic:
354-
dim0 = torch.export.Dim("dim0")
353+
dim0 = torch.export.Dim.AUTO
355354
dim1 = torch.export.Dim("dim1", min=1, max=3)
356355
dynamic_shapes = {
357356
"input": {0: dim0, 1: dim1},
@@ -370,11 +369,12 @@ def forward(self, input, other):
370369
if dynamic:
371370
for input_proto in coreml_model.input_description._fd_spec:
372371
size_ranges = input_proto.type.multiArrayType.shapeRange.sizeRanges
373-
assert size_ranges[0].lowerBound == TORCH_EXPORT_DEFAULT_LOWER_BOUND[frontend]
372+
assert size_ranges[0].lowerBound == 2
374373
assert size_ranges[0].upperBound == 2147483647
375-
assert size_ranges[1].lowerBound == max(
376-
1, TORCH_EXPORT_DEFAULT_LOWER_BOUND[frontend]
377-
)
374+
assert size_ranges[1].lowerBound == {
375+
TorchFrontend.TORCHEXPORT: 1,
376+
TorchFrontend.EXECUTORCH: 2,
377+
}[frontend]
378378
assert size_ranges[1].upperBound == 3
379379

380380
mil_program = coreml_model._mil_program
@@ -451,7 +451,10 @@ def forward(self, arg):
451451
if dynamic:
452452
input_proto = coreml_model.input_description._fd_spec[0]
453453
size_ranges = input_proto.type.multiArrayType.shapeRange.sizeRanges
454-
assert size_ranges[0].lowerBound == TORCH_EXPORT_DEFAULT_LOWER_BOUND[frontend]
454+
assert size_ranges[0].lowerBound == {
455+
TorchFrontend.TORCHEXPORT: 0,
456+
TorchFrontend.EXECUTORCH: 2,
457+
}[frontend]
455458
assert size_ranges[0].upperBound == 2147483647
456459
assert size_ranges[1].lowerBound == 3
457460
assert size_ranges[1].upperBound == 3
@@ -637,10 +640,16 @@ def forward(self, a, x, b):
637640
if i == 0:
638641
assert size_ranges[0].lowerBound == 2
639642
assert size_ranges[0].upperBound == 2
640-
assert size_ranges[1].lowerBound == TORCH_EXPORT_DEFAULT_LOWER_BOUND[frontend]
643+
assert size_ranges[1].lowerBound == {
644+
TorchFrontend.TORCHEXPORT: 0,
645+
TorchFrontend.EXECUTORCH: 2,
646+
}[frontend]
641647
assert size_ranges[1].upperBound == 2147483647
642648
elif i == 1:
643-
assert size_ranges[0].lowerBound == TORCH_EXPORT_DEFAULT_LOWER_BOUND[frontend]
649+
assert size_ranges[0].lowerBound == {
650+
TorchFrontend.TORCHEXPORT: 0,
651+
TorchFrontend.EXECUTORCH: 2,
652+
}[frontend]
644653
assert size_ranges[0].upperBound == 2147483647
645654
assert size_ranges[1].lowerBound == 2
646655
assert size_ranges[1].upperBound == 2
@@ -745,7 +754,10 @@ def forward(self, x):
745754
if dynamic:
746755
input_proto = coreml_model.input_description._fd_spec[0]
747756
size_ranges = input_proto.type.multiArrayType.shapeRange.sizeRanges
748-
assert size_ranges[0].lowerBound == TORCH_EXPORT_DEFAULT_LOWER_BOUND[frontend]
757+
assert size_ranges[0].lowerBound == {
758+
TorchFrontend.TORCHEXPORT: 0,
759+
TorchFrontend.EXECUTORCH: 2,
760+
}[frontend]
749761
assert size_ranges[0].upperBound == 2147483647
750762
assert size_ranges[1].lowerBound == 2
751763
assert size_ranges[1].upperBound == 2

reqs/pytorch.pip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ torchaudio==2.2.0; platform_machine != "arm64"
55
torchvision==0.17.0; platform_machine != "arm64"
66

77
# Torch dependencies for ARM
8-
torch>=2.2.0,<2.8; platform_machine == "arm64"
8+
torch==2.7.0; platform_machine == "arm64"
99
torchaudio>=2.2.0; platform_machine == "arm64"
1010
torchvision>=0.17.0; platform_machine == "arm64"
1111
torchsr==1.0.4; platform_machine == "arm64"
1212

1313
# TODO (rdar://141476729) support a more recent timm
1414
timm==0.6.13; platform_machine == "arm64"
1515

16-
torchao==0.11.0; platform_machine == "arm64" and python_version >= '3.10'
16+
torchao==0.10.0; platform_machine == "arm64" and python_version >= '3.10'

reqs/test_executorch.pip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
# Warning: Starting from ExecuTorch 0.6.0, coremltools is added as a dependency
55
# so we need to re-install built-from-source coremltools after pip install ExecuTorch
6-
executorch>=0.4.0; platform_machine == "arm64" and python_version >= '3.10'
6+
executorch>=0.6.0; platform_machine == "arm64" and python_version >= '3.10'

scripts/test.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ echo
8282
echo "Using python from $(which python)"
8383
echo
8484

85+
# Install dependencies if specified
86+
if [ ! -z "${REQUIREMENTS}" ]; then
87+
$PIP_EXECUTABLE install --prefer-binary -r "${REQUIREMENTS}"
88+
fi
89+
8590
if [[ $WHEEL_PATH == "" ]]; then
8691
cd ..
8792
$PIP_EXECUTABLE install -e ${COREMLTOOLS_NAME} --upgrade --no-deps
@@ -90,11 +95,6 @@ else
9095
$PIP_EXECUTABLE install $~WHEEL_PATH --upgrade --no-deps --force-reinstall
9196
fi
9297

93-
# Install dependencies if specified
94-
if [ ! -z "${REQUIREMENTS}" ]; then
95-
$PIP_EXECUTABLE install --prefer-binary -r "${REQUIREMENTS}"
96-
fi
97-
9898
if [[ ! -z "${WHEEL_PATH}" ]]; then
9999
# in a test of a wheel, need to run from ${COREMLTOOLS_HOME}/coremltools for some reason.
100100
# otherwise pytest picks up tests in deps, env, etc.

0 commit comments

Comments
 (0)