diff --git a/backends/xnnpack/runtime/XNNCompiler.cpp b/backends/xnnpack/runtime/XNNCompiler.cpp index 0c1c9e6d42c..8498bd84c5f 100644 --- a/backends/xnnpack/runtime/XNNCompiler.cpp +++ b/backends/xnnpack/runtime/XNNCompiler.cpp @@ -1517,6 +1517,7 @@ __ET_NODISCARD Error XNNCompiler::compileModel( if (!executor->qinputs_.empty() && flatbuffer_graph->xnodes()->size() > 0 && flatbuffer_graph->xnodes()->Get(0)->xnode_union_type() == fb_xnnpack::XNodeUnion::XNNFullyConnected) { +#ifdef ENABLE_DYNAMIC_QUANTIZATION // This delegate is for DQLinear which supports dynamic input shapes if (executor->getNumInputs() < 1 || executor->getNumOutputs() != 1) { ET_LOG( @@ -1525,6 +1526,10 @@ __ET_NODISCARD Error XNNCompiler::compileModel( return Error::NotSupported; } executor->setNeedsResizeOutput(); +#else + ET_LOG(Error, "DQ Linear is not supported"); + return Error::NotSupported; +#endif } return err; diff --git a/backends/xnnpack/runtime/XNNExecutor.cpp b/backends/xnnpack/runtime/XNNExecutor.cpp index 5e39c86c1ba..30b60ee329d 100644 --- a/backends/xnnpack/runtime/XNNExecutor.cpp +++ b/backends/xnnpack/runtime/XNNExecutor.cpp @@ -7,7 +7,9 @@ */ #include +#ifdef ENABLE_DYNAMIC_QUANTIZATION #include +#endif namespace torch { namespace executor { @@ -17,6 +19,7 @@ namespace delegate { Error XNNExecutor::set_external_input(uint32_t id, Tensor* input) { auto qinput_pair = qinputs_.find(id); if (qinput_pair != qinputs_.end()) { +#ifdef ENABLE_DYNAMIC_QUANTIZATION auto qinput = qinput_pair->second; // dq the input and copy it in to qinput float input_min, input_max; @@ -60,6 +63,10 @@ Error XNNExecutor::set_external_input(uint32_t id, Tensor* input) { {static_cast(input_qparam.scale), static_cast(input_qparam.zero_point)}, batch_size}); +#else + ET_LOG(Error, "Dynamic Quantization is not supported"); + return Error::NotSupported; +#endif } else { externals_.emplace_back(xnn_external_value{id, input->mutable_data_ptr()}); } diff --git a/backends/xnnpack/targets.bzl b/backends/xnnpack/targets.bzl index 6df70f654aa..0f80af77cd0 100644 --- a/backends/xnnpack/targets.bzl +++ b/backends/xnnpack/targets.bzl @@ -65,6 +65,7 @@ def define_common_targets(): "//executorch/extension/pybindings/...", "@EXECUTORCH_CLIENTS", ], + preprocessor_flags = [] if runtime.is_oss else ["-DENABLE_DYNAMIC_QUANTIZATION"], deps = [ third_party_dep("XNNPACK"), ":xnnpack_schema",