File size: 920 Bytes
57d7761
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
import os
from importlib import import_module

# Model Constants
IGNORE_INDEX = -100
IMAGE_TOKEN_INDEX = -200
IMAGE_TOKEN = "<image>"

# Log & Print
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):
    # Split the path to get separate module and class names
    module_path, _, class_name = full_class_string.rpartition('.')

    # Import the module using the module path
    module = import_module(module_path)

    # Get the class from the imported module
    cls = getattr(module, class_name)
    return cls