Skip to content

Commit

Permalink
add comparison of pcc/atol of all outputs
Browse files Browse the repository at this point in the history
add _extract_outputs function to ModelTester that subclasses may need to
implement. This function should return a tuple of torch.Tensors

Trim unused code in tests/utils.py

move verify_against_golden to verify.py

replace self.model with self.framework_model and self.compiled_model
  • Loading branch information
LPanosTT committed Jan 10, 2025
1 parent c14f359 commit 8bb73bc
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 572 deletions.
2 changes: 1 addition & 1 deletion tests/models/MobileNetV2/test_MobileNetV2.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_MobileNetV2(record_property, mode, nightly):
else:
cc.compile_depth = CompileDepth.TTNN_IR

tester = ThisTester(model_name, mode, compiler_config=cc)
tester = ThisTester(model_name, mode, compiler_config=cc, required_atol=0.03)
results = tester.test_model()
if mode == "eval":
# Print the top 5 predictions
Expand Down
11 changes: 9 additions & 2 deletions tests/models/beit/test_beit_image_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def append_fake_loss_function(self, outputs):
def get_results_train(self, model, inputs, outputs):
return inputs["pixel_values"].grad

def _extract_outputs(self, output_object):
return (output_object.logits,)


@pytest.mark.parametrize(
"mode",
Expand All @@ -57,14 +60,18 @@ def test_beit_image_classification(record_property, model_name, mode, nightly):
else:
cc.compile_depth = CompileDepth.TTNN_IR

tester = ThisTester(model_name, mode, compiler_config=cc)
atol = 0.05
tester = ThisTester(model_name, mode, compiler_config=cc, required_atol=atol)
results = tester.test_model()

if mode == "eval":
logits = results.logits

# model predicts one of the 1000 ImageNet classes
predicted_class_idx = logits.argmax(-1).item()
print("Predicted class:", tester.model.config.id2label[predicted_class_idx])
print(
"Predicted class:",
tester.framework_model.config.id2label[predicted_class_idx],
)

record_property("torch_ttnn", (tester, results))
5 changes: 4 additions & 1 deletion tests/models/mgp-str-base/test_mgp_str_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def _load_inputs(self):
inputs["pixel_values"] = inputs["pixel_values"].to(torch.bfloat16)
return inputs

def _extract_outputs(self, output_object):
return output_object.logits


@pytest.mark.parametrize(
"mode",
Expand All @@ -52,7 +55,7 @@ def test_mgp_str_base(record_property, mode, nightly):
else:
cc.compile_depth = CompileDepth.TTNN_IR

tester = ThisTester(model_name, mode, compiler_config=cc)
tester = ThisTester(model_name, mode, relative_atol=0.02, compiler_config=cc)
results = tester.test_model()

if mode == "eval":
Expand Down
6 changes: 4 additions & 2 deletions tests/models/openpose/test_openpose_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ def get_image_tensor():
return input_batch


# NOTE: If we are to decompose BatchNorm2d (which we must in order to lower to SHLO)
# we need to run in float32 to maintain precision.
class ThisTester(ModelTester):
def _load_model(self):
# Create PyBuda module from PyTorch model
model = ptcv_get_model("lwopenpose2d_mobilenet_cmupan_coco", pretrained=True)
model = model.to(torch.bfloat16)
model = model.to(torch.float32)
return model

def _load_inputs(self):
input_batch = [get_image_tensor()]
batch_input = torch.cat(input_batch, dim=0)
batch_input = batch_input.to(torch.bfloat16)
batch_input = batch_input.to(torch.float32)
return batch_input


Expand Down
5 changes: 4 additions & 1 deletion tests/models/perceiver_io/test_perceiver_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def _load_inputs(self):
}
return arguments

def _extract_outputs(self, output_object):
return (output_object.logits,)


@pytest.mark.parametrize(
"mode",
Expand All @@ -52,7 +55,7 @@ def test_perceiver_io(record_property, mode, nightly):
else:
cc.compile_depth = CompileDepth.TTNN_IR

tester = ThisTester(model_name, mode, compiler_config=cc)
tester = ThisTester(model_name, mode, relative_atol=0.02, compiler_config=cc)
results = tester.test_model()
if mode == "eval":
logits = results.logits
Expand Down
3 changes: 3 additions & 0 deletions tests/models/squeeze_bert/test_squeeze_bert.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def _load_inputs(self):
inputs = self.tokenizer("Hello, my dog is cute", return_tensors="pt")
return inputs

def _extract_outputs(self, output_object):
return (output_object.logits,)


@pytest.mark.parametrize(
"mode",
Expand Down
Loading

0 comments on commit 8bb73bc

Please sign in to comment.