Skip to content

Commit c82349a

Browse files
committed
Move device check ahead of dist check
1 parent a49469a commit c82349a

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/open_clip_train/distributed.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ def init_distributed_device_so(
127127
global_rank = 0
128128
local_rank = 0
129129
device_type, *device_idx = device.split(':', maxsplit=1)
130+
is_avail, is_known = is_device_available(device_type)
131+
if not is_known:
132+
warnings.warn(f"Device {device} was not known and checked for availability, trying anyways.")
133+
elif not is_avail:
134+
warnings.warn(f"Device {device} was not available, falling back to CPU.")
135+
device_type = device = 'cpu'
130136

131137
if horovod:
132138
import horovod.torch as hvd
@@ -172,13 +178,6 @@ def init_distributed_device_so(
172178
global_rank = torch.distributed.get_rank()
173179
distributed = True
174180

175-
is_avail, is_known = is_device_available(device_type)
176-
if not is_known:
177-
warnings.warn(f"Device {device} was not known and checked for availability, trying anyways.")
178-
elif not is_avail:
179-
warnings.warn(f"Device {device} was not available, falling back to CPU.")
180-
device_type = device = 'cpu'
181-
182181
if distributed and not no_set_device_rank and device_type not in ('cpu', 'mps'):
183182
# Ignore manually specified device index in distributed mode and
184183
# override with resolved local rank, fewer headaches in most setups.

0 commit comments

Comments
 (0)