Fix code portability when looking for Dot (#153259)

When trying to plot a trace graph, Inductor checks if "dot" is installed. Currently, the code runs a "which dot" command.

By default, Windows doesn't have the "which" command. This patch replaces it with the more portable alternative.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/153259
Approved by: https://github.com/Skylion007
This commit is contained in:
Vlad K 2025-05-10 16:12:44 +00:00 committed by PyTorch MergeBot
parent 01cbf5a30a
commit 6a84fe65ec

View File

@ -12,7 +12,6 @@ import os.path
import pickle
import pstats
import shutil
import subprocess
import traceback
from collections.abc import Iterator
from typing import Any, Callable, IO, Optional, Union
@ -53,11 +52,7 @@ GRAPHVIZ_COMMAND_SCALABLE = ["dot", "-Gnslimit=2", "-Gnslimit1=2", "-Gmaxiter=50
@functools.lru_cache(None)
def has_dot() -> bool:
try:
subprocess.check_output(["which", "dot"], stderr=subprocess.PIPE)
return True
except subprocess.SubprocessError:
return False
return shutil.which("dot") is not None
def draw_buffers(