From c09fe87ab004e0ee764d21d3c4f2799bacec2646 Mon Sep 17 00:00:00 2001 From: Wei Lu Date: Thu, 25 Jul 2024 19:36:46 -0700 Subject: [PATCH] remove unused tensors from VK model's graph (#4427) Summary: Pull Request resolved: https://github.com/pytorch/executorch/pull/4427 We implemented [operators fusion](https://github.com/pytorch/executorch/pull/3769?fbclid=IwZXh0bgNhZW0CMTEAAR3kYya0wRrkupmV86OpPZZ9_QhqLYEmNrKcJk5Jj_4VSO_WqvFsbWNigTs_aem_gQeSu2zvazf_hpy3RsIXhg) (`conv+bn`) which fused `conv` and `bn`'s weights and biases, but the old parameters are not deleted. Hence we saw that VK model's size is nearly twice large as CPU's. As regards mobilenet_v2, before this diff CPU vs VK: 14M vs 22M. After this diff, both of them have 14M. Reviewed By: SS-JIA Differential Revision: D60257047 --- backends/vulkan/serialization/vulkan_graph_builder.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backends/vulkan/serialization/vulkan_graph_builder.py b/backends/vulkan/serialization/vulkan_graph_builder.py index 477e54a2d7..da40f0a720 100644 --- a/backends/vulkan/serialization/vulkan_graph_builder.py +++ b/backends/vulkan/serialization/vulkan_graph_builder.py @@ -262,6 +262,9 @@ def get_or_create_value_for(self, arg: _Argument): raise RuntimeError(f"Cannot create value for arg of type {type(arg)}") def process_placeholder_node(self, node: Node) -> None: + # ignores any tensors that don't get used in any ops + if len(node.users) == 0: + return None ids = self.create_node_value(node) if not self.is_param_node(node): if isinstance(ids, int):