Vulkan divide with truncate rounding mode doesn't match eager/portable
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5k
- Forks
- 1.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 581
Description
🐛 Describe the bug
Vulkan divide ops with rounding_mode="trunc" do not match eager/portable. When rounding mode is "floor" the output matches. It's not immediately clear if this is within expected numerical bounds, but enough values are off by 1 that it looks like the computation does not match. Feel free to close this issue if this is the expected behavior.
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 forward(self, x, y):
return torch.div(x, y, rounding_mode="trunc")
model = Model()
inputs = (
torch.randn(1, 12),
torch.randn(1, 12),
)
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:
Inputs: (tensor([[ 1.3996, 0.2905, 0.9381, 0.7877, 0.5824, -0.5655, 0.3260, -0.0476,
0.2626, -0.3083, -2.1130, 0.5721]]), tensor([[-0.7415, 0.2069, -0.5097, 0.2503, 1.0457, 0.6018, -0.6957, -0.0889,
1.3877, -0.1224, -1.4198, 1.6500]]))
Eager: tensor([[-1., 1., -1., 3., 0., -0., -0., 0., 0., 2., 1., 0.]])
ET: tensor([[-2., 1., -2., 3., 0., -1., -1., 0., 0., 2., 1., 0.]])
Versions
Run on Meta internal master, Jul 3, fbcode/SwiftShader
cc @SS-JIA @manuelcandales @cbilgin
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided reproduction with the VulkanPartitioner and compare truncating division against eager and portable outputs. Then trace the Vulkan lowering path for torch.div with rounding_mode="trunc"; done means Vulkan results match the eager and portable results while floor behavior remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100