Skip to content

Delete old preprocess code #2017

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 2 commits 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
6 changes: 5 additions & 1 deletion backends/qualcomm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

# --gc-sections is added by torch.
add_compile_options("-O3" "-ffunction-sections" "-fdata-sections" "-frtti" "-Wno-unused-command-line-argument")
add_compile_options("-O3"
"-ffunction-sections"
"-fdata-sections"
"-frtti"
"-Wno-unused-command-line-argument")
endif()

include_directories(
Expand Down
115 changes: 5 additions & 110 deletions backends/xnnpack/xnnpack_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
from typing import Dict, final, List

import torch

from executorch.backends.transforms import get_shape
from executorch.backends.xnnpack.operators.node_visitor import get_node_visitors

from executorch.backends.xnnpack.passes import XNNPACKPassManager
Expand All @@ -21,19 +19,18 @@

from executorch.backends.xnnpack.serialization.xnnpack_graph_schema import (
Buffer,
PerChannelQuant,
PerTensorQuant,
XNNDatatype,
XNNGraph,
XNNQuantizedTensorValue,
XNNTensorValue,
XValue,
)
from executorch.backends.xnnpack.serialization.xnnpack_graph_serialize import (
serialize_xnnpack_binary,
)
from executorch.backends.xnnpack.utils.utils import is_param_node

from executorch.backends.xnnpack.utils.xnnpack_constants import (
XNN_VALUE_FLAG_EXTERNAL_INPUT,
XNN_VALUE_FLAG_EXTERNAL_OUTPUT,
)

from executorch.exir.backend.backend_details import (
BackendDetails,
CompileSpec,
Expand All @@ -42,17 +39,6 @@
from executorch.exir.verification.verifier import EXIREdgeDialectVerifier
from torch.export.exported_program import ExportedProgram

XNN_VALUE_FLAG_NON_EXTERNAL = 0
XNN_VALUE_FLAG_EXTERNAL_INPUT = 1
XNN_VALUE_FLAG_EXTERNAL_OUTPUT = 2
XNN_FLAG_TRANSPOSE_WEIGHTS = 1
XNN_INVALID_VALUE_ID = 2**32 - 1
XNN_TYPE_MAP = {
torch.float32: XNNDatatype.xnn_datatype_fp32,
torch.uint8: XNNDatatype.xnn_datatype_quint8,
torch.int8: XNNDatatype.xnn_datatype_qint8,
torch.int32: XNNDatatype.xnn_datatype_qint32,
}
DEFAULT_DEBUG_HANDLE = 65535

logger = logging.getLogger(__name__)
Expand All @@ -65,97 +51,6 @@ class ExternalMeta:
io_type: int


def node_to_xvalue(
node: torch.fx.Node,
constant_buffer_idx: int,
external_id: int,
flags: int,
id_out: int,
dq_datatype=XNNDatatype.xnn_datatype_invalid,
) -> XValue:
node_val = node.meta["val"]
node_value = XValue(
xvalue_union=XNNTensorValue(
datatype=XNN_TYPE_MAP[node_val.dtype],
num_dims=node_val.dim(),
dims=get_shape(node),
constant_buffer_idx=constant_buffer_idx,
external_id=external_id,
flags=flags,
id_out=id_out,
dq_datatype=dq_datatype,
)
)
return node_value


def node_to_per_tensor_quantized_xvalue(
node: torch.fx.Node,
dtype: torch.dtype,
constant_buffer_idx: int,
external_id: int,
flags: int,
id_out: int,
scale: float,
zero_point: int,
) -> XValue:
node_val = node.meta["val"]
node_xvalue = XNNTensorValue(
datatype=XNN_TYPE_MAP[dtype],
num_dims=node_val.dim(),
dims=get_shape(node),
constant_buffer_idx=constant_buffer_idx,
external_id=external_id,
flags=flags,
id_out=id_out,
dq_datatype=XNNDatatype.xnn_datatype_invalid, # always invalid
)

per_tensor_quantized_params = PerTensorQuant(scale=scale, zero_point=zero_point)
quantized_node_val = XValue(
xvalue_union=XNNQuantizedTensorValue(
tensor_value=node_xvalue,
quant_params=per_tensor_quantized_params,
)
)
return quantized_node_val


def node_to_per_channel_quantized_xvalue(
node: torch.fx.Node,
dtype: torch.dtype,
constant_buffer_idx: int,
external_id: int,
flags: int,
id_out: int,
channel_dim: int,
scale: torch.Tensor,
) -> XValue:
node_val = node.meta["val"]
assert dtype == torch.torch.int8
node_xvalue = XNNTensorValue(
datatype=XNNDatatype.xnn_datatype_qcint8, # HACK: XNN_TYPE_MAP[dtype],
num_dims=node_val.dim(),
dims=get_shape(node),
constant_buffer_idx=constant_buffer_idx,
external_id=external_id,
flags=flags,
id_out=id_out,
dq_datatype=XNNDatatype.xnn_datatype_invalid, # always invalid
)

per_channel_quantized_params = PerChannelQuant(
scale=scale.tolist(), channel_dim=channel_dim
)
quantized_node_val = XValue(
xvalue_union=XNNQuantizedTensorValue(
tensor_value=node_xvalue,
quant_params=per_channel_quantized_params,
)
)
return quantized_node_val


def generate_node_to_external_map(
exported_program: ExportedProgram,
edge_graph_module: torch.fx.GraphModule,
Expand Down