Skip to content

Restructuring demos #531

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

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 2 additions & 3 deletions .ci/scripts/gather_test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import Any

from examples.models import MODEL_NAME_TO_MODEL
from examples.recipes.xnnpack_optimization import MODEL_NAME_TO_OPTIONS
from examples.xnnpack import MODEL_NAME_TO_OPTIONS

# NB: Skip buck2 on MacOS to cut down the number of combinations we
# need to run there as the number of MacOS runner is limited. Buck2
Expand Down Expand Up @@ -80,8 +80,7 @@ def export_models_for_ci() -> None:
}
delegation_configs = {
False,
name in MODEL_NAME_TO_OPTIONS
and MODEL_NAME_TO_OPTIONS[name].xnnpack_delegation,
name in MODEL_NAME_TO_OPTIONS and MODEL_NAME_TO_OPTIONS[name].delegation,
}
for build_tool in BUILD_TOOLS.keys():
if target_os not in BUILD_TOOLS[build_tool]:
Expand Down
24 changes: 12 additions & 12 deletions .ci/scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ test_model() {
cd ../../..
fi

"${PYTHON_EXECUTABLE}" -m examples.export.export_example --model_name="${MODEL_NAME}"
"${PYTHON_EXECUTABLE}" -m examples.portable.scripts.export --model_name="${MODEL_NAME}"

# Run test model
if [[ "${BUILD_TOOL}" == "buck2" ]]; then
buck2 run //examples/executor_runner:executor_runner -- --model_path "./${MODEL_NAME}.pte"
buck2 run //examples/portable/executor_runner:executor_runner -- --model_path "./${MODEL_NAME}.pte"
elif [[ "${BUILD_TOOL}" == "cmake" ]]; then
if [[ ! -f ${CMAKE_OUTPUT_DIR}/executor_runner ]]; then
build_cmake_executor_runner
Expand Down Expand Up @@ -98,24 +98,24 @@ test_model_with_xnnpack() {

# Quantization-only
if [[ ${WITH_QUANTIZATION} == true ]] && [[ ${WITH_DELEGATION} == false ]]; then
bash examples/quantization/test_quantize.sh "${BUILD_TOOL}" "${MODEL_NAME}"
bash examples/xnnpack/quantization/test_quantize.sh "${BUILD_TOOL}" "${MODEL_NAME}"
exit 0
fi

# Delegation
if [[ ${WITH_QUANTIZATION} == true ]]; then
SUFFIX="q8"
"${PYTHON_EXECUTABLE}" -m examples.backend.xnnpack_examples --model_name="${MODEL_NAME}" --delegate --quantize
"${PYTHON_EXECUTABLE}" -m examples.xnnpack.aot_compiler --model_name="${MODEL_NAME}" --delegate --quantize
else
SUFFIX="fp32"
"${PYTHON_EXECUTABLE}" -m examples.backend.xnnpack_examples --model_name="${MODEL_NAME}" --delegate
"${PYTHON_EXECUTABLE}" -m examples.xnnpack.aot_compiler --model_name="${MODEL_NAME}" --delegate
fi

OUTPUT_MODEL_PATH="${MODEL_NAME}_xnnpack_${SUFFIX}.pte"

# Run test model
if [[ "${BUILD_TOOL}" == "buck2" ]]; then
buck2 run //examples/backend:xnn_executor_runner -- --model_path "${OUTPUT_MODEL_PATH}"
buck2 run //examples/xnnpack:xnn_executor_runner -- --model_path "${OUTPUT_MODEL_PATH}"
elif [[ "${BUILD_TOOL}" == "cmake" ]]; then
if [[ ! -f ${CMAKE_OUTPUT_DIR}/backends/xnnpack/xnn_executor_runner ]]; then
build_cmake_xnn_executor_runner
Expand All @@ -129,15 +129,15 @@ test_model_with_xnnpack() {

test_demo_backend_delegation() {
echo "Testing demo backend delegation on AddMul"
"${PYTHON_EXECUTABLE}" -m examples.export.export_and_delegate --option "composite"
"${PYTHON_EXECUTABLE}" -m examples.export.export_and_delegate --option "partition"
"${PYTHON_EXECUTABLE}" -m examples.export.export_and_delegate --option "whole"
"${PYTHON_EXECUTABLE}" -m examples.portable.scripts.export_and_delegate --option "composite"
"${PYTHON_EXECUTABLE}" -m examples.portable.scripts.export_and_delegate --option "partition"
"${PYTHON_EXECUTABLE}" -m examples.portable.scripts.export_and_delegate --option "whole"

# Run test model
if [[ "${BUILD_TOOL}" == "buck2" ]]; then
buck2 run //examples/executor_runner:executor_runner -- --model_path "./composite_model.pte"
buck2 run //examples/executor_runner:executor_runner -- --model_path "./partition_lowered_model.pte"
buck2 run //examples/executor_runner:executor_runner -- --model_path "./whole.pte"
buck2 run //examples/portable/executor_runner:executor_runner -- --model_path "./composite_model.pte"
buck2 run //examples/portable/executor_runner:executor_runner -- --model_path "./partition_lowered_model.pte"
buck2 run //examples/portable/executor_runner:executor_runner -- --model_path "./whole.pte"
elif [[ "${BUILD_TOOL}" == "cmake" ]]; then
if [[ ! -f ${CMAKE_OUTPUT_DIR}/executor_runner ]]; then
build_cmake_executor_runner
Expand Down
2 changes: 1 addition & 1 deletion .ci/scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ install_flatc_from_source() {

build_executorch_runner_buck2() {
# Build executorch runtime with retry as this step is flaky on macos CI
retry buck2 build //examples/executor_runner:executor_runner
retry buck2 build //examples/portable/executor_runner:executor_runner
}

build_executorch_runner_cmake() {
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
MODEL_NAME=${{ matrix.model }}
BUILD_TOOL=${{ matrix.build-tool }}
XNNPACK_QUANTIZATION=${{ matrix.xnnpack_quantization }}
XNNPACK_DELEGATION=${{ matrix.xnnpack_delegation }}
XNNPACK_DELEGATION=${{ matrix.delegation }}
DEMO_BACKEND_DELEGATION=${{ matrix.demo_backend_delegation }}

PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "${BUILD_TOOL}"
Expand Down Expand Up @@ -87,7 +87,7 @@ jobs:
BUILD_TOOL=${{ matrix.build-tool }}
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "${BUILD_TOOL}"
# Test custom ops
PYTHON_EXECUTABLE=python bash examples/custom_ops/test_custom_ops.sh "${BUILD_TOOL}"
PYTHON_EXECUTABLE=python bash examples/portable/custom_ops/test_custom_ops.sh "${BUILD_TOOL}"

test-selective-build-linux:
name: test-selective-build-linux
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/trunk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
MODEL_NAME=${{ matrix.model }}
BUILD_TOOL=${{ matrix.build-tool }}
XNNPACK_QUANTIZATION=${{ matrix.xnnpack_quantization }}
XNNPACK_DELEGATION=${{ matrix.xnnpack_delegation }}
XNNPACK_DELEGATION=${{ matrix.delegation }}
DEMO_BACKEND_DELEGATION=${{ matrix.demo_backend_delegation }}

# Setup MacOS dependencies as there is no Docker support on MacOS atm
Expand Down Expand Up @@ -85,7 +85,7 @@ jobs:
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-macos.sh "${BUILD_TOOL}"

# Build and test custom ops
PYTHON_EXECUTABLE=python bash examples/custom_ops/test_custom_ops.sh "${BUILD_TOOL}"
PYTHON_EXECUTABLE=python bash examples/portable/custom_ops/test_custom_ops.sh "${BUILD_TOOL}"
popd

test-selective-build-macos:
Expand Down
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")

# Option to register custom operator `my_ops::mul3` or `my_ops::mul4` or no
# custom ops at all. Custom ops are defined in
# `examples/custom_ops/custom_ops_1.py` and
# `examples/custom_ops/custom_ops_2.cpp`.
# `examples/portable/custom_ops/custom_ops_1.py` and
# `examples/portable/custom_ops/custom_ops_2.cpp`.
option(
REGISTER_EXAMPLE_CUSTOM_OP
"Register whether custom op 1 (my_ops::mul3) or custom op 2 (my_ops::mul4) \
Expand Down Expand Up @@ -296,7 +296,7 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)

# Generate custom_ops_lib based on REGISTER_EXAMPLE_CUSTOM_OP
if(REGISTER_EXAMPLE_CUSTOM_OP EQUAL 1 OR REGISTER_EXAMPLE_CUSTOM_OP EQUAL 2)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples/custom_ops)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples/portable/custom_ops)
list(APPEND _executor_runner_libs custom_ops_lib)
endif()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ python_library(
],
deps = [
"//caffe2:torch",
"//executorch/examples/example_quantizer_and_delegate/example_operators:example_operators_lib",
"//executorch/backends/example/example_operators:example_operators_lib",
],
)

Expand All @@ -18,7 +18,7 @@ python_library(
"example_backend.py",
],
deps = [
"//executorch/examples/example_quantizer_and_delegate/example_backend_delegate_passes:lib",
"//executorch/backends/example/example_backend_delegate_passes:lib",
"//executorch/exir/backend:backend_details",
"//executorch/exir/backend:compile_spec_schema",
],
Expand All @@ -32,7 +32,7 @@ python_library(
deps = [
":example_backend",
"//caffe2:torch",
"//executorch/examples/example_quantizer_and_delegate/example_operators:example_operators_lib",
"//executorch/backends/example/example_operators:example_operators_lib",
"//executorch/exir:graph_module",
"//executorch/exir/backend:partitioner",
"//executorch/exir/backend/canonical_partitioners:canonical_partitioner_lib",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import copy
from typing import final, List

from executorch.examples.example_quantizer_and_delegate.example_backend_delegate_passes.merge_to_dim_pass import (
from executorch.backends.example.example_backend_delegate_passes.merge_to_dim_pass import (
MergeToDimPass,
)
from executorch.examples.example_quantizer_and_delegate.example_backend_delegate_passes.permute_memory_formats_pass import (
from executorch.backends.example.example_backend_delegate_passes.permute_memory_formats_pass import (
PermuteMemoryFormatsPass,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ python_library(
],
deps = [
"//caffe2:torch",
"//executorch/examples/example_quantizer_and_delegate/example_operators:example_operators_lib",
"//executorch/backends/example/example_operators:example_operators_lib",
"//executorch/exir:dim_order_utils",
"//executorch/exir:pass_base",
"//executorch/exir/dialects:lib",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
from itertools import chain

import torch
from executorch.examples.example_quantizer_and_delegate.example_operators.ops import (
module_to_annotator,
)
from executorch.backends.example.example_operators.ops import module_to_annotator
from executorch.exir.dialects._ops import ops as exir_ops
from executorch.exir.dim_order_utils import get_dim_order
from executorch.exir.pass_base import ExportPass, PassResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
from dataclasses import dataclass

import torch
from executorch.examples.example_quantizer_and_delegate.example_operators.op_base import (
OpBase,
)
from executorch.examples.example_quantizer_and_delegate.example_operators.utils import (
from executorch.backends.example.example_operators.op_base import OpBase
from executorch.backends.example.example_operators.utils import (
_annotate_nodes,
_nodes_are_annotated,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
from dataclasses import dataclass

import torch
from executorch.examples.example_quantizer_and_delegate.example_operators.op_base import (
OpBase,
)
from executorch.examples.example_quantizer_and_delegate.example_operators.utils import (
from executorch.backends.example.example_operators.op_base import OpBase
from executorch.backends.example.example_operators.utils import (
_annotate_nodes,
_nodes_are_annotated,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
from dataclasses import dataclass

import torch
from executorch.examples.example_quantizer_and_delegate.example_operators.op_base import (
OpBase,
)
from executorch.examples.example_quantizer_and_delegate.example_operators.utils import (
from executorch.backends.example.example_operators.op_base import OpBase
from executorch.backends.example.example_operators.utils import (
_annotate_nodes,
_nodes_are_annotated,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
from dataclasses import dataclass

import torch
from executorch.examples.example_quantizer_and_delegate.example_operators.op_base import (
OpBase,
)
from executorch.examples.example_quantizer_and_delegate.example_operators.utils import (
from executorch.backends.example.example_operators.op_base import OpBase
from executorch.backends.example.example_operators.utils import (
_annotate_nodes,
_nodes_are_annotated,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
from dataclasses import dataclass

import torch
from executorch.examples.example_quantizer_and_delegate.example_operators.op_base import (
OpBase,
)
from executorch.examples.example_quantizer_and_delegate.example_operators.utils import (
from executorch.backends.example.example_operators.op_base import OpBase
from executorch.backends.example.example_operators.utils import (
_annotate_nodes,
_nodes_are_annotated,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
from dataclasses import dataclass

import torch
from executorch.examples.example_quantizer_and_delegate.example_operators.op_base import (
OpBase,
)
from executorch.examples.example_quantizer_and_delegate.example_operators.utils import (
from executorch.backends.example.example_operators.op_base import OpBase
from executorch.backends.example.example_operators.utils import (
_annotate_nodes,
_nodes_are_annotated,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
from dataclasses import dataclass

import torch
from executorch.examples.example_quantizer_and_delegate.example_operators.op_base import (
OpBase,
)
from executorch.examples.example_quantizer_and_delegate.example_operators.utils import (
from executorch.backends.example.example_operators.op_base import OpBase
from executorch.backends.example.example_operators.utils import (
_annotate_nodes,
_nodes_are_annotated,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,16 @@

from collections import OrderedDict

from executorch.examples.example_quantizer_and_delegate.example_operators.adaptive_avg_pool2d import (
from executorch.backends.example.example_operators.adaptive_avg_pool2d import (
AdaptiveAvgPool2dNode,
)

from executorch.examples.example_quantizer_and_delegate.example_operators.add import (
AddNode,
)
from executorch.examples.example_quantizer_and_delegate.example_operators.conv2d import (
Conv2DNode,
)
from executorch.examples.example_quantizer_and_delegate.example_operators.conv_relu import (
ConvReluNode,
)
from executorch.examples.example_quantizer_and_delegate.example_operators.dropout import (
DropOutNode,
)
from executorch.examples.example_quantizer_and_delegate.example_operators.flatten import (
FlattenNode,
)
from executorch.examples.example_quantizer_and_delegate.example_operators.linear import (
LinearNode,
)
from executorch.backends.example.example_operators.add import AddNode
from executorch.backends.example.example_operators.conv2d import Conv2DNode
from executorch.backends.example.example_operators.conv_relu import ConvReluNode
from executorch.backends.example.example_operators.dropout import DropOutNode
from executorch.backends.example.example_operators.flatten import FlattenNode
from executorch.backends.example.example_operators.linear import LinearNode

# The ordering of this is important as the quantizer will try to match the patterns in this order.
# That's why we want to match the fused patterns first and then the non-fused ones.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@
from typing import Dict, final

import torch
from executorch.examples.example_quantizer_and_delegate.example_backend import (
TosaBackend,
)
from executorch.examples.example_quantizer_and_delegate.example_operators.ops import (
module_to_annotator,
)
from executorch.backends.example.example_backend import TosaBackend
from executorch.backends.example.example_operators.ops import module_to_annotator
from executorch.exir.backend.canonical_partitioners.pattern_op_partitioner import (
generate_partitions_from_list_of_nodes,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
from typing import List

import torch
from executorch.examples.example_quantizer_and_delegate.example_operators.ops import (
module_to_annotator,
)
from executorch.backends.example.example_operators.ops import module_to_annotator
from torch import fx
from torch.ao.quantization.observer import HistogramObserver, MinMaxObserver
from torch.ao.quantization.pt2e.graph_utils import find_sequential_partitions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@
import torch
import torch._export as export
from executorch import exir
from executorch.examples.example_quantizer_and_delegate.example_partitioner import (
ExamplePartitioner,
)
from executorch.examples.example_quantizer_and_delegate.example_quantizer import (
ExampleQuantizer,
)
from executorch.backends.example.example_partitioner import ExamplePartitioner
from executorch.backends.example.example_quantizer import ExampleQuantizer
from executorch.exir.backend.backend_api import to_backend

from executorch.exir.backend.canonical_partitioners.duplicate_dequant_node_pass import (
Expand Down
4 changes: 2 additions & 2 deletions build/cmake_deps.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ excludes = [

[targets.executor_runner]
buck_targets = [
"//examples/executor_runner:executor_runner",
"//examples/portable/executor_runner:executor_runner",
]
filters = [
".cpp$",
Expand Down Expand Up @@ -104,7 +104,7 @@ deps = [

[targets.xnn_executor_runner]
buck_targets = [
"//examples/backend:xnn_executor_runner",
"//examples/xnnpack:xnn_executor_runner",
]
filters = [
".cpp$",
Expand Down
Loading