Skip to content

Commit 974b543

Browse files
authored
Merge branch 'main' into wenqinglan/update-gpu-burn-submodule
2 parents c650eec + e3fd943 commit 974b543

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

superbench/common/utils/network.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import re
88
import os
99
from pathlib import Path
10+
from superbench.common.utils import logger
1011

1112

1213
def get_free_port():
@@ -33,7 +34,26 @@ def get_ib_devices():
3334
ib_devices_port (list): IB devices with available ports in current system.
3435
"""
3536
if os.getenv('IB_DEVICES', None):
36-
return os.getenv('IB_DEVICES').split(',')
37+
ib_devices_env = os.getenv('IB_DEVICES').split(',')
38+
# Validate that IB_DEVICES contains either all
39+
# numeric indices or all device names, not mixed
40+
numeric_flags = [device.strip().isdigit() for device in ib_devices_env]
41+
all_numeric = all(numeric_flags)
42+
any_numeric = any(numeric_flags)
43+
44+
# Check for mixed case (some numeric, some not)
45+
if any_numeric and not all_numeric:
46+
logger.log_and_raise(
47+
exception=ValueError,
48+
msg='IB_DEVICES contains mixed numeric indices and device names: {}. '
49+
'All values must be either numeric indices (e.g., "0,2,4,6") '
50+
'or device names (e.g., "mlx5_ib0,mlx5_ib2").'.format(os.getenv('IB_DEVICES'))
51+
)
52+
53+
# If all numeric, fall through to discover actual devices; otherwise use provided names
54+
if not all_numeric:
55+
# All are device names, use them directly
56+
return ib_devices_env
3757
devices = list(p.name for p in Path('/sys/class/infiniband').glob('*'))
3858
ib_devices_port_dict = {}
3959
for device in devices:

0 commit comments

Comments
 (0)