|
import os |
|
from importlib import import_module |
|
|
|
|
|
IGNORE_INDEX = -100 |
|
IMAGE_TOKEN_INDEX = -200 |
|
IMAGE_TOKEN = "<image>" |
|
|
|
|
|
BEGIN_LINE = '========================************========================' |
|
END_LINE = '------------------------------------------------------------' |
|
|
|
|
|
def rank0_print(*args): |
|
if int(os.getenv("LOCAL_PROCESS_RANK", os.getenv("LOCAL_RANK", 0))) == 0: |
|
print(*args) |
|
|
|
|
|
def smart_unit(num): |
|
if num / 1.0e9 >= 1: |
|
return f'{num / 1.0e9:.2f}B' |
|
else: |
|
return f'{num / 1.0e6:.2f}M' |
|
|
|
|
|
def import_class_from_string(full_class_string): |
|
|
|
module_path, _, class_name = full_class_string.rpartition('.') |
|
|
|
|
|
module = import_module(module_path) |
|
|
|
|
|
cls = getattr(module, class_name) |
|
return cls |
|
|