66 lines
1.8 KiB
Python
66 lines
1.8 KiB
Python
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
def generate_bootinfo():
|
|
from pathlib import Path
|
|
import datetime
|
|
import os
|
|
workspace_path = Path.cwd()
|
|
bootinfo_time = str(datetime.datetime.now())
|
|
bootinfo_tag_vccl = "[vccl]"
|
|
bootinfo_seq = "@@@"
|
|
|
|
bootinfo_config = f'{workspace_path}/.bootinfos'
|
|
bootinfo_inited = os.path.exists(bootinfo_config)
|
|
|
|
bootinfo_start_up_times = 0
|
|
if bootinfo_inited:
|
|
try:
|
|
with open(bootinfo_config) as w:
|
|
current_bootinfos = w.readline()
|
|
# print("current_bootinfos:",current_bootinfos)
|
|
bootinfo_start_up_times = int(current_bootinfos.split('cycle')[1].strip())
|
|
except Exception as e:
|
|
print("[WARN] read bootinfo fail, caused by ", e)
|
|
# limit max run times
|
|
if bootinfo_start_up_times > 10000000:
|
|
bootinfo_start_up_times = 0
|
|
|
|
current_bootinfos = f'{bootinfo_tag_vccl}{bootinfo_seq}{bootinfo_time} cycle {bootinfo_start_up_times + 1}'
|
|
try:
|
|
with open(bootinfo_config, 'w') as w:
|
|
w.write(current_bootinfos)
|
|
except Exception as e:
|
|
print("[WARN] write bootinfo fail, caused by ", e)
|
|
|
|
def exec_patching():
|
|
import sys
|
|
from vllm_vacc.vllm_patch import VllmPatchManager, patch_vllm, patch_vllm_v1, patch_torch, regist_mock_module
|
|
import sys
|
|
|
|
vpm = VllmPatchManager
|
|
|
|
if vpm.patched:
|
|
return
|
|
|
|
regist_mock_module()
|
|
patch_torch()
|
|
patch_vllm(vpm)
|
|
patch_vllm_v1(vpm)
|
|
|
|
vpm.apply_patches()
|
|
generate_bootinfo()
|
|
|
|
if "vllm.executor.executor_base" in sys.modules:
|
|
del sys.modules["vllm.executor.executor_base"]
|
|
|
|
def register():
|
|
return "vllm_vacc.platform.VaccPlatform"
|
|
|
|
def register_model():
|
|
exec_patching()
|
|
|
|
# from .models import register_model
|
|
# register_model()
|
|
return
|
|
|
|
# exec_patching() |