Skip to content

Check that ET and Eager are numericaly equivalent #4779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions exir/tests/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ python_unittest(
deps = [
"//caffe2:torch",
"//executorch/exir:lib",
"//executorch/extension/pybindings:portable_lib",
],
)

Expand Down Expand Up @@ -209,6 +210,7 @@ python_unittest(
"//executorch/exir/passes:debug_handle_generator_pass",
"//executorch/exir/passes:insert_write_back_for_buffers_pass",
"//executorch/exir/passes:lib",
"//executorch/exir/passes:memory_format_ops_pass",
"//executorch/exir/passes:normalize_view_copy_base_pass",
"//executorch/exir/passes:remove_graph_asserts_pass",
"//executorch/exir/passes:remove_mixed_type_operators",
Expand Down
19 changes: 19 additions & 0 deletions exir/tests/test_joint_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
import torch._dynamo

from executorch.exir import to_edge

from executorch.extension.pybindings.portable_lib import (
_load_for_executorch_from_buffer,
)
from torch.export._trace import _export
from torch.export.experimental import _export_forward_backward
from torch.export.exported_program import OutputKind
Expand Down Expand Up @@ -89,3 +93,18 @@ def forward(self, x, y):
.val.allocation_info.memory_offset_low,
48,
)

loss = m(*example_inputs)
loss.backward()
et_mod = _load_for_executorch_from_buffer(et.buffer)
et_outputs = et_mod.forward(
example_inputs
) # ET outputs are [loss, grads, weights]

self.assertTrue(torch.allclose(loss, et_outputs[0]))
self.assertTrue(
torch.allclose(m.linear.weight.grad, et_outputs[1]) # pyre-ignore[6]
)
self.assertTrue(torch.allclose(m.linear.bias.grad, et_outputs[2]))
self.assertTrue(torch.allclose(m.linear.weight, et_outputs[3]))
self.assertTrue(torch.allclose(m.linear.bias, et_outputs[4]))
Loading