Skip to content

Vulkan floor_divide gives incorrect outputs with integer divisor #12229

Open
@GregoryComer

Description

@GregoryComer

🐛 Describe the bug

Floor divide ops delegated to Vulkan give incorrect outputs when the divisor (or dividend) are not floats. When both are floats, output appears valid.

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 FloorDivideModel(torch.nn.Module):
    def __init__(self):
        super().__init__()
        
    def forward(self, x, y):
        return torch.floor_divide(x, y)
        
model = FloorDivideModel()
inputs = (
    torch.randint(-100, 100, (10, 10)).to(torch.float),
    torch.full((10, 10), 2).clone() # Divisor of 2 
)
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:

Eager: tensor([[ 14., -23.,  21.,   4., -26.,  22., -17.,  14., -21., -20.],
        [ 23.,  23.,  17., -24.,  40., -27.,  -6., -36., -44.,  11.],
        [-23.,  30., -45., -22.,  23.,  45., -15., -42.,  49.,   3.],
        [ -6.,  38.,  28.,   6., -29., -36.,  46.,   4.,   8., -26.],
        [ 49.,  -7., -45.,  18.,  36.,  18., -40.,  25.,  15.,   0.],
        [ 20., -34.,  43., -28.,  13., -48.,  20.,  18.,   0., -14.],
        [-40.,   9.,  38.,  49., -40.,  43.,  -3., -48.,  30., -10.],
        [ 13.,  32.,  -1.,  22.,  27.,  38., -35.,  35.,  15., -17.],
        [ 13., -36.,  20., -37.,  43.,  44., -34., -26.,   0.,  -8.],
        [-16.,  15.,  33., -10.,  21., -21.,  14.,  25., -31.,  26.]])
ET:    tensor([[inf, -inf, inf, inf, -inf, inf, -inf, inf, -inf, -inf],
        [inf, inf, inf, -inf, inf, -inf, -inf, -inf, -inf, inf],
        [-inf, inf, -inf, -inf, inf, inf, -inf, -inf, inf, inf],
        [-inf, inf, inf, inf, -inf, -inf, inf, inf, inf, -inf],
        [inf, -inf, -inf, inf, inf, inf, -inf, inf, inf, nan],
        [inf, -inf, inf, -inf, inf, -inf, inf, inf, nan, -inf],
        [-inf, inf, inf, inf, -inf, inf, -inf, -inf, inf, -inf],
        [inf, inf, -inf, inf, inf, inf, -inf, inf, inf, -inf],
        [inf, -inf, inf, -inf, inf, inf, -inf, -inf, nan, -inf],
        [-inf, inf, inf, -inf, inf, -inf, inf, inf, -inf, inf]])

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