From 2b2c6810ac7dcccd649c40f54c0ff4e6b3859811 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Mon, 9 Sep 2024 13:26:14 -0700 Subject: [PATCH 1/2] [ExecuTorch] Preserve undelegated Linear ops in Llama demo export Allows us to use optimized op_linear from the previous diff. Differential Revision: [D62262532](https://our.internmc.facebook.com/intern/diff/D62262532/) [ghstack-poisoned] --- extension/llm/export/builder.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/extension/llm/export/builder.py b/extension/llm/export/builder.py index 4237ae7b3a7..338d997297d 100644 --- a/extension/llm/export/builder.py +++ b/extension/llm/export/builder.py @@ -16,6 +16,7 @@ from executorch.backends.transforms.duplicate_dynamic_quant_chain import ( DuplicateDynamicQuantChainPass, ) +from executorch.backends.xnnpack.passes.convert_to_linear import ConvertToLinearPass from executorch.exir import EdgeProgramManager from executorch.exir.backend.partitioner import Partitioner @@ -382,6 +383,10 @@ def to_executorch(self) -> "LLMEdgeManager": ExecutorchBackendConfig( extract_delegate_segments=True, passes=[ + # If there are Linear operations left in the graph, let's execute + # them with the optimized op_linear rather than materializing a + # transpose followed by a regular op_mm. + ConvertToLinearPass(), QuantFusionPass(), ], memory_planning_pass=MemoryPlanningPass( From 67feefb23d38ffe90cde503e9dcb13dcf5fdc9aa Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Mon, 9 Sep 2024 16:15:59 -0700 Subject: [PATCH 2/2] Update base for Update on "[ExecuTorch] Preserve undelegated Linear ops in Llama demo export" Allows us to use optimized op_linear from the previous diff. Differential Revision: [D62262532](https://our.internmc.facebook.com/intern/diff/D62262532/) [ghstack-poisoned] --- kernels/optimized/optimized-oss.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernels/optimized/optimized-oss.yaml b/kernels/optimized/optimized-oss.yaml index f79d652b91d..797744f3bd4 100644 --- a/kernels/optimized/optimized-oss.yaml +++ b/kernels/optimized/optimized-oss.yaml @@ -45,6 +45,11 @@ - arg_meta: null kernel_name: torch::executor::opt_le_tensor_out +- op: linear.out + kernels: + - arg_meta: null + kernel_name: torch::executor::opt_linear_out + - op: mul.out kernels: - arg_meta: null