Skip to content

Commit

Permalink
Use os.path.abspath instead of pathlib.Path.absolute
Browse files Browse the repository at this point in the history
  • Loading branch information
sogartar committed Jan 4, 2025
1 parent 8cc3f8d commit 9a10e62
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 22 deletions.
3 changes: 2 additions & 1 deletion build_tools/python_deploy/compute_common_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import json
from datetime import datetime
import subprocess
import os

from packaging.version import Version

Expand All @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion build_tools/python_deploy/write_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import argparse
from pathlib import Path
import json
import os

from packaging.version import Version

Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion shark-ai/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion sharktank/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions shortfin/dev_me.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:])
4 changes: 2 additions & 2 deletions shortfin/python/shortfin_apps/sd/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion shortfin/tests/examples/async_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down
2 changes: 1 addition & 1 deletion shortfin/tests/examples/fastapi_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down
12 changes: 6 additions & 6 deletions tuner/examples/dispatch/dispatch_tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"""

from tuner import libtuner
from pathlib import Path, PurePath
from pathlib import Path
import os


Expand All @@ -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(),
Expand All @@ -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",
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -133,15 +133,15 @@ 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

libtuner.save_pickle(path_config.candidate_trackers_pkl, candidate_trackers)
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)
10 changes: 6 additions & 4 deletions tuner/examples/punet/punet_autotune.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"""

from tuner import libtuner
from pathlib import Path
import os


class PunetClient(libtuner.TuningClient):
Expand Down Expand Up @@ -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",
Expand All @@ -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(),
Expand All @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion tuner/examples/test/tuner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import argparse
from pathlib import Path
from tuner import libtuner
import os


class TestTuner(libtuner.TuningClient):
Expand Down Expand Up @@ -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)

0 comments on commit 9a10e62

Please sign in to comment.