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

Add an exception for torch<1.8.1 #1556

Merged
merged 4 commits into from
Apr 16, 2022
Merged
Changes from 3 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
14 changes: 12 additions & 2 deletions ts/torch_handler/base_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@
import importlib.util
import time
import torch
from torch.profiler import profile, record_function, ProfilerActivity
from pkg_resources import packaging
from ..utils.util import list_classes_from_module, load_label_mapping

if packaging.version.parse(torch.__version__) >= packaging.version.parse("1.8.1"):
from torch.profiler import profile, record_function, ProfilerActivity
PROFILER_AVAILABLE = True
else:
PROFILER_AVAILABLE = False


logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -211,7 +217,11 @@ def handle(self, data, context):

is_profiler_enabled = os.environ.get("ENABLE_TORCH_PROFILER", None)
if is_profiler_enabled:
output, _ = self._infer_with_profiler(data=data)
if PROFILER_AVAILABLE:
output, _ = self._infer_with_profiler(data=data)
else:
raise RuntimeError("Profiler is enabled but current version of torch does not support."
"Install torch>=1.8.1 to use profiler.")
else:
if self._is_describe():
output = [self.describe_handle()]
Expand Down