pytorch / pytorch/executorch

Vulkan floor_divide gives incorrect outputs with integer divisor

Open
#12,229 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backend tester module: vulkan
Dominant language
Python
Stars
5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
581

Description

🐛 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the supplied FloorDivideModel reproduction through VulkanPartitioner and compare the eager and ExecuTorch outputs. Start at the floor_divide lowering and Vulkan backend entry points shown in the example. Done means floor_divide produces outputs matching eager execution when the divisor or dividend is integer-valued, including negative values.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.