Skip to content

Revert "torchx/runner: log events to torch.monitor (#379)" #536

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion .pyre_configuration
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
],
"site_package_search_strategy": "all",
"source_directories": [
"typestubs",
"."
],
"strict": true,
Expand Down
10 changes: 0 additions & 10 deletions torchx/runner/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,6 @@ def _get_or_create_logger(destination: str = "null") -> logging.Logger:
def record(event: TorchxEvent, destination: str = "null") -> None:
_get_or_create_logger(destination).info(event.serialize())

if destination != "console":
# if using torch>1.11 log the event to torch.monitor
try:
from torch import monitor

# pyre-fixme[16]: Module `monitor` has no attribute `log_event`.
monitor.log_event(event.to_monitor_event())
except ImportError:
pass


class log_event:
"""
Expand Down
17 changes: 1 addition & 16 deletions torchx/runner/events/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@

import json
from dataclasses import asdict, dataclass
from datetime import datetime
from enum import Enum
from typing import Optional, TYPE_CHECKING, Union

if TYPE_CHECKING:
from torch import monitor
from typing import Optional, Union


class SourceType(str, Enum):
Expand Down Expand Up @@ -64,14 +60,3 @@ def deserialize(data: Union[str, "TorchxEvent"]) -> "TorchxEvent":

def serialize(self) -> str:
return json.dumps(asdict(self))

# pyre-fixme[11]: Annotation `Event` is not defined as a type.
def to_monitor_event(self) -> "monitor.Event":
from torch import monitor

# pyre-fixme[16]: Module `monitor` has no attribute `Event`.
return monitor.Event(
name="torch.runner.Event",
timestamp=datetime.now(),
data={k: v for k, v in self.__dict__.items() if v is not None},
)
58 changes: 0 additions & 58 deletions torchx/runner/events/test/lib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,15 @@
import json
import logging
import unittest
from typing import List
from unittest.mock import MagicMock, patch

from torchx.runner.events import (
_get_or_create_logger,
log_event,
record,
SourceType,
TorchxEvent,
)

try:
from torch import monitor

SKIP_MONITOR: bool = False
except ImportError:
SKIP_MONITOR: bool = True


class TorchxEventLibTest(unittest.TestCase):
def assert_event(
Expand Down Expand Up @@ -66,55 +57,6 @@ def test_event_deser(self) -> None:
deser_event = TorchxEvent.deserialize(json_event)
self.assert_event(event, deser_event)

@unittest.skipIf(SKIP_MONITOR, "no torch.monitor available")
def test_monitor(self) -> None:
event = TorchxEvent(
session="test_session",
scheduler="test_scheduler",
api="test_api",
source=SourceType.EXTERNAL,
)
monitor_event = event.to_monitor_event()
self.assertEqual(
monitor_event.data,
{
"session": "test_session",
"scheduler": "test_scheduler",
"api": "test_api",
"source": "EXTERNAL",
},
)
self.assertEqual(monitor_event.name, "torch.runner.Event")

@unittest.skipIf(SKIP_MONITOR, "no torch.monitor available")
@patch("torchx.runner.events._get_or_create_logger")
def test_monitor_record(self, get_logging_handler: MagicMock) -> None:
event = TorchxEvent(
session="test_session",
scheduler="test_scheduler",
api="test_api",
source=SourceType.EXTERNAL,
)
# pyre-fixme[11]: Annotation `Event` is not defined as a type.
events: List[monitor.Event] = []

def handler(e: monitor.Event) -> None:
events.append(e)

# pyre-fixme[16]: Module `monitor` has no attribute `register_event_handler`.
handle = monitor.register_event_handler(handler)

try:
record(event)
finally:
# pyre-fixme[16]: Module `monitor` has no attribute
# `unregister_event_handler`.
monitor.unregister_event_handler(handle)

self.assertEqual(get_logging_handler.call_count, 1)
self.assertEqual(len(events), 1)
self.assertEqual(events[0].data["session"], "test_session")


@patch("torchx.runner.events.record")
class LogEventTest(unittest.TestCase):
Expand Down