Skip to content

Vulkan squeeze errors out for negative (relative) dims #12233

Open
@GregoryComer

Description

@GregoryComer

🐛 Describe the bug

Squeeze operations on Vulkan error out when dim is negative (end-relative). Unsqueeze appears to work as expected with negative dims.

Repro:

import torch
from executorch.backends.vulkan.partitioner.vulkan_partitioner import VulkanPartitioner
from executorch.exir import to_edge_transform_and_lower, EdgeCompileConfig, to_edge
from executorch.extension.pybindings.portable_lib import _load_for_executorch_from_buffer
from typing import Callable, List, Optional, Tuple, Union

class Model(torch.nn.Module):
    def __init__(
        self,
    ):
        super().__init__()
        
    def forward(self, x):
        return torch.squeeze(x, dim=-1)
        
model = Model()
inputs = (
    torch.randn(8, 1),
)
eager_outputs = model(*inputs)

ep = torch.export.export(model.eval(), inputs)
print(ep)
lowered = to_edge_transform_and_lower(
    ep,
    partitioner=[VulkanPartitioner()],
    compile_config=EdgeCompileConfig(_check_ir_validity=False)
).to_executorch()
print(lowered.exported_program())

et_model = _load_for_executorch_from_buffer(lowered.buffer)
et_outputs = et_model([*inputs])[0]

print(f"Inputs: {inputs}")
print(f"Eager: {eager_outputs}")
print(f"ET:    {et_outputs}")

Outputs:

IndexError                                Traceback (most recent call last)
Cell In[48], line 31
     24 lowered = to_edge_transform_and_lower(
     25     ep,
     26     partitioner=[VulkanPartitioner()],
     27     compile_config=EdgeCompileConfig(_check_ir_validity=False)
     28 ).to_executorch()
     29 print(lowered.exported_program())
---> 31 et_model = _load_for_executorch_from_buffer(lowered.buffer)
     32 et_outputs = et_model([*inputs])[0]
     34 print(f"Inputs: {inputs}")
IndexError: vector::_M_range_check: __n (which is 18446744073709551615) >= this->size() (which is 2)

Versions

Run on Meta internal master, Jul 3, fbcode/SwiftShader

cc @SS-JIA @manuelcandales @cbilgin

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend testerThis bug was found by the backend test suite.module: vulkanIssues related to the Vulkan delegate and code under backends/vulkan/

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions