Skip to content

Commit

Permalink
reproducer tests: grab output/error, and use the correct python (#1554)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and riccardofelluga committed Jan 27, 2025
1 parent 6c068f2 commit 7deee09
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions thunder/tests/test_dynamo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import warnings
import itertools
import os
from subprocess import run
import subprocess
import sys
import torch
import torch.fx
import torch.nn as nn
Expand Down Expand Up @@ -850,12 +851,16 @@ def func(x):
s2 = f"{tmp_path}/graph1_thunder_0.py"
assert os.path.exists(s1)
assert os.path.exists(s2)
cmd = "pytest" if use_pytest_benchmark else "python"
result1 = run([cmd, s1], capture_output=True, text=True)
result2 = run([cmd, s2], capture_output=True, text=True)
cmd = [sys.executable]
if use_pytest_benchmark:
cmd = cmd + ["-m", "pytest"]
cmd1 = cmd + [s1]
cmd2 = cmd + [s2]
result1 = subprocess.run(cmd1, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
result2 = subprocess.run(cmd2, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)

assert result1.returncode == 0, f"Reproducer {s1} failed with return code {result1.returncode}"
assert result2.returncode == 0, f"Reproducer {s2} failed with return code {result2.returncode}"
assert result1.returncode == 0, f"Reproducer {s1} failed: {result1}"
assert result2.returncode == 0, f"Reproducer {s2} failed: {result2}"


@requiresCUDA
Expand Down Expand Up @@ -883,9 +888,12 @@ def forward(self, x):

s1 = f"{tmp_path}/graph0_thunder_0.py"
assert os.path.exists(s1)
cmd = "pytest" if use_pytest_benchmark else "python"
result1 = run([cmd, s1], capture_output=True, text=True)
assert result1.returncode == 0, f"Reproducer {s1} failed with return code {result1.returncode}"
cmd = [sys.executable]
if use_pytest_benchmark:
cmd = cmd + ["-m", "pytest"]
cmd1 = cmd + [s1]
result1 = subprocess.run(cmd1, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
assert result1.returncode == 0, f"Reproducer {s1} failed: {result1}"


def test_deepcopy_graph_module():
Expand Down Expand Up @@ -940,13 +948,16 @@ def func(x):

def check(file_name, cmd):
assert os.path.exists(file_name)
result = run([cmd, file_name], capture_output=True, text=True)
assert result.returncode == 0, f"Reproducer {file_name} failed with return code {result.returncode}"
cmd = cmd + [file_name]
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
assert result.returncode == 0, f"Reproducer {file_name} failed: {result}"

s1 = f"{tmp_path}/graph0_thunder_0.py"
s2 = f"{tmp_path}/graph0_thunder_2.py"
s3 = f"{tmp_path}/graph0_thunder_4.py"
cmd = "pytest" if use_pytest_benchmark else "python"
cmd = [sys.executable]
if use_pytest_benchmark:
cmd = cmd + ["-m", "pytest"]
for fname in [s1, s2, s3]:
check(fname, cmd)

Expand Down

0 comments on commit 7deee09

Please sign in to comment.