From 9a10e62eee94bbb147df711c4aa604ce9a0f3a0b Mon Sep 17 00:00:00 2001 From: Boian Petkantchin Date: Sat, 4 Jan 2025 02:16:08 +0000 Subject: [PATCH] Use os.path.abspath instead of pathlib.Path.absolute --- build_tools/python_deploy/compute_common_version.py | 3 ++- build_tools/python_deploy/write_requirements.py | 3 ++- shark-ai/setup.py | 2 +- sharktank/conftest.py | 3 ++- shortfin/dev_me.py | 4 ++-- .../python/mobilenet_server/inference_system.py | 2 +- shortfin/python/shortfin_apps/sd/server.py | 4 ++-- shortfin/tests/examples/async_test.py | 3 ++- shortfin/tests/examples/fastapi_test.py | 2 +- tuner/examples/dispatch/dispatch_tuner.py | 12 ++++++------ tuner/examples/punet/punet_autotune.py | 10 ++++++---- tuner/examples/test/tuner_test.py | 3 ++- 12 files changed, 29 insertions(+), 22 deletions(-) diff --git a/build_tools/python_deploy/compute_common_version.py b/build_tools/python_deploy/compute_common_version.py index 99ce4aeae..6a52d3ade 100755 --- a/build_tools/python_deploy/compute_common_version.py +++ b/build_tools/python_deploy/compute_common_version.py @@ -18,6 +18,7 @@ import json from datetime import datetime import subprocess +import os from packaging.version import Version @@ -33,7 +34,7 @@ args = parser.parse_args() -THIS_DIR = Path(__file__).parent.absolute() +THIS_DIR = Path(os.path.abspath(__file__)).parent REPO_ROOT = THIS_DIR.parent.parent VERSION_FILE_SHARKTANK_PATH = REPO_ROOT / "sharktank/version.json" diff --git a/build_tools/python_deploy/write_requirements.py b/build_tools/python_deploy/write_requirements.py index 81ad83f97..7f9765747 100755 --- a/build_tools/python_deploy/write_requirements.py +++ b/build_tools/python_deploy/write_requirements.py @@ -21,6 +21,7 @@ import argparse from pathlib import Path import json +import os from packaging.version import Version @@ -31,7 +32,7 @@ args = parser.parse_args() -THIS_DIR = Path(__file__).parent.absolute() +THIS_DIR = Path(os.path.abspath(__file__)).parent REPO_ROOT = THIS_DIR.parent.parent VERSION_FILE_SHARKTANK = REPO_ROOT / "sharktank/version_local.json" diff --git a/shark-ai/setup.py b/shark-ai/setup.py index 0dc031853..7a0399470 100644 --- a/shark-ai/setup.py +++ b/shark-ai/setup.py @@ -11,7 +11,7 @@ from setuptools import setup -THIS_DIR = Path(__file__).parent.absolute() +THIS_DIR = Path(os.path.abspath(__file__)).parent # Setup and get version information. # The `version_local.json` is generated by calling: diff --git a/sharktank/conftest.py b/sharktank/conftest.py index a0b0aad8a..b274e1ca0 100644 --- a/sharktank/conftest.py +++ b/sharktank/conftest.py @@ -8,6 +8,7 @@ import pytest from pytest import FixtureRequest from typing import Optional, Any +import os # Tests under each top-level directory will get a mark. @@ -19,7 +20,7 @@ def pytest_collection_modifyitems(items, config): # Add marks to all tests based on their top-level directory component. - root_path = Path(__file__).absolute().parent + root_path = Path(os.path.abspath(__file__)).parent for item in items: item_path = Path(item.path) rel_path = item_path.relative_to(root_path) diff --git a/shortfin/dev_me.py b/shortfin/dev_me.py index 2a2f1040a..448fafa1e 100755 --- a/shortfin/dev_me.py +++ b/shortfin/dev_me.py @@ -57,7 +57,7 @@ class EnvInfo: def __init__(self, args): - self.this_dir = Path(__file__).absolute().parent + self.this_dir = Path(os.path.abspath(__file__)).parent self.python_exe = sys.executable self.python_version = Version(".".join(str(v) for v in sys.version_info[1:2])) self.debug = bool(sysconfig.get_config_var("Py_DEBUG")) @@ -76,7 +76,7 @@ def __init__(self, args): def add_configured(self, path: Path): probe = path / "CMakeCache.txt" - if probe.absolute().exists(): + if probe.exists(): self.configured_dirs.append(path) def find_cmake(self, args): diff --git a/shortfin/examples/python/mobilenet_server/inference_system.py b/shortfin/examples/python/mobilenet_server/inference_system.py index 27e92cf46..982e2501a 100644 --- a/shortfin/examples/python/mobilenet_server/inference_system.py +++ b/shortfin/examples/python/mobilenet_server/inference_system.py @@ -153,5 +153,5 @@ def client(): if __name__ == "__main__": - home_dir = Path(__file__).absolute().parent + home_dir = Path(os.path.abspath(__file__)).parent run_cli(home_dir, sys.argv[1:]) diff --git a/shortfin/python/shortfin_apps/sd/server.py b/shortfin/python/shortfin_apps/sd/server.py index 4bff9a3cb..9052fffb0 100644 --- a/shortfin/python/shortfin_apps/sd/server.py +++ b/shortfin/python/shortfin_apps/sd/server.py @@ -33,7 +33,7 @@ logger.addHandler(native_handler) logger.propagate = False -THIS_DIR = Path(__file__).absolute().parent +THIS_DIR = Path(os.path.abspath(__file__)).parent UVICORN_LOG_CONFIG = { "version": 1, @@ -398,7 +398,7 @@ def main(argv, log_config=UVICORN_LOG_CONFIG): artdir = home / ".cache" / "shark" args.artifacts_dir = str(artdir) else: - args.artifacts_dir = Path(args.artifacts_dir).absolute() + args.artifacts_dir = os.path.abspath(args.artifacts_dir) global sysman sysman, model_config, flagfile, tuning_spec = configure_sys(args) diff --git a/shortfin/tests/examples/async_test.py b/shortfin/tests/examples/async_test.py index e4db1a803..2bf979541 100644 --- a/shortfin/tests/examples/async_test.py +++ b/shortfin/tests/examples/async_test.py @@ -10,8 +10,9 @@ from pathlib import Path import subprocess import sys +import os -project_dir = Path(__file__).absolute().parent.parent.parent +project_dir = Path(os.path.abspath(__file__)).parent.parent.parent example_dir = project_dir / "examples" / "python" diff --git a/shortfin/tests/examples/fastapi_test.py b/shortfin/tests/examples/fastapi_test.py index ebceacbab..497bdb0ad 100644 --- a/shortfin/tests/examples/fastapi_test.py +++ b/shortfin/tests/examples/fastapi_test.py @@ -14,7 +14,7 @@ import sys import time -project_dir = Path(__file__).absolute().parent.parent.parent +project_dir = Path(os.path.abspath(__file__)).parent.parent.parent example_dir = project_dir / "examples" / "python" diff --git a/tuner/examples/dispatch/dispatch_tuner.py b/tuner/examples/dispatch/dispatch_tuner.py index 541cad907..7198ebd50 100644 --- a/tuner/examples/dispatch/dispatch_tuner.py +++ b/tuner/examples/dispatch/dispatch_tuner.py @@ -22,7 +22,7 @@ """ from tuner import libtuner -from pathlib import Path, PurePath +from pathlib import Path import os @@ -35,7 +35,7 @@ def get_dispatch_compile_command( ) -> list[str]: assert candidate_tracker.dispatch_mlir_path is not None mlir_path: Path = candidate_tracker.dispatch_mlir_path - script_dir = Path(__file__).absolute().parent + script_dir = Path(os.path.abspath(__file__)).parent command = [ (script_dir / "compile_dispatch.sh").as_posix(), mlir_path.as_posix(), @@ -55,7 +55,7 @@ def get_dispatch_benchmark_command( command = [ "iree-benchmark-module", f"--device={libtuner.DEVICE_ID_PLACEHOLDER}", - f"--module={compiled_vmfb_path.absolute()}", + f"--module={os.path.abspath(compiled_vmfb_path)}", "--batch_size=1000", "--benchmark_repetitions=3", "--benchmark_format=json", @@ -93,7 +93,7 @@ def main(): args = libtuner.parse_arguments() path_config = libtuner.PathConfig() # These will not be used, so always default to the empty config in the script dir. - script_dir = Path(__file__).absolute().parent + script_dir = Path(os.path.abspath(__file__)).parent path_config.global_config_prolog_mlir = ( script_dir / path_config.global_config_prolog_mlir ) @@ -133,7 +133,7 @@ def main(): top_candidates = libtuner.benchmark_dispatches( args, path_config, compiled_candidates, candidate_trackers, dispatch_tuner ) - print(f"\nStored results in {path_config.output_unilog.absolute()}\n") + print(f"\nStored results in {os.path.abspath(path_config.output_unilog)}\n") if stop_after_phase == libtuner.ExecutionPhases.benchmark_dispatches: return @@ -141,7 +141,7 @@ def main(): print(f"Candidate trackers are saved in {path_config.candidate_trackers_pkl}\n") print("Check the detailed execution logs in:") - print(path_config.run_log.absolute()) + print(os.path.abspath(path_config.run_log)) for candidate in candidate_trackers: libtuner.logging.debug(candidate) diff --git a/tuner/examples/punet/punet_autotune.py b/tuner/examples/punet/punet_autotune.py index 0538b31d0..bb8012d75 100644 --- a/tuner/examples/punet/punet_autotune.py +++ b/tuner/examples/punet/punet_autotune.py @@ -22,6 +22,8 @@ """ from tuner import libtuner +from pathlib import Path +import os class PunetClient(libtuner.TuningClient): @@ -52,7 +54,7 @@ def get_dispatch_benchmark_command( command = [ "iree-benchmark-module", f"--device={libtuner.DEVICE_ID_PLACEHOLDER}", - f"--module={compiled_vmfb_path.absolute()}", + f"--module={os.path.abspath(compiled_vmfb_path)}", "--hip_use_streams=true", "--hip_allow_inline_execution=true", "--batch_size=1000", @@ -70,13 +72,13 @@ def get_model_compile_command( ) -> list[str]: mlir_spec_path = candidate_tracker.spec_path assert mlir_spec_path is not None - target_dir = mlir_spec_path.absolute().parent.parent.parent + target_dir = Path(os.path.abspath(mlir_spec_path)).parent.parent.parent output_name = f"unet_candidate_{candidate_tracker.candidate_id}.vmfb" command = [ "compile-punet-base.sh", "iree-compile", "gfx942", - f"{mlir_spec_path.absolute()}", + f"{os.path.abspath(mlir_spec_path)}", "./punet.mlir", "-o", (target_dir / output_name).as_posix(), @@ -98,7 +100,7 @@ def get_model_benchmark_command( "--hip_use_streams=true", "--hip_allow_inline_execution=true", "--device_allocator=caching", - f"--module={unet_candidate_path.absolute()}", + f"--module={os.path.abspath(unet_candidate_path)}", "--parameters=model=punet.irpa", "--function=main", "--input=1x4x128x128xf16", diff --git a/tuner/examples/test/tuner_test.py b/tuner/examples/test/tuner_test.py index dfd1aa943..35321c908 100644 --- a/tuner/examples/test/tuner_test.py +++ b/tuner/examples/test/tuner_test.py @@ -7,6 +7,7 @@ import argparse from pathlib import Path from tuner import libtuner +import os class TestTuner(libtuner.TuningClient): @@ -163,7 +164,7 @@ def main(): print(f"Top model candidates: {top_model_candidates}") print("Check the detailed execution logs in:") - print(path_config.run_log.absolute()) + print(os.path.abspath(path_config.run_log)) for candidate in candidate_trackers: libtuner.logging.debug(candidate)