Skip to content

Commit

Permalink
Use temporary files to dump runtime stack
Browse files Browse the repository at this point in the history
  • Loading branch information
mmanzoorTT committed Jan 7, 2025
1 parent a6f26f0 commit 16c3a26
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions tt_torch/dynamo/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
import multiprocessing as mp
import time
import faulthandler
import re
import sys
import tempfile


def import_graph(graph: torch.fx.GraphModule):
Expand Down Expand Up @@ -269,9 +271,9 @@ def run_op(self, binary, *inputs):
receiver = mp.Queue()
obj = {"binary": binary, "inputs": inputs}

stderr_file_name = "stderr.txt"
f_stderr = tempfile.TemporaryFile(mode="w+t")
old_stderr = sys.stderr
sys.stderr = f_stderr = open(stderr_file_name, "w")
sys.stderr = f_stderr

exec_event = mp.Event()
process = mp.Process(
Expand Down Expand Up @@ -302,13 +304,13 @@ def run_op(self, binary, *inputs):
outputs = outputs[0]

sys.stderr = old_stderr
f_stderr.close()
stderr_data = ""
if outputs is None:
f_stderr = open(stderr_file_name, "r")
f_stderr.seek(0)
stderr_data = f_stderr.read()
f_stderr.close()
os.unlink(stderr_file_name)
stderr_data = stderr_data.replace("\n", "\\n")
stderr_data = re.sub(r"[^\x20-\x7E]", "", stderr_data)
f_stderr.close()

return outputs, stderr_data

Expand Down

0 comments on commit 16c3a26

Please sign in to comment.