Skip to content
Open
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
12 changes: 12 additions & 0 deletions backends/arm/quantizer/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ runtime.python_library(
deps = [
":arm_quantizer_utils",
":quantization_annotator",
":quantizer_support",
"//executorch/backends/arm:constants",
"//executorch/backends/arm:ethosu",
"//executorch/backends/arm:vgf",
"//executorch/backends/cortex_m/quantizer:quantizer",
"//executorch/backends/arm/tosa:specification",
"//executorch/backends/arm:arm_compile_spec",
"//caffe2:torch",
Expand Down Expand Up @@ -48,6 +50,16 @@ runtime.python_library(
],
)

runtime.python_library(
name = "quantizer_support",
srcs = ["quantizer_support.py"],
deps = [
":quantization_annotator",
"//caffe2:torch",
"//executorch/backends/cortex_m/quantizer:quantizer",
],
)

runtime.python_library(
name = "lib",
srcs = ["__init__.py"],
Expand Down
31 changes: 24 additions & 7 deletions backends/arm/quantizer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,34 @@
"""

from .quantization_config import QuantizationConfig # noqa # usort: skip
from .arm_quantizer import ( # noqa
EthosUQuantizer,
get_symmetric_a16w8_quantization_config,
get_symmetric_quantization_config,
TOSAQuantizer,
VgfQuantizer,
)

# Used in tests
from .arm_quantizer_utils import is_annotated # noqa

# Lazily import heavy quantizer classes to avoid circular imports with
# Cortex-M quantization configs.
_LAZY_EXPORTS = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_LAZY_IMPORTS?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a workaround since the import situation is a bit messy with imports across the cortex-m and arm backend. The idea is to clean this up when things have stabilized, I didn't want to move things in this commit to make the diff cleaner, I hope this is OK.

"EthosUQuantizer": "executorch.backends.arm.quantizer.arm_quantizer",
"get_symmetric_a16w8_quantization_config": "executorch.backends.arm.quantizer.arm_quantizer",
"get_symmetric_quantization_config": "executorch.backends.arm.quantizer.arm_quantizer",
"TOSAQuantizer": "executorch.backends.arm.quantizer.arm_quantizer",
"VgfQuantizer": "executorch.backends.arm.quantizer.arm_quantizer",
}


def __getattr__(name: str):
if name not in _LAZY_EXPORTS:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
import importlib

module = importlib.import_module(_LAZY_EXPORTS[name])
return getattr(module, name)


def __dir__():
return sorted(list(globals().keys()) + list(_LAZY_EXPORTS.keys()))


# Load quantized ops library.
try:
import executorch.extension.pybindings.portable_lib
Expand Down
Loading
Loading