feat: auto-run connectivity test on startup, print results to logs
This commit is contained in:
93
main.py
93
main.py
@@ -653,22 +653,85 @@ def main():
|
|||||||
log(f"STRATEGY_ID: {STRATEGY_ID}")
|
log(f"STRATEGY_ID: {STRATEGY_ID}")
|
||||||
log(f"GPU: {', '.join(GPU_CONFIGS.keys())}")
|
log(f"GPU: {', '.join(GPU_CONFIGS.keys())}")
|
||||||
|
|
||||||
# 启动后自动执行一次提交流程(暂时禁用,用于测试连通性)
|
# 启动后自动运行连通性测试
|
||||||
# def _auto_run():
|
def _startup_test():
|
||||||
# time.sleep(3)
|
time.sleep(2)
|
||||||
# log("自动触发提交流程...")
|
log("=" * 50)
|
||||||
# try:
|
log("连通性测试开始")
|
||||||
# state['running'] = True
|
log("=" * 50)
|
||||||
# state['last_run'] = datetime.now().isoformat()
|
|
||||||
# count = run_pipeline(submit_limit=30)
|
|
||||||
# state['last_result'] = {'submitted': count, 'success': True}
|
|
||||||
# except Exception as e:
|
|
||||||
# log(f"流程异常: {traceback.format_exc()}")
|
|
||||||
# state['last_result'] = {'error': str(e), 'success': False}
|
|
||||||
# finally:
|
|
||||||
# state['running'] = False
|
|
||||||
|
|
||||||
# threading.Thread(target=_auto_run, daemon=True).start()
|
# 1. ModelScope 搜索
|
||||||
|
try:
|
||||||
|
resp = requests.get(
|
||||||
|
'https://modelscope.cn/openapi/v1/models',
|
||||||
|
params={'search': 'qwen', 'page_size': 2, 'sort': 'downloads'},
|
||||||
|
timeout=10, headers={'User-Agent': 'Mozilla/5.0'}
|
||||||
|
)
|
||||||
|
if resp.status_code == 200:
|
||||||
|
data = resp.json()
|
||||||
|
models = data.get('data', {}).get('models', [])
|
||||||
|
log(f"[ModelScope搜索] ✅ status={resp.status_code} models={len(models)}")
|
||||||
|
for m in models[:2]:
|
||||||
|
log(f" {m.get('id')} downloads={m.get('downloads')}")
|
||||||
|
else:
|
||||||
|
log(f"[ModelScope搜索] ❌ status={resp.status_code} body={resp.text[:100]}")
|
||||||
|
except Exception as e:
|
||||||
|
log(f"[ModelScope搜索] ❌ error={e}")
|
||||||
|
|
||||||
|
# 2. ModelScope config.json
|
||||||
|
try:
|
||||||
|
resp = requests.get(
|
||||||
|
'https://modelscope.cn/api/v1/models/Qwen/Qwen3-8B/repo?Revision=master&FilePath=config.json',
|
||||||
|
timeout=10
|
||||||
|
)
|
||||||
|
if resp.status_code == 200:
|
||||||
|
cfg = resp.json()
|
||||||
|
log(f"[ModelScope配置] ✅ arch={cfg.get('architectures')} type={cfg.get('model_type')}")
|
||||||
|
else:
|
||||||
|
log(f"[ModelScope配置] ❌ status={resp.status_code}")
|
||||||
|
except Exception as e:
|
||||||
|
log(f"[ModelScope配置] ❌ error={e}")
|
||||||
|
|
||||||
|
# 3. ModelHub 查询
|
||||||
|
try:
|
||||||
|
token = list(ACCOUNTS.values())[0]
|
||||||
|
resp = requests.get(
|
||||||
|
'https://modelhub.org.cn/api/adapt/task/page',
|
||||||
|
headers={'Xc-Token': token, 'Accept': 'application/json'},
|
||||||
|
params={'current': 1, 'pageSize': 1, 'onlyMine': 'true'},
|
||||||
|
timeout=10
|
||||||
|
)
|
||||||
|
data = resp.json()
|
||||||
|
if data.get('code') == 0:
|
||||||
|
log(f"[ModelHub查询] ✅ total={data['data'].get('total')}")
|
||||||
|
else:
|
||||||
|
log(f"[ModelHub查询] ❌ code={data.get('code')} msg={data.get('message','')[:80]}")
|
||||||
|
except Exception as e:
|
||||||
|
log(f"[ModelHub查询] ❌ error={e}")
|
||||||
|
|
||||||
|
# 4. ModelHub 提交
|
||||||
|
try:
|
||||||
|
token = list(ACCOUNTS.values())[0]
|
||||||
|
resp = requests.post(
|
||||||
|
'https://modelhub.org.cn/api/adapt/task/add',
|
||||||
|
headers={'Xc-Token': token, 'Accept': 'application/json', 'Content-Type': 'application/json'},
|
||||||
|
json={
|
||||||
|
'modelAddress': 'https://www.modelscope.cn/models/Qwen/Qwen3-8B',
|
||||||
|
'taskType': 'text-generation', 'targetGpu': 'Kunlunxin_p-800',
|
||||||
|
'framework': 'vllm', 'strategyId': STRATEGY_ID,
|
||||||
|
'configParams': 'framework: vllm\n',
|
||||||
|
}, timeout=10
|
||||||
|
)
|
||||||
|
data = resp.json()
|
||||||
|
log(f"[ModelHub提交] code={data.get('code')} msg={data.get('message','')[:80]}")
|
||||||
|
except Exception as e:
|
||||||
|
log(f"[ModelHub提交] ❌ error={e}")
|
||||||
|
|
||||||
|
log("=" * 50)
|
||||||
|
log("连通性测试完成,请查看上方结果")
|
||||||
|
log("=" * 50)
|
||||||
|
|
||||||
|
threading.Thread(target=_startup_test, daemon=True).start()
|
||||||
|
|
||||||
while not shutdown_requested:
|
while not shutdown_requested:
|
||||||
server.handle_request()
|
server.handle_request()
|
||||||
|
|||||||
Reference in New Issue
Block a user