Skip to content

Commit

Permalink
Make transfer_to_logical_device copy the tensor during eager execution (
Browse files Browse the repository at this point in the history
#239)

Currently eager and generate don't have the same semantics. Generate
would create a new value while in eager we return the same tensor.
It is desirable to have the same behavior in both paths, this will allow
us to catch in-place errors on the torch level and not during IREE
execution.
The only downside is that during eager it will be slower. This is far
less of headache.

Signed-off-by: Boian Petkantchin <boian.petkantchin@amd.com>
  • Loading branch information
sogartar authored Oct 23, 2024
1 parent ae9a51c commit 00dcee7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion iree/turbine/ops/iree.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def select(self, ksel: KernelSelection):
ksel.return_tensor(ta.t).specialize_dims(*spec)

def eager_execute(self, device_moniker, tensor):
return tensor
return tensor.clone()

def generate(self, ksel: KernelSelection, kb: KernelBuilder):
moniker = cast(AttrArg, ksel.arg_descs[0]).v
Expand Down
2 changes: 1 addition & 1 deletion tests/ops/iree_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TransferToLogicalDeviceTest(unittest.TestCase):
def testEager(self):
t1 = torch.randn(3, 4)
t2 = ops.iree.transfer_to_logical_device("1", t1)
self.assertIs(t1, t2)
assert torch.all(t1 == t2)

def testAOT(self):
class MyModule(nn.Module):
Expand Down

0 comments on commit 00dcee7

Please sign in to comment.