(
executorch_program: ExportedProgram,
model: torch.nn.Module,
inputs: Tuple[torch.tensor],
model_name: str,
use_fp16: bool,
)
| 79 | |
| 80 | |
| 81 | def 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 | ) |
no test coverage detected