Skip to content

fix: Refactor assertions in E2E tests for Dynamo #2001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions py/torch_tensorrt/dynamo/test/test_dynamo_backend.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import torch
import timm
import pytest
import unittest

import torch_tensorrt as torchtrt
import torchvision.models as models
Expand All @@ -12,6 +13,8 @@
cosine_similarity,
)

assertions = unittest.TestCase()


@pytest.mark.unit
def test_resnet18(ir):
Expand All @@ -31,9 +34,9 @@ def test_resnet18(ir):

trt_mod = torchtrt.compile(model, **compile_spec)
cos_sim = cosine_similarity(model(input), trt_mod(input))
assert (
assertions.assertTrue(
cos_sim > COSINE_THRESHOLD,
f"Resnet18 TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
msg=f"Resnet18 TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
)

# Clean up model env
Expand Down Expand Up @@ -61,9 +64,9 @@ def test_mobilenet_v2(ir):

trt_mod = torchtrt.compile(model, **compile_spec)
cos_sim = cosine_similarity(model(input), trt_mod(input))
assert (
assertions.assertTrue(
cos_sim > COSINE_THRESHOLD,
f"Mobilenet v2 TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
msg=f"Mobilenet v2 TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
)

# Clean up model env
Expand Down Expand Up @@ -91,9 +94,9 @@ def test_efficientnet_b0(ir):

trt_mod = torchtrt.compile(model, **compile_spec)
cos_sim = cosine_similarity(model(input), trt_mod(input))
assert (
assertions.assertTrue(
cos_sim > COSINE_THRESHOLD,
f"EfficientNet-B0 TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
msg=f"EfficientNet-B0 TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
)

# Clean up model env
Expand Down Expand Up @@ -134,9 +137,9 @@ def test_bert_base_uncased(ir):
for key in model_outputs.keys():
out, trt_out = model_outputs[key], trt_model_outputs[key]
cos_sim = cosine_similarity(out, trt_out)
assert (
assertions.assertTrue(
cos_sim > COSINE_THRESHOLD,
f"HF BERT base-uncased TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
msg=f"HF BERT base-uncased TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
)

# Clean up model env
Expand Down Expand Up @@ -164,9 +167,9 @@ def test_resnet18_half(ir):

trt_mod = torchtrt.compile(model, **compile_spec)
cos_sim = cosine_similarity(model(input), trt_mod(input))
assert (
assertions.assertTrue(
cos_sim > COSINE_THRESHOLD,
f"Resnet18 Half TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
msg=f"Resnet18 Half TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
)

# Clean up model env
Expand Down