Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3eed33f0d8 | ||
|
|
a2ef82d954 | ||
|
|
2198aed3c2 | ||
|
|
965342bafe |
79
main.py
79
main.py
@@ -47,7 +47,7 @@ SUPPORTED_SPECIAL_ARCHS = ['Eagle3Speculator', 'LlamaForCausalLMEagle3']
|
|||||||
MODELHUB_API = "https://modelhub.org.cn/api"
|
MODELHUB_API = "https://modelhub.org.cn/api"
|
||||||
|
|
||||||
# 搜索关键词
|
# 搜索关键词
|
||||||
SEARCH_KEYWORDS = ['qwen', 'Qwen2', 'Qwen3', 'Qwen3.5', 'Llama-3', 'Llama-3.1', 'Mistral', 'DeepSeek']
|
SEARCH_KEYWORDS = ['Llama-3', 'Llama-3.1', 'Llama-3.2', 'Meta-Llama', 'Llama-4']
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
# 全局状态
|
# 全局状态
|
||||||
@@ -157,7 +157,7 @@ def search_models(keyword: str) -> list:
|
|||||||
|
|
||||||
|
|
||||||
def check_architecture(model_id: str) -> tuple:
|
def check_architecture(model_id: str) -> tuple:
|
||||||
"""检查模型架构"""
|
"""检查模型是否有有效的 config.json(不限架构类型)"""
|
||||||
try:
|
try:
|
||||||
cfg_url = f"{MODELSCOPE_API}/models/{model_id}/repo?Revision=master&FilePath=config.json"
|
cfg_url = f"{MODELSCOPE_API}/models/{model_id}/repo?Revision=master&FilePath=config.json"
|
||||||
resp = requests.get(cfg_url, timeout=10)
|
resp = requests.get(cfg_url, timeout=10)
|
||||||
@@ -165,20 +165,13 @@ def check_architecture(model_id: str) -> tuple:
|
|||||||
cfg = resp.json()
|
cfg = resp.json()
|
||||||
archs = cfg.get('architectures', [])
|
archs = cfg.get('architectures', [])
|
||||||
mtype = cfg.get('model_type', '')
|
mtype = cfg.get('model_type', '')
|
||||||
arch_str = str(archs)
|
if archs or mtype:
|
||||||
for special in SUPPORTED_SPECIAL_ARCHS:
|
return True, f"arch={archs} type={mtype}"
|
||||||
if special in arch_str:
|
return False, "empty config"
|
||||||
return True, special
|
|
||||||
for kw in SUPPORTED_ARCH_KEYWORDS:
|
|
||||||
if kw in arch_str:
|
|
||||||
return True, kw
|
|
||||||
if mtype in SUPPORTED_MODEL_TYPES:
|
|
||||||
return True, mtype
|
|
||||||
return False, f"arch={archs} type={mtype}"
|
|
||||||
mid_upper = model_id.upper()
|
mid_upper = model_id.upper()
|
||||||
if 'QWEN3' in mid_upper or 'QWEN2' in mid_upper:
|
if 'LLAMA' in mid_upper:
|
||||||
return True, "GGUF"
|
return True, "Llama(GGUF)"
|
||||||
return False, "no config, not Qwen"
|
return False, "no config"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return True, f"check error: {e}"
|
return True, f"check error: {e}"
|
||||||
|
|
||||||
@@ -254,26 +247,25 @@ def check_queue_available() -> int:
|
|||||||
|
|
||||||
|
|
||||||
def build_config_params() -> str:
|
def build_config_params() -> str:
|
||||||
"""构建 YAML 配置 - llama.cpp (支持 GGUF)"""
|
"""构建 YAML 配置 - vllm"""
|
||||||
params = {
|
params = {
|
||||||
'framework': 'llama.cpp',
|
'framework': 'vllm',
|
||||||
'nv_framework': 'llama.cpp',
|
'nv_framework': 'vllm',
|
||||||
'api': 'completion',
|
'api': 'completion',
|
||||||
'max_tokens': 1024,
|
'max_tokens': 1024,
|
||||||
'temperature': 0.7,
|
'temperature': 0.7,
|
||||||
'repetition_penalty': 1.2,
|
'repetition_penalty': 1.2,
|
||||||
'top_p': 0.9,
|
'top_p': 0.9,
|
||||||
'lang': 'zh',
|
'lang': 'zh',
|
||||||
'max_model_len': 4096,
|
'max_model_len': 2048,
|
||||||
'sut_config': {
|
'sut_config': {
|
||||||
'gpu_num': 1,
|
'gpu_num': 1,
|
||||||
'values': {
|
'values': {
|
||||||
'command': [
|
'command': [
|
||||||
'llama-server', '--model', '/model', '--alias', 'llm',
|
'vllm', 'serve', '/model', '--port', '8000',
|
||||||
'--threads', '20', '--n-gpu-layers', '999', '--prio', '3',
|
'--served-model-name', 'llm', '--max-model-len', '2048',
|
||||||
'--min_p', '0.01', '--ctx-size', '4096',
|
'--dtype', 'auto', '--gpu-memory-utilization', '0.95',
|
||||||
'--host', '0.0.0.0', '--port', '8000',
|
'-tp', '1', '--enforce-eager', '--trust-remote-code',
|
||||||
'--jinja', '--flash-attn', 'off',
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -281,9 +273,9 @@ def build_config_params() -> str:
|
|||||||
'gpu_num': 1,
|
'gpu_num': 1,
|
||||||
'values': {
|
'values': {
|
||||||
'command': [
|
'command': [
|
||||||
'llama-server', '--model', '/model', '--alias', 'llm',
|
'vllm', 'serve', '/model', '--port', '80',
|
||||||
'--threads', '20', '--n-gpu-layers', '999',
|
'--served-model-name', 'llm', '--max-model-len', '4096',
|
||||||
'--ctx-size', '4096', '--host', '0.0.0.0', '--port', '8000',
|
'--enforce-eager', '--trust-remote-code', '-tp', '1',
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -303,7 +295,7 @@ def submit_model(model_url: str) -> tuple:
|
|||||||
'modelAddress': normalize_model_url(model_url),
|
'modelAddress': normalize_model_url(model_url),
|
||||||
'taskType': 'text-generation',
|
'taskType': 'text-generation',
|
||||||
'targetGpu': TARGET_GPU,
|
'targetGpu': TARGET_GPU,
|
||||||
'framework': 'llama.cpp',
|
'framework': 'vllm',
|
||||||
'strategyId': STRATEGY_ID,
|
'strategyId': STRATEGY_ID,
|
||||||
'configParams': build_config_params(),
|
'configParams': build_config_params(),
|
||||||
}
|
}
|
||||||
@@ -322,7 +314,7 @@ def submit_model(model_url: str) -> tuple:
|
|||||||
# 主流程
|
# 主流程
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|
||||||
def run_pipeline(submit_limit: int = 2):
|
def run_pipeline(submit_limit: int = 5):
|
||||||
"""完整流程:搜索→筛选→提交(只针对目标GPU)"""
|
"""完整流程:搜索→筛选→提交(只针对目标GPU)"""
|
||||||
init_db()
|
init_db()
|
||||||
log("=" * 50)
|
log("=" * 50)
|
||||||
@@ -366,14 +358,22 @@ def run_pipeline(submit_limit: int = 2):
|
|||||||
hf_models.append(m)
|
hf_models.append(m)
|
||||||
log(f"格式筛选: {len(hf_models)} 通过, {format_skipped} 跳过 (GPTQ/AWQ)")
|
log(f"格式筛选: {len(hf_models)} 通过, {format_skipped} 跳过 (GPTQ/AWQ)")
|
||||||
|
|
||||||
# 3. 架构筛选(参考检查,不做严格过滤,让平台决定兼容性)
|
# 3. 架构筛选(只保留有标准config.json的模型,排除无效格式)
|
||||||
log("\n--- 阶段3: 架构检查 ---")
|
log("\n--- 阶段3: 架构检查 ---")
|
||||||
|
arch_passed = []
|
||||||
|
arch_rejected = 0
|
||||||
for m in hf_models:
|
for m in hf_models:
|
||||||
ok, reason = check_architecture(m['model_id'])
|
ok, reason = check_architecture(m['model_id'])
|
||||||
if not ok:
|
if not ok:
|
||||||
log(f" ! {m['model_id']}: {reason} (仍保留)")
|
arch_rejected += 1
|
||||||
|
log(f" x {m['model_id']}: {reason}")
|
||||||
|
elif reason == 'GGUF':
|
||||||
|
arch_rejected += 1
|
||||||
|
log(f" x {m['model_id']}: GGUF(无config)")
|
||||||
|
else:
|
||||||
|
arch_passed.append(m)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
log(f"架构检查: {len(hf_models)} 个模型进入下一阶段")
|
log(f"架构检查: {len(arch_passed)} 通过, {arch_rejected} 拒绝")
|
||||||
|
|
||||||
# 4. 筛选并提交(只针对目标GPU)
|
# 4. 筛选并提交(只针对目标GPU)
|
||||||
log(f"\n--- 阶段4: 筛选并提交 [{TARGET_GPU}] ---")
|
log(f"\n--- 阶段4: 筛选并提交 [{TARGET_GPU}] ---")
|
||||||
@@ -387,7 +387,7 @@ def run_pipeline(submit_limit: int = 2):
|
|||||||
|
|
||||||
# 筛选
|
# 筛选
|
||||||
to_submit = []
|
to_submit = []
|
||||||
for m in hf_models:
|
for m in arch_passed:
|
||||||
model_id = m['model_id']
|
model_id = m['model_id']
|
||||||
|
|
||||||
# 检查全平台验证状态
|
# 检查全平台验证状态
|
||||||
@@ -418,8 +418,9 @@ def run_pipeline(submit_limit: int = 2):
|
|||||||
submitted += 1
|
submitted += 1
|
||||||
log(f" ✅ {m['model_id']}")
|
log(f" ✅ {m['model_id']}")
|
||||||
db_conn.execute(
|
db_conn.execute(
|
||||||
'INSERT OR REPLACE INTO submitted VALUES (?,?,?,?)',
|
'INSERT OR REPLACE INTO submitted VALUES (?,?,?,?,?,?)',
|
||||||
(m['model_id'], TARGET_GPU, str(task_id), datetime.now().isoformat())
|
(m['model_id'], TARGET_GPU, str(task_id), 'submitted',
|
||||||
|
datetime.now().isoformat(), None)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
log(f" ❌ {m['model_id']}: {msg}")
|
log(f" ❌ {m['model_id']}: {msg}")
|
||||||
@@ -486,7 +487,7 @@ class AgentHandler(BaseHTTPRequestHandler):
|
|||||||
if content_len > 0:
|
if content_len > 0:
|
||||||
body = json.loads(self.rfile.read(content_len))
|
body = json.loads(self.rfile.read(content_len))
|
||||||
|
|
||||||
limit = body.get('limit', 2)
|
limit = body.get('limit', 5)
|
||||||
|
|
||||||
self._json({'status': 'started', 'gpu': TARGET_GPU, 'limit': limit})
|
self._json({'status': 'started', 'gpu': TARGET_GPU, 'limit': limit})
|
||||||
|
|
||||||
@@ -567,7 +568,7 @@ class AgentHandler(BaseHTTPRequestHandler):
|
|||||||
'modelAddress': 'https://www.modelscope.cn/models/Qwen/Qwen3-8B',
|
'modelAddress': 'https://www.modelscope.cn/models/Qwen/Qwen3-8B',
|
||||||
'taskType': 'text-generation',
|
'taskType': 'text-generation',
|
||||||
'targetGpu': TARGET_GPU,
|
'targetGpu': TARGET_GPU,
|
||||||
'framework': 'llama.cpp',
|
'framework': 'vllm',
|
||||||
'strategyId': STRATEGY_ID,
|
'strategyId': STRATEGY_ID,
|
||||||
'configParams': build_config_params(),
|
'configParams': build_config_params(),
|
||||||
},
|
},
|
||||||
@@ -685,7 +686,7 @@ def main():
|
|||||||
json={
|
json={
|
||||||
'modelAddress': 'https://www.modelscope.cn/models/Qwen/Qwen3-8B',
|
'modelAddress': 'https://www.modelscope.cn/models/Qwen/Qwen3-8B',
|
||||||
'taskType': 'text-generation', 'targetGpu': TARGET_GPU,
|
'taskType': 'text-generation', 'targetGpu': TARGET_GPU,
|
||||||
'framework': 'llama.cpp', 'strategyId': STRATEGY_ID,
|
'framework': 'vllm', 'strategyId': STRATEGY_ID,
|
||||||
'configParams': build_config_params(),
|
'configParams': build_config_params(),
|
||||||
}, timeout=10
|
}, timeout=10
|
||||||
)
|
)
|
||||||
@@ -703,7 +704,7 @@ def main():
|
|||||||
try:
|
try:
|
||||||
state['running'] = True
|
state['running'] = True
|
||||||
state['last_run'] = datetime.now().isoformat()
|
state['last_run'] = datetime.now().isoformat()
|
||||||
count = run_pipeline(submit_limit=2)
|
count = run_pipeline(submit_limit=5)
|
||||||
state['last_result'] = {'submitted': count, 'success': True}
|
state['last_result'] = {'submitted': count, 'success': True}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log(f"流程异常: {traceback.format_exc()}")
|
log(f"流程异常: {traceback.format_exc()}")
|
||||||
|
|||||||
Reference in New Issue
Block a user