Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6e9f2e7a0 | ||
|
|
821edbc8f5 | ||
|
|
5e2df178e1 | ||
|
|
761e74ff82 |
116
main.py
116
main.py
@@ -121,12 +121,12 @@ def init_db():
|
||||
# ModelScope 搜索
|
||||
# ============================================================
|
||||
|
||||
def search_models(keyword: str, limit: int = 100) -> list:
|
||||
def search_models(keyword: str, limit: int = 50) -> list:
|
||||
"""从 ModelScope 搜索模型"""
|
||||
url = "https://modelscope.cn/openapi/v1/models"
|
||||
params = {
|
||||
'search': keyword,
|
||||
'page_size': limit,
|
||||
'page_size': min(limit, 50), # API 上限 50
|
||||
'page_number': 1,
|
||||
'sort': 'downloads',
|
||||
}
|
||||
@@ -135,7 +135,11 @@ def search_models(keyword: str, limit: int = 100) -> list:
|
||||
headers={'User-Agent': 'Mozilla/5.0'})
|
||||
data = resp.json()
|
||||
if data.get('success'):
|
||||
return data.get('data', {}).get('models', [])
|
||||
models = data.get('data', {}).get('models', [])
|
||||
log(f" 搜索 [{keyword}]: status={resp.status_code} models={len(models)}")
|
||||
return models
|
||||
else:
|
||||
log(f" 搜索 [{keyword}]: success=false, data={str(data)[:200]}")
|
||||
except Exception as e:
|
||||
log(f" 搜索失败 [{keyword}]: {e}")
|
||||
return []
|
||||
@@ -653,22 +657,98 @@ def main():
|
||||
log(f"STRATEGY_ID: {STRATEGY_ID}")
|
||||
log(f"GPU: {', '.join(GPU_CONFIGS.keys())}")
|
||||
|
||||
# 启动后自动执行一次提交流程(暂时禁用,用于测试连通性)
|
||||
# def _auto_run():
|
||||
# time.sleep(3)
|
||||
# log("自动触发提交流程...")
|
||||
# try:
|
||||
# state['running'] = True
|
||||
# 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
|
||||
# 启动后自动运行连通性测试
|
||||
def _startup_test():
|
||||
time.sleep(2)
|
||||
log("=" * 50)
|
||||
log("连通性测试开始")
|
||||
log("=" * 50)
|
||||
|
||||
# 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)
|
||||
|
||||
# 开始正式提交流程
|
||||
log("\n自动触发提交流程...")
|
||||
try:
|
||||
state['running'] = True
|
||||
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=_startup_test, daemon=True).start()
|
||||
|
||||
while not shutdown_requested:
|
||||
server.handle_request()
|
||||
|
||||
Reference in New Issue
Block a user