Skip to content

Commit

Permalink
test (finn/mobilenet): Allow tolerance of up-to 7 in output.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickfraser committed Jan 28, 2025
1 parent ef384e3 commit 43b02e5
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
reason='Issue with ORT and MobileNet export on MacOS on PyTorch >= 1.5.0')

INPUT_SIZE = (1, 3, 224, 224)
ATOL = 1e-3
ATOL = 7 # How many bitflips to tolerate in the 32-bit output
RTOL = 1e-2
SEED = 0


Expand All @@ -42,6 +43,7 @@ def test_mobilenet_v1_4b(pretrained):
# do forward pass in PyTorch/Brevitas
expected = mobilenet(torch_tensor).detach().numpy()
export_qonnx(mobilenet, input_shape=INPUT_SIZE, export_path=finn_onnx)
output_scale = mobilenet.output.bias_quant.scale() # Scale at the output
model = ModelWrapper(finn_onnx)
model = model.transform(GiveUniqueNodeNames())
model = model.transform(DoubleToSingleFloat())
Expand All @@ -53,4 +55,4 @@ def test_mobilenet_v1_4b(pretrained):
input_dict = {inp_name: numpy_tensor}
output_dict = oxe.execute_onnx(model, input_dict)
produced = output_dict[list(output_dict.keys())[0]]
assert np.isclose(produced, expected, atol=ATOL).all()
assert np.isclose(produced, expected, rtol=RTOL, atol=ATOL * output_scale).all()

0 comments on commit 43b02e5

Please sign in to comment.