Skip to content

Commit 3488114

Browse files
authored
Improve behavior on OS X (#20)
* Adding a guard to check if the Process class has the cpu_affinity function. * Import the inspect class. * Remove debug code.
1 parent 1eb779c commit 3488114

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

hpc_launcher/schedulers/local.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# Copyright (c) 2014-2024, Lawrence Livermore National Security, LLC.
2+
# Produced at the Lawrence Livermore National Laboratory.
3+
# Written by the LBANN Research Team (B. Van Essen, et al.) listed in
4+
# the CONTRIBUTORS file. See the top-level LICENSE file for details.
5+
#
6+
# LLNL-CODE-697807.
7+
# All rights reserved.
8+
#
9+
# This file is part of LBANN: Livermore Big Artificial Neural Network
10+
# Toolkit. For details, see http://software.llnl.gov/LBANN or
11+
# https://github.com/LBANN and https://github.com/LLNL/LBANN.
12+
#
13+
# SPDX-License-Identifier: (Apache-2.0)
114
from hpc_launcher.schedulers.scheduler import Scheduler
215
from dataclasses import dataclass
316
from typing import TYPE_CHECKING, Optional

hpc_launcher/torch/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@
1212
#
1313
# SPDX-License-Identifier: (Apache-2.0)
1414
from psutil import Process
15+
import inspect
1516

16-
# Save affinity before importing torch
17-
affinity = Process().cpu_affinity()
17+
affinity = None
18+
if (hasattr(Process, 'cpu_affinity') and inspect.isfunction(Process.cpu_affinity)):
19+
# Save affinity before importing torch
20+
affinity = Process().cpu_affinity()
1821

1922
import torch
2023

21-
# Restore affinity after importing torch
22-
Process().cpu_affinity(affinity)
24+
if affinity is not None:
25+
# Restore affinity after importing torch
26+
Process().cpu_affinity(affinity)
2327
import os
2428

2529
if torch.cuda.is_available():

0 commit comments

Comments
 (0)