Skip to content

Commit

Permalink
Update name from xtensa to cadence
Browse files Browse the repository at this point in the history
Summary: As titled.

Differential Revision: D55998135
  • Loading branch information
mcremon-meta authored and facebook-github-bot committed Apr 11, 2024
1 parent 2fc99b0 commit 6ce0748
Show file tree
Hide file tree
Showing 32 changed files with 35 additions and 35 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
logging.basicConfig(level=logging.INFO, format=FORMAT)


def export_xtensa_model(model, example_inputs):
def export_model(model, example_inputs):
# Quantizer
quantizer = XtensaBaseQuantizer()

Expand All @@ -46,20 +46,20 @@ def export_xtensa_model(model, example_inputs):
patterns = [q.pattern for q in quantizer.quantizers]
QuantFusion(patterns)(converted_model)

# Get edge program (note: the name will change to export_to_xtensa in future PRs)
# Get edge program (note: the name will change to export_to_cadence in future PRs)
edge_prog_manager = export_to_edge(converted_model, example_inputs, pt2_quant=True)

# Run a couple required passes for quant/dequant ops
xtensa_prog_manager = edge_prog_manager.transform(
cadence_prog_manager = edge_prog_manager.transform(
[ReplacePT2QuantWithXtensaQuant(), ReplacePT2DequantWithXtensaDequant()],
check_ir_validity=False,
)

exec_prog = xtensa_prog_manager.to_executorch()
exec_prog = cadence_prog_manager.to_executorch()

logging.info(
f"Final exported graph module:\n{exec_prog.exported_program().graph_module}"
)

# Save the program as XtensaDemoModel.pte
save_pte_program(exec_prog, "XtensaDemoModel")
# Save the program as CadenceDemoModel.pte
save_pte_program(exec_prog, "CadenceDemoModel")
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def get_anchors(
)

def replacement_op(self):
return torch.ops.xtensa.quantized_linear.default
return torch.ops.cadence.quantized_linear.default


class LinearFunctionalPattern(QuantizationPattern):
Expand All @@ -457,7 +457,7 @@ def get_anchors(
)

def replacement_op(self):
return torch.ops.xtensa.quantized_linear.default
return torch.ops.cadence.quantized_linear.default


class LayerNormPattern(QuantizationPattern):
Expand All @@ -476,7 +476,7 @@ def get_anchors(self, gm, fused_partition) -> PartitionAnchors:
)

def replacement_op(self):
return torch.ops.xtensa.quantized_layer_norm.default
return torch.ops.cadence.quantized_layer_norm.default


class Conv1dPattern(QuantizationPattern):
Expand All @@ -503,7 +503,7 @@ def get_anchors(
)

def replacement_op(self):
return torch.ops.xtensa.quantized_conv.default
return torch.ops.cadence.quantized_conv.default


class Conv2dPattern(QuantizationPattern):
Expand All @@ -530,7 +530,7 @@ def get_anchors(
)

def replacement_op(self):
return torch.ops.xtensa.quantized_conv.default
return torch.ops.cadence.quantized_conv.default


class AddmmPattern(QuantizationPattern):
Expand All @@ -550,7 +550,7 @@ def get_anchors(
)

def replacement_op(self):
return torch.ops.xtensa.quantized_linear.default
return torch.ops.cadence.quantized_linear.default


class ReluPattern(QuantizationPattern):
Expand All @@ -573,7 +573,7 @@ def get_anchors(
)

def replacement_op(self):
return torch.ops.xtensa.quantized_relu.default
return torch.ops.cadence.quantized_relu.default


class GenericQuantizer(Quantizer):
Expand Down Expand Up @@ -823,15 +823,15 @@ def mark_fused(cls, nodes) -> bool:

class ReplacePT2QuantWithXtensaQuant(ExportPass):
"""
Replace the pt2 quantization ops with custom xtensa quantization ops.
Replace the pt2 quantization ops with custom cadence quantization ops.
"""

def call_operator(self, op, args, kwargs, meta):
if op not in {exir_ops.edge.quantized_decomposed.quantize_per_tensor.default}:
return super().call_operator(op, args, kwargs, meta)

return super().call_operator(
exir_ops.edge.xtensa.quantize_per_tensor.default,
exir_ops.edge.cadence.quantize_per_tensor.default,
args,
kwargs,
meta,
Expand All @@ -840,15 +840,15 @@ def call_operator(self, op, args, kwargs, meta):

class ReplacePT2DequantWithXtensaDequant(ExportPass):
"""
Replace the pt2 dequantization ops with custom xtensa dequantization ops.
Replace the pt2 dequantization ops with custom cadence dequantization ops.
"""

def call_operator(self, op, args, kwargs, meta):
if op not in {exir_ops.edge.quantized_decomposed.dequantize_per_tensor.default}:
return super().call_operator(op, args, kwargs, meta)

return super().call_operator(
exir_ops.edge.xtensa.dequantize_per_tensor.default,
exir_ops.edge.cadence.dequantize_per_tensor.default,
args,
kwargs,
meta,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ set(_aten_ops__srcs
"${CMAKE_CURRENT_SOURCE_DIR}/op_view_copy.cpp"
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/broadcast_util.cpp"
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/repeat_util.cpp")
add_library(aten_ops_xtensa ${_aten_ops__srcs})
target_link_libraries(aten_ops_xtensa PUBLIC executorch)
target_link_libraries(aten_ops_xtensa PRIVATE xtensa_kernels)
add_library(aten_ops_cadence ${_aten_ops__srcs})
target_link_libraries(aten_ops_cadence PUBLIC executorch)
target_link_libraries(aten_ops_cadence PRIVATE cadence_kernels)

# Let files say "include <executorch/path/to/header.h>".
set(_common_include_directories ${EXECUTORCH_ROOT}/..)

target_include_directories(aten_ops_xtensa PUBLIC ${ROOT_DIR}/..
target_include_directories(aten_ops_cadence PUBLIC ${ROOT_DIR}/..
${CMAKE_BINARY_DIR}
${_common_include_directories})

Expand All @@ -52,7 +52,7 @@ target_include_directories(custom_ops PUBLIC ${ROOT_DIR}/..
${_common_include_directories})

target_link_libraries(custom_ops PUBLIC executorch)
target_link_libraries(custom_ops PRIVATE xtensa_kernels)
target_link_libraries(custom_ops PRIVATE cadence_kernels)

# Generate C++ bindings to register kernels into both PyTorch (for AOT) and
# Executorch (for runtime). Here select all ops in functions.yaml
Expand All @@ -62,6 +62,6 @@ generate_bindings_for_kernels(
message("Generated files ${gen_command_sources}")

gen_operators_lib(
"xtensa_ops_lib"
"cadence_ops_lib"
KERNEL_LIBS custom_ops
DEPS aten_ops_xtensa)
DEPS aten_ops_cadence)
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,29 @@
kernel_name: torch::executor::view_copy_out

# custom ops
- func: xtensa::quantize_per_tensor.out(Tensor input, float scale, int zero_point, int quant_min, int quant_max, ScalarType dtype, *, Tensor(a!) out) -> Tensor(a!)
- func: cadence::quantize_per_tensor.out(Tensor input, float scale, int zero_point, int quant_min, int quant_max, ScalarType dtype, *, Tensor(a!) out) -> Tensor(a!)
variants: function
kernels:
- arg_meta: null
kernel_name: impl::HiFi::quantize_per_tensor_out

- func: xtensa::dequantize_per_tensor.out(Tensor input, float scale, int zero_point, int quant_min, int quant_max, ScalarType dtype, *, Tensor(a!) out) -> Tensor(a!)
- func: cadence::dequantize_per_tensor.out(Tensor input, float scale, int zero_point, int quant_min, int quant_max, ScalarType dtype, *, Tensor(a!) out) -> Tensor(a!)
variants: function
kernels:
- arg_meta: null
kernel_name: impl::HiFi::dequantize_per_tensor_out

- func: xtensa::quantized_conv.out(Tensor input, Tensor weight, Tensor bias, int[] stride, SymInt[] padding, int[] dilation, int groups, int input_zero_point, Tensor weight_zero_point, Tensor bias_scale, float out_scale, int out_zero_point, Tensor out_multiplier, Tensor out_shift, bool channel_last=False, *, Tensor(a!) out) -> Tensor(a!)
- func: cadence::quantized_conv.out(Tensor input, Tensor weight, Tensor bias, int[] stride, SymInt[] padding, int[] dilation, int groups, int input_zero_point, Tensor weight_zero_point, Tensor bias_scale, float out_scale, int out_zero_point, Tensor out_multiplier, Tensor out_shift, bool channel_last=False, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: impl::HiFi::quantized_conv_out

- func: xtensa::quantized_linear.out(Tensor src, Tensor weight, Tensor bias, float src_scale, int src_zero_point, float weight_scale, int weight_zero_point, Tensor out_multiplier, Tensor out_shift, int out_zero_point, *, Tensor(a!) out) -> Tensor(a!)
- func: cadence::quantized_linear.out(Tensor src, Tensor weight, Tensor bias, float src_scale, int src_zero_point, float weight_scale, int weight_zero_point, Tensor out_multiplier, Tensor out_shift, int out_zero_point, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: impl::HiFi::quantized_linear_out

- func: xtensa::quantized_relu.out(Tensor X, Tensor X_zero_point, *, Tensor(a!) out) -> Tensor(a!)
- func: cadence::quantized_relu.out(Tensor X, Tensor X_zero_point, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: impl::HiFi::quantized_relu_out
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import torch

from ..aot.export_example import export_xtensa_model
from ..aot.export_example import export_model


FORMAT = "[%(levelname)s %(asctime)s %(filename)s:%(lineno)s] %(message)s"
Expand Down Expand Up @@ -55,4 +55,4 @@ def forward(self, x: torch.Tensor):

example_inputs = (torch.randn(shape),)

export_xtensa_model(model, example_inputs)
export_model(model, example_inputs)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import torch

from ..aot.export_example import export_xtensa_model
from ..aot.export_example import export_model


FORMAT = "[%(levelname)s %(asctime)s %(filename)s:%(lineno)s] %(message)s"
Expand All @@ -39,4 +39,4 @@ def forward(self, x: torch.Tensor):

example_inputs = (torch.ones(shape),)

export_xtensa_model(model, example_inputs)
export_model(model, example_inputs)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from typing import Tuple

from ..aot.export_example import export_xtensa_model
from ..aot.export_example import export_model


FORMAT = "[%(levelname)s %(asctime)s %(filename)s:%(lineno)s] %(message)s"
Expand Down Expand Up @@ -66,4 +66,4 @@ def forward(
predictor_lengths,
)

export_xtensa_model(model, example_inputs)
export_model(model, example_inputs)
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 6ce0748

Please sign in to comment.