get_dcu_version.py 1.88 KB
Newer Older
zhanggzh's avatar
zhanggzh committed
1
2
3
4
5
6
7
8
9
try:
    import torch
except ImportError:
    pass
import subprocess
from pathlib import Path
import os
UNKNOWN = "Unknown"

zhanggezhong's avatar
zhanggezhong committed
10
def sha_value(moe_root):
zhanggzh's avatar
zhanggzh committed
11
12
    try:
        return (
zhanggezhong's avatar
zhanggezhong committed
13
            subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=moe_root)
zhanggzh's avatar
zhanggzh committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
            .decode("ascii")
            .strip()
        )
    except Exception:
        return UNKNOWN

def abi_value():
    try:
        return (
            subprocess.check_output("echo '#include <string>' | gcc -x c++ -E -dM - | fgrep _GLIBCXX_USE_CXX11_ABI", shell=True)
            .decode('ascii')
            .strip()[-1]
        )
    except Exception:
        return UNKNOWN

def dtk_version_value():
    try:
       dtk_path=os.getenv('ROCM_PATH')
       dtk_version_path = os.path.join(dtk_path, '.info', "version-dev")
       with open(dtk_version_path, 'r',encoding='utf-8') as file:
           lines = file.readlines()
       dtk_version="dtk"+lines[0][:-2].replace(".", "")
       return dtk_version
    except Exception:
       return UNKNOWN


def torch_version_value():
    try:
       torch_version = "torch" + (torch.__version__).split('.')[0]+ "." +torch.__version__.split('.')[1]
       return torch_version
    except Exception:
       return UNKNOWN

def moe_whl_name():
    try:
zhanggezhong's avatar
zhanggezhong committed
51
52
        moe_root = Path(__file__).parent
        sha = "das1.1.git" + sha_value(moe_root)[0:7]
zhanggzh's avatar
zhanggzh committed
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
        abi = "abi" + abi_value()
        dtk_version = dtk_version_value()
        try:
            import torch
            torch_version = torch_version_value()
        except ImportError:
            torch_version = "null"
        whl_name = "+" + sha + "." + abi + "." + dtk_version + "." + torch_version
        return whl_name
    except Exception:
        return UNKNOWN

def dcu_version():
    try:
        moe_version = '0.28.0'
        dcu_version = moe_version + moe_whl_name()
        return dcu_version
    except Exception:
        return UNKNOWN