Spaces:
Running
on
Zero
Running
on
Zero
File size: 746 Bytes
0b4562b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
#
# For licensing see accompanying LICENSE file.
# Copyright (C) 2025 Apple Inc. All Rights Reserved.
#
import os
def get_local_rank():
if os.environ.get('IRISCTL_ROLE'):
import irisctl.api as irisctl
return irisctl.local_rank()
elif os.environ.get('MASTER_PORT'):
return int(os.environ['LOCAL_RANK'])
else:
return 0
def print(*args, **kwargs):
if get_local_rank() == 0:
import builtins
builtins.print(*args, **kwargs)
def xprint(string):
import builtins
local_rank = get_local_rank()
builtins.print(f'[Local Rank {local_rank}] {string}')
def dividable(x):
for i in range(int(x ** 0.5), 0, -1):
if x % i == 0:
return x // i
return x
|