load rocm.py only when needed

Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
Vladimir Mandic
2025-10-18 08:31:28 -04:00
parent a36916616f
commit c8ca5cd75c
2 changed files with 29 additions and 21 deletions
+11 -5
View File
@@ -887,7 +887,6 @@ def check_torch():
if args.profile:
pr = cProfile.Profile()
pr.enable()
from modules import rocm
allow_cuda = not (args.use_rocm or args.use_directml or args.use_ipex or args.use_openvino)
allow_rocm = not (args.use_cuda or args.use_directml or args.use_ipex or args.use_openvino)
allow_ipex = not (args.use_cuda or args.use_rocm or args.use_directml or args.use_openvino)
@@ -904,11 +903,17 @@ def check_torch():
log.error('DirectML is only supported on Windows')
if torch_command != '':
pass
is_cuda_available = False
is_ipex_available = False
is_rocm_available = False
else:
is_cuda_available = allow_cuda and (args.use_cuda or shutil.which('nvidia-smi') is not None or args.use_xformers or os.path.exists(os.path.join(os.environ.get('SystemRoot') or r'C:\Windows', 'System32', 'nvidia-smi.exe')))
is_rocm_available = allow_rocm and (args.use_rocm or args.use_zluda or rocm.is_installed)
is_cuda_available = allow_cuda and (args.use_cuda or shutil.which('nvidia-smi') is not None or os.path.exists(os.path.join(os.environ.get('SystemRoot') or r'C:\Windows', 'System32', 'nvidia-smi.exe')))
is_ipex_available = allow_ipex and (args.use_ipex or shutil.which('sycl-ls') is not None or shutil.which('sycl-ls.exe') is not None or os.environ.get('ONEAPI_ROOT') is not None or os.path.exists('/opt/intel/oneapi') or os.path.exists("C:/Program Files (x86)/Intel/oneAPI") or os.path.exists("C:/oneAPI") or os.path.exists("C:/Program Files/Intel/Intel Graphics Software"))
is_rocm_available = False
if not is_cuda_available and not is_ipex_available and allow_rocm:
from modules import rocm
is_rocm_available = allow_rocm and (args.use_rocm or args.use_zluda or rocm.is_installed) # late eval to avoid unnecessary import
if is_cuda_available and args.use_cuda: # prioritize cuda
torch_command = install_cuda()
@@ -937,6 +942,7 @@ def check_torch():
else:
log.warning('Torch: CPU-only version installed')
torch_command = os.environ.get('TORCH_COMMAND', 'torch torchvision')
if args.version:
return
@@ -996,7 +1002,7 @@ def check_torch():
if not args.ignore:
sys.exit(1)
if rocm.is_installed:
if is_rocm_available:
rocm.postinstall()
if not args.skip_all:
install_torch_addons()
+18 -16
View File
@@ -207,6 +207,22 @@ def get_flash_attention_command(agent: Agent) -> str:
return "--no-build-isolation " + os.environ.get("FLASH_ATTENTION_PACKAGE", default)
def refresh():
global environment, blaslt_tensile_libpath, is_installed, version # pylint: disable=global-statement
if sys.platform == "win32":
global agents
try:
agents = driver_get_agents()
except Exception:
agents = []
environment = find()
if environment is not None:
if isinstance(environment, ROCmEnvironment):
blaslt_tensile_libpath = os.environ.get("HIPBLASLT_TENSILE_LIBPATH", os.path.join(environment.path, "bin" if sys.platform == "win32" else "lib", "hipblaslt", "library"))
is_installed = True
version = get_version()
if sys.platform == "win32":
def get_agents() -> List[Agent]:
return agents
@@ -287,7 +303,7 @@ if sys.platform == "win32":
is_wsl: bool = False
agents: List[Agent] = [] # temp
else:
else: # sys.platform != "win32"
def get_agents() -> List[Agent]:
try:
agents = spawn("rocm_agent_enumerator").split("\n")
@@ -312,23 +328,9 @@ else:
return True, None
is_wsl: bool = os.environ.get('WSL_DISTRO_NAME', 'unknown' if spawn('wslpath -w /') else None) is not None
environment = None
blaslt_tensile_libpath = ""
is_installed = False
version = None
def refresh():
global environment, blaslt_tensile_libpath, is_installed, version # pylint: disable=global-statement
if sys.platform == "win32":
global agents
try:
agents = driver_get_agents()
except Exception:
agents = []
environment = find()
if environment is not None:
if isinstance(environment, ROCmEnvironment):
blaslt_tensile_libpath = os.environ.get("HIPBLASLT_TENSILE_LIBPATH", os.path.join(environment.path, "bin" if sys.platform == "win32" else "lib", "hipblaslt", "library"))
is_installed = True
version = get_version()
refresh()