Add pass to remove local_scalar_dense (#5886)
Summary: Pull Request resolved: https://github.com/pytorch/executorch/pull/5886 ## Context Scalar tensors (i.e. tensors with only 1 element) are often passed in to functions as scalars via ``` scalar_tensor[0].item() ``` This translates to the following chain in the graph ``` index_select = index_select(scalar_tensor, ...) scalar = local_scalar_dense(index_select) ``` This diff introduces a pass to remove the `local_scalar_dense` "chain" in favor of passing in the input tensor directly. Note that this replacement only occurs if the original tensor is a scalar tensor. In the Vulkan backend, these scalar tensors will be represented as symbolic integers instead of actual tensors, which is why this replacement is valid. However, it may not a valid replacement for other backends. ghstack-source-id: 246752220 Reviewed By: jorgep31415 Differential Revision: D63913432 fbshipit-source-id: 86ab48ef6a171cd631643db521e8dec041fa63e0
S
Stephen Jia committed
400fefa4cd78a0b742184a15a90ab4fc5992a810
Parent: cb12061
Committed by Facebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
on 10/8/2024, 2:12:54 PM