MCPcopy Create free account
hub / github.com/pytorch/executorch / validate_tensor_allclose

Method validate_tensor_allclose

examples/models/test/test_export.py:46–69  ·  view source on GitHub ↗
(
        self, eager_output, executorch_output, rtol=1e-5, atol=1e-5
    )

Source from the content-addressed store, hash-verified

44 return (eager_output, executorch_output)
45
46 def validate_tensor_allclose(
47 self, eager_output, executorch_output, rtol=1e-5, atol=1e-5
48 ):
49 self.assertTrue(
50 isinstance(eager_output, type(executorch_output)),
51 f"Outputs are not of the same type: eager type: {type(eager_output)}, executorch type: {type(executorch_output)}",
52 )
53 self.assertTrue(
54 len(eager_output) == len(executorch_output),
55 f"len(eager_output)={len(eager_output)}, len(executorch_output)={len(executorch_output)}",
56 )
57 result = True
58 for i in range(len(eager_output)):
59 result = torch.allclose(
60 eager_output[i],
61 executorch_output[i],
62 rtol=rtol,
63 atol=atol,
64 )
65 if not result:
66 print(f"eager output[{i}]: {eager_output[i]}")
67 print(f"executorch output[{i}]: {executorch_output[i]}")
68 break
69 return self.assertTrue(result)
70
71 def test_mv3_export_to_executorch(self):
72 eager_model, example_inputs, _, _ = EagerModelFactory.create_model(

Calls

no outgoing calls

Tested by

no test coverage detected