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

Function compare_outputs

examples/apple/mps/scripts/bench_utils.py:81–108  ·  view source on GitHub ↗
(
    executorch_program: ExportedProgram,
    model: torch.nn.Module,
    inputs: Tuple[torch.tensor],
    model_name: str,
    use_fp16: bool,
)

Source from the content-addressed store, hash-verified

79
80
81def compare_outputs(
82 executorch_program: ExportedProgram,
83 model: torch.nn.Module,
84 inputs: Tuple[torch.tensor],
85 model_name: str,
86 use_fp16: bool,
87):
88 test_module = TestMPS()
89 inputs_copy = []
90 if use_fp16:
91 model = model.to(torch.float16)
92 model = model
93 for t in inputs:
94 tensor = t.detach().clone()
95 if use_fp16 and tensor.dtype == torch.float32:
96 tensor = tensor.to(torch.float16)
97 inputs_copy.append(tensor)
98 inputs_copy = tuple(inputs_copy)
99
100 pytorch_results = model(*inputs_copy)
101
102 executorch_model = get_executorch_model(executorch_program)
103 if executorch_model is not None:
104 executorch_results = executorch_model.forward(inputs)
105 test_module.assert_outputs_equal(executorch_results, pytorch_results, use_fp16)
106 logging.info(
107 f"Results between ExecuTorch forward pass with MPS backend and PyTorch forward pass for {model_name} are matching!"
108 )

Callers 1

mps_example.pyFile · 0.90

Calls 8

assert_outputs_equalMethod · 0.95
TestMPSClass · 0.90
get_executorch_modelFunction · 0.85
cloneMethod · 0.80
infoMethod · 0.80
toMethod · 0.45
appendMethod · 0.45
forwardMethod · 0.45

Tested by

no test coverage detected