Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profiling with PPE for Local #326

Closed
wants to merge 7 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions pfio/v2/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@
import shutil
from typing import Optional

try:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation should be in pfio/v2/_profiler.py or pfio/_profiler.py because these noop implementation will be used in all FS.

from pytorch_pfn_extras.profiler import ( # type: ignore # NOQA
record_function, record_iterable)

except ImportError:

# IF PPE is not available, wrap with noop
def record_function(*args): # type: ignore # NOQA
def wrapper(f):
return f
return wrapper

def record_iterable(tag, iter, *args): # type: ignore # NOQA
yield from iter


from .fs import FS, FileStat, format_repr


Expand Down Expand Up @@ -83,6 +99,7 @@ def __repr__(self):
},
)

@record_function("pfio.v2.Local:open")
def open(self, file_path, mode='r',
buffering=-1, encoding=None, errors=None,
newline=None, closefd=True, opener=None):
Expand All @@ -94,6 +111,12 @@ def open(self, file_path, mode='r',

def list(self, path: Optional[str] = '', recursive=False,
detail=False):
for e in record_iterable("pfio.v2.Local:list",
self._list(path, recursive, detail)):
yield e

def _list(self, path: Optional[str] = '', recursive=False,
detail=False):
path_or_prefix = os.path.join(self.cwd,
"" if path is None else path)

Expand Down Expand Up @@ -128,6 +151,7 @@ def _recursive_list(self, prefix_end_index: int, path: str,
yield from self._recursive_list(prefix_end_index,
e.path, detail)

@record_function("pfio.v2.Local:stat")
def stat(self, path):
path = os.path.join(self.cwd, path)
return LocalFileStat(os.stat(path), path)
Expand All @@ -136,23 +160,28 @@ def isdir(self, path: str):
path = os.path.join(self.cwd, path)
return os.path.isdir(path)

@record_function("pfio.v2.Local:mkdir")
def mkdir(self, file_path: str, mode=0o777, *args, dir_fd=None):
path = os.path.join(self.cwd, file_path)
return os.mkdir(path, mode, *args, dir_fd=None)

@record_function("pfio.v2.Local:makedirs")
def makedirs(self, file_path: str, mode=0o777, exist_ok=False):
path = os.path.join(self.cwd, file_path)
return os.makedirs(path, mode, exist_ok)

@record_function("pfio.v2.Local:exists")
def exists(self, file_path: str):
path = os.path.join(self.cwd, file_path)
return os.path.exists(path)

@record_function("pfio.v2.Local:rename")
def rename(self, src, dst):
s = os.path.join(self.cwd, src)
d = os.path.join(self.cwd, dst)
return os.rename(s, d)

@record_function("pfio.v2.Local:remove")
def remove(self, file_path: str, recursive=False):
file_path = os.path.join(self.cwd, file_path)
if recursive:
Expand All @@ -162,6 +191,7 @@ def remove(self, file_path: str, recursive=False):

return os.remove(file_path)

@record_function("pfio.v2.Local:glob")
def glob(self, pattern: str):
return [
str(item.relative_to(self.cwd))
Expand Down