From ee468d6fb844dd67486e97105007babb4fac87d6 Mon Sep 17 00:00:00 2001 From: atalman Date: Mon, 27 Feb 2023 10:24:56 -0800 Subject: [PATCH 1/5] Add smoke test Using a simple RN50 with torch.compile --- test/smoke_test.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/smoke_test.py b/test/smoke_test.py index e8ee178d95e..3701f661add 100644 --- a/test/smoke_test.py +++ b/test/smoke_test.py @@ -26,6 +26,13 @@ def smoke_test_torchvision_read_decode() -> None: if img_png.ndim != 3 or img_png.numel() < 100: raise RuntimeError(f"Unexpected shape of img_png: {img_png.shape}") +def smoke_test_compile() -> None: + import torch.nn as nn + model = resnet50().cuda() + model = torch.compile(model) + x = torch.randn(1, 3, 224, 224).cuda() + out = model(x) + print(out.shape) def smoke_test_torchvision_resnet50_classify(device: str = "cpu") -> None: img = read_image(str(SCRIPT_DIR / ".." / "gallery" / "assets" / "dog2.jpg")).to(device) @@ -59,8 +66,12 @@ def main() -> None: smoke_test_torchvision_resnet50_classify() if torch.cuda.is_available(): smoke_test_torchvision_resnet50_classify("cuda") +<<<<<<< HEAD if torch.backends.mps.is_available(): smoke_test_torchvision_resnet50_classify("mps") +======= + smoke_test_compile() +>>>>>>> 2b8667d9a4 (Add smoke test Using a simple RN50 with torch.compile) if __name__ == "__main__": From 338dda954d12e76a094d5724533680ddcaa47d7a Mon Sep 17 00:00:00 2001 From: atalman Date: Wed, 1 Mar 2023 06:10:34 -0800 Subject: [PATCH 2/5] Apply cuda fix --- test/smoke_test.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test/smoke_test.py b/test/smoke_test.py index 3701f661add..31af998487e 100644 --- a/test/smoke_test.py +++ b/test/smoke_test.py @@ -4,6 +4,7 @@ from pathlib import Path import torch +import torch.nn as nn import torchvision from torchvision.io import read_image from torchvision.models import resnet50, ResNet50_Weights @@ -27,10 +28,9 @@ def smoke_test_torchvision_read_decode() -> None: raise RuntimeError(f"Unexpected shape of img_png: {img_png.shape}") def smoke_test_compile() -> None: - import torch.nn as nn model = resnet50().cuda() model = torch.compile(model) - x = torch.randn(1, 3, 224, 224).cuda() + x = torch.randn(1, 3, 224, 224, device="cuda") out = model(x) print(out.shape) @@ -66,12 +66,10 @@ def main() -> None: smoke_test_torchvision_resnet50_classify() if torch.cuda.is_available(): smoke_test_torchvision_resnet50_classify("cuda") -<<<<<<< HEAD + smoke_test_compile() if torch.backends.mps.is_available(): smoke_test_torchvision_resnet50_classify("mps") -======= - smoke_test_compile() ->>>>>>> 2b8667d9a4 (Add smoke test Using a simple RN50 with torch.compile) + if __name__ == "__main__": From ff61cd0e6ba653bdc4162781028834ed0d220dfa Mon Sep 17 00:00:00 2001 From: atalman Date: Wed, 1 Mar 2023 06:23:10 -0800 Subject: [PATCH 3/5] torch.compile output --- test/smoke_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/smoke_test.py b/test/smoke_test.py index 31af998487e..5d03b393bbc 100644 --- a/test/smoke_test.py +++ b/test/smoke_test.py @@ -32,7 +32,7 @@ def smoke_test_compile() -> None: model = torch.compile(model) x = torch.randn(1, 3, 224, 224, device="cuda") out = model(x) - print(out.shape) + print(f"torch.compile output: {out.shape}") def smoke_test_torchvision_resnet50_classify(device: str = "cpu") -> None: img = read_image(str(SCRIPT_DIR / ".." / "gallery" / "assets" / "dog2.jpg")).to(device) From db6fbf0493af80a3e0063a8543f40aaa13bc9b66 Mon Sep 17 00:00:00 2001 From: atalman Date: Wed, 1 Mar 2023 06:47:16 -0800 Subject: [PATCH 4/5] Make sure we have result of new test --- test/smoke_test.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/smoke_test.py b/test/smoke_test.py index 5d03b393bbc..50f941a054f 100644 --- a/test/smoke_test.py +++ b/test/smoke_test.py @@ -32,7 +32,7 @@ def smoke_test_compile() -> None: model = torch.compile(model) x = torch.randn(1, 3, 224, 224, device="cuda") out = model(x) - print(f"torch.compile output: {out.shape}") + print(f"torch.compile model output: {out.shape}") def smoke_test_torchvision_resnet50_classify(device: str = "cpu") -> None: img = read_image(str(SCRIPT_DIR / ".." / "gallery" / "assets" / "dog2.jpg")).to(device) @@ -61,12 +61,14 @@ def smoke_test_torchvision_resnet50_classify(device: str = "cpu") -> None: def main() -> None: print(f"torchvision: {torchvision.__version__}") + print(f"torch.cuda.is_available: {torch.cuda.is_available()}") smoke_test_torchvision() + smoke_test_compile() smoke_test_torchvision_read_decode() smoke_test_torchvision_resnet50_classify() if torch.cuda.is_available(): smoke_test_torchvision_resnet50_classify("cuda") - smoke_test_compile() + if torch.backends.mps.is_available(): smoke_test_torchvision_resnet50_classify("mps") From 87424abeb8d947fd9a2c52ff1b220514d19f4d63 Mon Sep 17 00:00:00 2001 From: atalman Date: Wed, 1 Mar 2023 07:09:24 -0800 Subject: [PATCH 5/5] Fix smoke test --- test/smoke_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/smoke_test.py b/test/smoke_test.py index 50f941a054f..9ffc9117773 100644 --- a/test/smoke_test.py +++ b/test/smoke_test.py @@ -63,11 +63,11 @@ def main() -> None: print(f"torchvision: {torchvision.__version__}") print(f"torch.cuda.is_available: {torch.cuda.is_available()}") smoke_test_torchvision() - smoke_test_compile() smoke_test_torchvision_read_decode() smoke_test_torchvision_resnet50_classify() if torch.cuda.is_available(): smoke_test_torchvision_resnet50_classify("cuda") + smoke_test_compile() if torch.backends.mps.is_available(): smoke_test_torchvision_resnet50_classify("mps")