From 0a79fd1cc4e45a1bcdf2443204ebad7139c9a1fb Mon Sep 17 00:00:00 2001 From: Max Ren Date: Thu, 9 May 2024 10:08:43 -0700 Subject: [PATCH] Break flag bc (#3128) Summary: Pull Request resolved: https://github.com/pytorch/executorch/pull/3128 XNNPACK broke Backwards Compatibility by forcing pooling operations to reduce dims, and introducing a flag to allow these operation to keep the dims. This is backwards breaking because previously XNNPACK would not keep the dims if no flag was given, now a flag must be specified to keep the dims. While initially we proposed the inverse to maintain backwards compatibility, they have encountered breakages and have decided to commit to this breakage. As we are a downstream dependency, and will have to accept this breakages ourselves, it is important that we break early before this is used in any production code. As a result we break BC Here by accepting XNNPACK's change. ``` git diff roll_back_commit > rollback.patch cd fbsource/fbcode/xplat/third-party/XNNPACK/XNNPACK git apply ../../../../../../rollback.patch ``` We have to update the change in ExecuTorch, as a result we change the XNNPACK dep we are pointing to the branch containing these changes here: https://github.com/digantdesai/XNNPACK/commits/et_v21/ Reviewed By: digantdesai Differential Revision: D56271242 --- backends/xnnpack/operators/op_avg_pooling2d.py | 3 ++- backends/xnnpack/operators/op_max_pool2d.py | 3 ++- backends/xnnpack/operators/op_mean_dim.py | 3 ++- backends/xnnpack/third-party/XNNPACK | 2 +- backends/xnnpack/utils/xnnpack_constants.py | 12 ++++++++---- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/backends/xnnpack/operators/op_avg_pooling2d.py b/backends/xnnpack/operators/op_avg_pooling2d.py index 18f981cb330..94cd06cc08e 100644 --- a/backends/xnnpack/operators/op_avg_pooling2d.py +++ b/backends/xnnpack/operators/op_avg_pooling2d.py @@ -16,6 +16,7 @@ XNNGraph, XNode, ) +from executorch.backends.xnnpack.utils.xnnpack_constants import XNN_FLAG_KEEP_DIMS @register_node_visitor @@ -67,7 +68,7 @@ def define_node( dilation_width=0, # Unused input_id=input_id, output_id=output_id, - flags=0, + flags=XNN_FLAG_KEEP_DIMS, ), debug_handle=debug_handle, ) diff --git a/backends/xnnpack/operators/op_max_pool2d.py b/backends/xnnpack/operators/op_max_pool2d.py index 6fb49d30d57..d1a010295ef 100644 --- a/backends/xnnpack/operators/op_max_pool2d.py +++ b/backends/xnnpack/operators/op_max_pool2d.py @@ -18,6 +18,7 @@ XNNMaxPooling2d, XNode, ) +from executorch.backends.xnnpack.utils.xnnpack_constants import XNN_FLAG_KEEP_DIMS @register_node_visitor @@ -80,7 +81,7 @@ def define_node( kwargs["dilation_height"] = dilation[0] kwargs["dilation_width"] = dilation[1] - kwargs["flags"] = 0 + kwargs["flags"] = XNN_FLAG_KEEP_DIMS ser_node = XNode( xnode_union=XNNMaxPooling2d( diff --git a/backends/xnnpack/operators/op_mean_dim.py b/backends/xnnpack/operators/op_mean_dim.py index fe9f2249631..663606a8880 100644 --- a/backends/xnnpack/operators/op_mean_dim.py +++ b/backends/xnnpack/operators/op_mean_dim.py @@ -18,6 +18,7 @@ XNNGraph, XNode, ) +from executorch.backends.xnnpack.utils.xnnpack_constants import XNN_FLAG_KEEP_DIMS @register_node_visitor @@ -70,7 +71,7 @@ def define_node( ser_node = XNode( xnode_union=XNNGlobalAvgPooling2d( - input_id=input_id, output_id=output_id, flags=0 + input_id=input_id, output_id=output_id, flags=XNN_FLAG_KEEP_DIMS ), debug_handle=debug_handle, ) diff --git a/backends/xnnpack/third-party/XNNPACK b/backends/xnnpack/third-party/XNNPACK index 70bbd07c1de..20c0d886fb7 160000 --- a/backends/xnnpack/third-party/XNNPACK +++ b/backends/xnnpack/third-party/XNNPACK @@ -1 +1 @@ -Subproject commit 70bbd07c1de310a1f89379c746b8f24a506c3283 +Subproject commit 20c0d886fb78d6497362e8303b999bf5d67aaa02 diff --git a/backends/xnnpack/utils/xnnpack_constants.py b/backends/xnnpack/utils/xnnpack_constants.py index 63c8d6fdeef..351cc8ad897 100644 --- a/backends/xnnpack/utils/xnnpack_constants.py +++ b/backends/xnnpack/utils/xnnpack_constants.py @@ -8,21 +8,25 @@ UINT32_MAX = 4294967295 XNN_EXTRA_BYTES = 16 XNN_MAX_TENSOR_DIMS = 6 -XNN_FLAG_SPARSE_INFERENCE = 0x00000001 -XNN_FLAG_HINT_SPARSE_INFERENCE = XNN_FLAG_SPARSE_INFERENCE -XNN_FLAG_FP16_INFERENCE = 0x00000002 -XNN_FLAG_HINT_FP16_INFERENCE = XNN_FLAG_FP16_INFERENCE +XNN_FLAG_HINT_SPARSE_INFERENCE = 0x00000001 +XNN_FLAG_HINT_FP16_INFERENCE = 0x00000002 XNN_FLAG_FORCE_FP16_INFERENCE = 0x00000004 XNN_FLAG_BASIC_PROFILING = 0x00000008 +XNN_FLAG_JIT = 0x00000010 XNN_FLAG_DEPTHWISE_CONVOLUTION = 0x00000001 XNN_FLAG_TRANSPOSE_WEIGHTS = 0x00000001 XNN_FLAG_INPUT_NHWC = 0x00000002 XNN_FLAG_TENSORFLOW_SAME_PADDING = 0x00000004 +XNN_FLAG_TRANSPOSE_B = XNN_FLAG_TRANSPOSE_WEIGHTS +XNN_FLAG_TRANSPOSE_A = 0x00000002 XNN_FLAG_TENSORFLOW_RESHAPE_2D = 0x00000004 XNN_FLAG_TENSORFLOW_LEGACY_MODE = 0x00000004 XNN_FLAG_FP32_STATIC_WEIGHTS = 0x00000008 XNN_FLAG_ALIGN_CORNERS = 0x00000008 XNN_FLAG_YIELD_WORKERS = 0x00000010 +XNN_FLAG_TRANSIENT_INDIRECTION_BUFFER = 0x00000020 +XNN_FLAG_KEEP_DIMS = 0x00000040 +XNN_EXTRA_QUANTIZATION_PARAMS = 8 XNN_VALUE_FLAG_EXTERNAL_INPUT = 0x00000001 XNN_VALUE_FLAG_EXTERNAL_OUTPUT = 0x00000002 XNN_VALUE_FLAG_PERSISTENT = 0x00000004