Skip to content

Commit 7d084de

Browse files
committed
Merge remote-tracking branch 'origin/main' into test-spec-update
2 parents 5214824 + de30572 commit 7d084de

File tree

161 files changed

+4241
-453
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+4241
-453
lines changed

.github/workflows/android-perf.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ jobs:
178178
upload-models:
179179
needs: export-models
180180
runs-on: linux.2xlarge
181+
if: always() # Continue this job regardless of previous job outcome
181182
steps:
182183
- name: Download the models from GitHub
183184
uses: actions/download-artifact@v3

.github/workflows/apple-perf.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ jobs:
179179
upload-models:
180180
needs: export-models
181181
runs-on: linux.2xlarge
182+
if: always() # Continue this job regardless of previous job outcome
182183
steps:
183184
- name: Download the models from GitHub
184185
uses: actions/download-artifact@v3

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ option(EXECUTORCH_BUILD_KERNELS_OPTIMIZED "Build the optimized kernels" OFF)
197197

198198
option(EXECUTORCH_BUILD_KERNELS_QUANTIZED "Build the quantized kernels" OFF)
199199

200-
option(EXECUTORCH_BUILD_SDK "Build the ExecuTorch SDK")
200+
option(EXECUTORCH_BUILD_SDK "Build the ExecuTorch Developer Tools")
201201

202202
option(EXECUTORCH_BUILD_SIZE_TEST "Build the size test" OFF)
203203

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Key value propositions of ExecuTorch are:
1010
- **Portability:** Compatibility with a wide variety of computing platforms,
1111
from high-end mobile phones to highly constrained embedded systems and
1212
microcontrollers.
13-
- **Productivity:** Enabling developers to use the same toolchains and SDK from
14-
PyTorch model authoring and conversion, to debugging and deployment to a wide
15-
variety of platforms.
13+
- **Productivity:** Enabling developers to use the same toolchains and Developer
14+
Tools from PyTorch model authoring and conversion, to debugging and deployment
15+
to a wide variety of platforms.
1616
- **Performance:** Providing end users with a seamless and high-performance
1717
experience due to a lightweight runtime and utilizing full hardware
1818
capabilities such as CPUs, NPUs, and DSPs.

backends/apple/coreml/compiler/coreml_preprocess.py

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# CoreML backend for delegating a EdgeProgram to CoreML.
44

55
import json
6+
import logging
67

78
import shutil
89
import uuid
@@ -14,6 +15,7 @@
1415
from typing import Any, Dict, final, List, Optional, Tuple
1516

1617
import coremltools as ct
18+
import coremltools.optimize as cto
1719
import executorchcoreml
1820

1921
from executorch.exir.backend.backend_details import (
@@ -23,12 +25,16 @@
2325
)
2426
from executorch.exir.backend.compile_spec_schema import CompileSpec
2527

28+
logger = logging.getLogger(__name__)
29+
logger.setLevel(logging.WARNING)
30+
2631

2732
class COMPILE_SPEC_KEYS(Enum):
2833
COMPUTE_UNITS = "compute_units"
2934
MODEL_TYPE = "model_type"
3035
MIN_DEPLOYMENT_TARGET = "min_deployment_target"
3136
MODEL_COMPUTE_PRECISION = "model_compute_precision"
37+
OP_LINEAR_QUANTIZER_CONFIG = "op_linear_quantizer_config"
3238

3339

3440
class MODEL_PATHS(Enum):
@@ -169,12 +175,44 @@ def generate_compute_unit_compile_spec(
169175
compute_unit.name.lower().encode("utf-8"),
170176
)
171177

178+
@staticmethod
179+
def generate_op_linear_quantizer_config_compile_spec(
180+
op_linear_quantizer_config: Dict,
181+
) -> CompileSpec:
182+
"""
183+
Returns the compile spec representing the model post conversion quantization,
184+
which is a dict that will construct cto.coreml.OpLinearQuantizerConfig
185+
"""
186+
str_representation = json.dumps(op_linear_quantizer_config)
187+
byte_representation = str_representation.encode("utf-8")
188+
return CompileSpec(
189+
COMPILE_SPEC_KEYS.OP_LINEAR_QUANTIZER_CONFIG.value,
190+
byte_representation,
191+
)
192+
193+
@staticmethod
194+
def op_linear_quantizer_config_from_compile_specs(
195+
compile_specs: List[CompileSpec],
196+
) -> cto.coreml.OpLinearQuantizerConfig:
197+
"""
198+
Returns the model's post conversion quantization by parsing the list of compile specs.
199+
"""
200+
for compile_spec in compile_specs:
201+
if compile_spec.key == COMPILE_SPEC_KEYS.OP_LINEAR_QUANTIZER_CONFIG.value:
202+
config_dict_str = compile_spec.value.decode("utf-8")
203+
config_dict = json.loads(config_dict_str)
204+
config = cto.coreml.OpLinearQuantizerConfig._from_dict(config_dict)
205+
return config
206+
207+
return None
208+
172209
@staticmethod
173210
def generate_compile_specs(
174211
compute_unit: ct.ComputeUnit = ct.ComputeUnit.ALL,
175212
minimum_deployment_target: ct.target = ct.target.iOS15,
176213
compute_precision: ct.precision = ct.precision.FLOAT16,
177214
model_type: MODEL_TYPE = MODEL_TYPE.MODEL,
215+
op_linear_quantizer_config: Optional[Dict] = None,
178216
) -> List[CompileSpec]:
179217
"""
180218
Returns the list of compile specs that's used by CoreMLBackend to lower the module.
@@ -192,6 +230,12 @@ def generate_compile_specs(
192230
CoreMLBackend.generate_compute_precision_compile_spec(compute_precision)
193231
)
194232
compile_specs.append(CoreMLBackend.generate_model_type_compile_spec(model_type))
233+
if op_linear_quantizer_config is not None:
234+
compile_specs.append(
235+
CoreMLBackend.generate_op_linear_quantizer_config_compile_spec(
236+
op_linear_quantizer_config
237+
)
238+
)
195239

196240
return compile_specs
197241

@@ -368,18 +412,18 @@ def preprocess(
368412
compile_specs,
369413
)
370414
)
371-
372415
model_compute_precision: ct.precision = (
373416
CoreMLBackend.model_compute_precision_from_compile_specs(compile_specs)
374417
)
375-
376418
minimum_deployment_target: ct.target = (
377419
CoreMLBackend.min_deployment_target_from_compile_specs(compile_specs)
378420
)
379-
380421
compute_units: ct.ComputeUnit = CoreMLBackend.compute_unit_from_compile_specs(
381422
compile_specs
382423
)
424+
op_linear_quantizer_config = (
425+
CoreMLBackend.op_linear_quantizer_config_from_compile_specs(compile_specs)
426+
)
383427

384428
mlmodel = ct.convert(
385429
model=edge_program,
@@ -392,4 +436,15 @@ def preprocess(
392436
compute_units=compute_units,
393437
)
394438

439+
if op_linear_quantizer_config is not None:
440+
logger.warning(
441+
"Core ML Backend op_linear_quantizer_config API is experimental"
442+
)
443+
config = cto.coreml.OptimizationConfig(
444+
global_config=op_linear_quantizer_config,
445+
# skip embedding
446+
op_type_configs={"gather": None},
447+
)
448+
mlmodel = cto.coreml.linear_quantize_weights(mlmodel, config=config)
449+
395450
return CoreMLBackend.preprocess_model(mlmodel, model_type=model_type)

backends/arm/arm_backend.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
55

6+
# pyre-unsafe
7+
68
#
79
# Main implementation of AoT flow to partition and preprocess for Arm target
810
# backends. Converts via TOSA as an intermediate form supported by AoT and

backends/arm/arm_partitioner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
55

6+
# pyre-unsafe
7+
68
import logging
79
import operator
810
import os

backends/arm/arm_vela.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
55

6+
# pyre-unsafe
7+
68
import os
79
import struct
810
import tempfile

backends/arm/operators/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
55

6+
# pyre-unsafe
7+
68
from . import ( # noqa
79
node_visitor,
810
op_add,

backends/arm/operators/node_visitor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
55

6+
# pyre-unsafe
7+
68
from typing import Dict, List
79

810
import serializer.tosa_serializer as ts

backends/arm/operators/op_add.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
55

6+
# pyre-unsafe
7+
68
from typing import List
79

810
import executorch.backends.arm.tosa_quant_utils as tqutils

backends/arm/operators/op_addmm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
55

6+
# pyre-unsafe
7+
68
from typing import List
79

810
import serializer.tosa_serializer as ts

backends/arm/operators/op_avg_pool2d.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
5+
6+
# pyre-unsafe
57
from typing import List
68

79
import serializer.tosa_serializer as ts

backends/arm/operators/op_batch_norm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
5+
6+
# pyre-unsafe
57
from typing import List
68

79
import serializer.tosa_serializer as ts

backends/arm/operators/op_bmm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
6+
7+
# pyre-unsafe
68
from typing import List
79

810
import serializer.tosa_serializer as ts

backends/arm/operators/op_cat.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
55

6+
# pyre-unsafe
7+
68
from typing import List
79

810
import serializer.tosa_serializer as ts

backends/arm/operators/op_conv2d.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
5+
6+
# pyre-unsafe
57
from typing import cast, List
68

79
import serializer.tosa_serializer as ts

backends/arm/operators/op_dequant.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
5+
6+
# pyre-unsafe
57
from typing import List
68

79
import serializer.tosa_serializer as ts

backends/arm/operators/op_div.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
5+
6+
# pyre-unsafe
57
from typing import List
68

79
import serializer.tosa_serializer as ts

backends/arm/operators/op_exp.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
5+
6+
# pyre-unsafe
57
from typing import List
68

79
import numpy as np

backends/arm/operators/op_full.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
5+
6+
# pyre-unsafe
57
from typing import List
68

79
import numpy as np

backends/arm/operators/op_get_item.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
5+
6+
# pyre-unsafe
57
from typing import List
68

79
import serializer.tosa_serializer as ts

backends/arm/operators/op_hardtanh.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
5+
6+
# pyre-unsafe
57
from typing import List
68

79
import serializer.tosa_serializer as ts

backends/arm/operators/op_log.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
5+
6+
# pyre-unsafe
57
from typing import List
68

79
import numpy as np

backends/arm/operators/op_mean_dim.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
5+
6+
# pyre-unsafe
57
from typing import List
68

79
import serializer.tosa_serializer as ts

backends/arm/operators/op_mm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
6+
7+
# pyre-unsafe
68
from typing import List
79

810
import serializer.tosa_serializer as ts

backends/arm/operators/op_mul.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
55

6+
# pyre-unsafe
7+
68
from typing import cast, List
79

810
import executorch.backends.arm.tosa_quant_utils as tqutils

backends/arm/operators/op_output.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
55

6+
# pyre-unsafe
7+
68
from typing import cast
79

810
import serializer.tosa_serializer as ts

backends/arm/operators/op_permute.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
55

6+
# pyre-unsafe
7+
68
from typing import List
79

810
import serializer.tosa_serializer as ts

backends/arm/operators/op_placeholder.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
55

6+
# pyre-unsafe
7+
68
import numpy as np
79
import serializer.tosa_serializer as ts
810
import torch.fx

0 commit comments

Comments
 (0)