Skip to content

Commit 511cdb2

Browse files
pdesupinskimarkc-614
authored andcommitted
[ez] Make NUMA signpost parameters JSON serializable (pytorch#160710)
# Context Broader context in pytorch#160163. In order for the _utils_internal version of signpost_event to do proper logging, its parameters argument needs to be json serializable. # This PR Convert `NumaOptions` to serializable form before inputting to `signpost_event`. # Test Plan ## Automated Added tests `$ pytest test/test_numa_binding.py`. ## Manual See [D80317206](https://www.internalfb.com/diff/D80317206). Pull Request resolved: pytorch#160710 Approved by: https://github.com/kiukchung
1 parent bca9ddf commit 511cdb2

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

test/test_numa_binding.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import json
56
import multiprocessing.spawn as spawn
67
import os
78
import subprocess
@@ -13,6 +14,7 @@
1314
from unittest.mock import mock_open, patch
1415

1516
import torch
17+
from torch._utils_internal import signpost_event
1618
from torch.distributed.elastic.multiprocessing import DefaultLogsSpecs, start_processes
1719
from torch.numa.binding import (
1820
_get_ranges_str_from_ints,
@@ -68,6 +70,7 @@ def setUp(self) -> None:
6870
patch("shutil.which", return_value="/usr/bin/numactl"),
6971
patch("torch.numa.binding.run"),
7072
patch("torch.numa.binding.mkstemp", self._mock_mkstemp),
73+
patch("torch.numa.binding.signpost_event", self._mock_signpost_event),
7174
]
7275

7376
for context_manager in self._context_managers_to_apply_to_all_tests:
@@ -86,6 +89,11 @@ def tearDown(self) -> None:
8689
context_manager.__exit__(None, None, None)
8790
super().tearDown()
8891

92+
def _mock_signpost_event(self, *args, **kwargs) -> None:
93+
# Please keep these parameters JSON serializable for logging purposes
94+
json.dumps(kwargs["parameters"])
95+
return signpost_event(*args, **kwargs)
96+
8997
def _mock_mkstemp(self, *args, **kwargs):
9098
# Just keep track of temp files so we can delete them
9199
fd, path = _real_mkstemp(*args, **kwargs)

torch/numa/binding.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import traceback
66
from collections import defaultdict
77
from collections.abc import Iterable
8-
from dataclasses import dataclass
8+
from dataclasses import asdict, dataclass
99
from enum import Enum
1010
from logging import getLogger
1111
from subprocess import run
@@ -113,7 +113,7 @@ def maybe_wrap_command_with_numa_bindings(
113113
kwargs = {
114114
"command_args": command_args,
115115
"gpu_index": gpu_index,
116-
"numa_options": numa_options,
116+
"numa_options": asdict(numa_options),
117117
}
118118
logger.info("Attempting to wrap command with NUMA bindings, given input %r", kwargs)
119119

0 commit comments

Comments
 (0)