From 87e3eafa64f351089cdd3c300afa84b8077d7682 Mon Sep 17 00:00:00 2001 From: KantaTamura Date: Thu, 22 Aug 2024 17:29:29 +0900 Subject: [PATCH] Split PPE methods --- pfio/v2/_profiler.py | 21 +++++++++++++++++++++ pfio/v2/local.py | 24 +----------------------- 2 files changed, 22 insertions(+), 23 deletions(-) create mode 100644 pfio/v2/_profiler.py diff --git a/pfio/v2/_profiler.py b/pfio/v2/_profiler.py new file mode 100644 index 00000000..6023e307 --- /dev/null +++ b/pfio/v2/_profiler.py @@ -0,0 +1,21 @@ +try: + from pytorch_pfn_extras.profiler import record, record_iterable + +except ImportError: + + class _DummyRecord: + def __init__(self): + pass + + def __enter__(self): + pass + + def __exit__(self, exc_type, exc_value, traceback): + pass + + # IF PPE is not available, wrap with noop + def record(tag, trace, *args): # type: ignore # NOQA + return _DummyRecord() + + def record_iterable(tag, iter, trace, *args): # type: ignore # NOQA + yield from iter diff --git a/pfio/v2/local.py b/pfio/v2/local.py index 81aca891..09945b0b 100644 --- a/pfio/v2/local.py +++ b/pfio/v2/local.py @@ -4,29 +4,7 @@ import shutil from typing import Optional -try: - from pytorch_pfn_extras.profiler import record, record_iterable - -except ImportError: - - class _DummyRecord: - def __init__(self): - pass - - def __enter__(self): - pass - - def __exit__(self, exc_type, exc_value, traceback): - pass - - # IF PPE is not available, wrap with noop - def record(tag, trace, *args): # type: ignore # NOQA - return _DummyRecord() - - def record_iterable(tag, iter, trace, *args): # type: ignore # NOQA - yield from iter - - +from ._profiler import record, record_iterable from .fs import FS, FileStat, format_repr