pytorch / pytorch/executorch

Vulkan partially delegated, decomposed cross product gives incorrect outputs

Open
#12,230 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

When torch linalg cross products ops are present in a Vulkan delegated model, the cross product gets decomposed and then partially delegated. It gives outputs that do not match eager. The model gives corrects results with no delegation.

May be related to https://github.com/pytorch/executorch/issues/12222.

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 LinalgCrossModel(torch.nn.Module):
    def __init__(
        self,
        dim: int = -1
    ):
        super().__init__()
        self.dim = dim
        
    def forward(self, x, y):
        return torch.linalg.cross(x, y, dim=self.dim)
        
model = LinalgCrossModel()
inputs = (
    torch.randn(3),
    torch.randn(3)
)
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([ 6.0440e-01,  1.6187e-04, -1.7365e-01]), tensor([-0.8563, -0.7608,  1.6770]))
Eager: tensor([-0.1318, -0.8649, -0.4597])
ET:    tensor([ 0.8649,  0.0000, -0.4597])
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

Start by running the provided LinalgCrossModel reproducer and compare eager outputs with the Executorch result. Inspect executorch.backends.vulkan.partitioner.vulkan_partitioner.VulkanPartitioner and the decomposition/lowering path for torch.linalg.cross, then verify that the delegated model matches eager output without delegation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
backend, machine-learning
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.