Files
xc_validation_strategy/main.py

468 lines
18 KiB
Python
Raw Permalink Normal View History

2026-06-12 14:24:27 +08:00
"""
xc_validation_strategy 主入口
2026-06-10 21:42:41 +08:00
2026-06-12 14:24:27 +08:00
启动后执行一次模型验证任务批量提交之后保持 HTTP 服务存活
同时暴露 /healthK8s 探活 /status运行状态
"""
2026-06-10 21:42:41 +08:00
2026-06-12 14:24:27 +08:00
import json
import os
import signal
import threading
from datetime import datetime
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from typing import List, Tuple
2026-06-10 21:42:41 +08:00
2026-06-12 14:24:27 +08:00
import requests
2026-06-10 21:42:41 +08:00
2026-06-12 14:24:27 +08:00
# ══════════════════════════════════════════════════════════
# 配置(全部从环境变量读取,不硬编码敏感信息)
# ══════════════════════════════════════════════════════════
BASE_URL = os.environ.get("BASE_URL", "https://modelhub.org.cn")
SUBMIT_ENDPOINT = "/adminApi/async/task/create-contest-task"
2026-06-10 21:42:41 +08:00
2026-06-14 23:54:02 +08:00
# 通过 curl -X POST https://modelhub.org.cn/adminApi/user/login 获取后填入
2026-07-13 19:43:35 +08:00
AUTH_TOKEN = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyQWNjb3VudCI6Inpob3VzaGFzaGEiLCJpZCI6MTQsInVzZXJSb2xlIjoibGVhZGVyYm9hcmQiLCJleHAiOjE3ODQ1NDc1NDYsImlhdCI6MTc4Mzk0Mjc0Nn0.ZcOqcrfI22LPi4mGMnt164nZGhi61ZxtJGYsoO7fZdM"
2026-06-14 23:54:02 +08:00
CONTEST_API_TOKEN = "ef1ef82f3c9efee413d602345fbe224d"
CONTRIBUTORS = "zhoushasha"
2026-07-13 18:38:55 +08:00
GPU_TYPE = "ppu_zw_810e"
2026-06-14 23:54:02 +08:00
TASK_TYPE = "text-generation"
STRATEGY_ID = os.environ.get("STRATEGY_ID", "") # 平台自动注入,无需修改
2026-06-10 21:42:41 +08:00
2026-06-12 14:24:27 +08:00
HTTP_HOST = "0.0.0.0"
HTTP_PORT = 8080
2026-06-10 21:42:41 +08:00
2026-06-12 14:24:27 +08:00
# ══════════════════════════════════════════════════════════
# 模型列表
# ══════════════════════════════════════════════════════════
2026-06-10 21:42:41 +08:00
ALL_MODEL_IDS = [
"Alienpenguin10/M3PO-bahdanau-trial1-seed123",
"sujalrajpoot/TrueSyncAI-Aurion",
"prithivMLmods/Tureis-Qwen3_QWQ-4B-Exp",
"standrey/listing-parser-llama31-8b-ft-v1-full",
"zarakiquemparte/zarablend-l2-7b",
"linzju/Bio-Medical-Llama-3-8B_EnchTable_FFN",
"leonMW/Qwen3-4B-Thinking-2507-GSPO-Easy",
"longvideoagent/longvideoagent-qwen3-4b",
"ishikaa/acquisition_qwen3b_alpaca_proximity",
"01ai/Yi-9B-200K",
"Gille/StrangeMerges_33-7B-slerp",
"sstoica12/acquisition_llama-3_2-3b_bins_medmcqa_gradient",
"speechlessai/speechless-coding-7b-16k-tora",
"unsloth/Qwen2.5-Math-1.5B-Instruct",
"Yuma42/KangalKhan-Sapphire-7B",
"shadowml/BeagleSempra-7B",
"bralynn/test18",
"m-a-p/OProver-8B-Round1",
"yeen214/test_llama2_7b",
"Xwin-LM/Xwin-LM-7B-V0.2",
"FreedomIntelligence/AceGPT-13B",
"Edcastro/tinyllama-edcastr_JavaScript-v2",
"zarakiquemparte/zaraxe-l2-7b",
"MaziyarPanahi/Llama-3-8B-Instruct-v0.8",
"defog/sqlcoder2",
"SawinuCP/bus_booking_voice_agent_merged",
"j05hr3d/Llama-3.2-3B-Instruct-C_M_T-DOLLY-SEED999",
"Changgil/K2S3-SOLAR-11b-v1.0",
"agentica-org/DeepCoder-1.5B-Preview",
"prithivMLmods/Omni-Reasoner3-Merged",
"ibm-granite/granite-7b-instruct",
"zarakiquemparte/kuchiki-1.1-l2-7b",
"MaziyarPanahi/Llama-3-8B-Instruct-v0.1",
"Magpie-Align/Llama-3.1-8B-Magpie-Align-v0.1",
"prithivMLmods/Neumind-Math-7B-Instruct",
"dphn/dolphin-2.9.3-qwen2-1.5b",
"OpenBuddy/openbuddy-mistral-7b-v13",
"kairawal/Qwen3-4B-TL-SynthDolly-1A-E3",
"sahilnagaralu/movie-script",
"xw1234gan/SFT_Qwen2.5-1.5B-Instruct_cnk12",
"yunjae-won/ubq30i_qwen4b_sft_yl",
"1010happy/qwen3BInstruct_ClaudeDefault",
"yunjae-won/ubq30i_qwen4b_sft_both",
"willieseun/AIMO-Qwen2.5-Math-1.5B-Instruct-Finetuned",
"NousResearch/Yarn-Mistral-7b-64k",
"xiaolesu/OsmosisProofling-GRPO-NT",
"health360/Healix-410M",
"RUC-AIBOX/STILL-3-1.5B-preview",
"cjvt/GaMS-1B",
"Lansechen/Qwen2.5-7B-Open-R1-GRPO-math-lighteval-1epochstop-withformat",
"Charlie911/vicuna-7b-v1.5-general-temporal-merged",
"Kyleyee/cDPO_hh-seed5",
"prithivMLmods/Llama-3.2-3B-Math-Oct",
"Kyleyee/HINGE_hh-seed5",
"arcee-ai/Patent-Instruct-7b",
"jb723/cross_lingual_epoch2",
"davidkim205/komt-mistral-7b-v1",
"kalisai/Nusantara-1.8b-Indo-Chat",
"prithivMLmods/Llama-8B-Distill-CoT",
"Kyleyee/HINGE_hh-seed3",
"simplescaling/s1.1-1.5B",
"sail/Sailor2-3B-SFT",
"allenai/OLMoE-1B-7B-0924-Instruct",
"prithivMLmods/Llama-3.2-6B-AlgoCode",
"CloneBO/OracleLM",
"NousResearch/Yarn-Solar-10b-32k",
"m-a-p/OProver-8B-Base",
"HuggingFaceH4/mistral-7b-sft-alpha",
"Hyeongwon/P2-split2_prob_Qwen3-4B-Base_0312-01",
"martyn/mixtral-megamerge-dare-8x7b-v1",
"Kyleyee/rDPO_hh-seed4",
"jingyeom/seal3.1.6n_7b",
"sonthenguyen/OpenHermes-2.5-Mistral-7B-mt-bench-DPO-reversed_corrupted",
"shibing624/ziya-llama-13b-medical-merged",
"datajuicer/LLaMA-1B-dj-refine-150B",
"ajibawa-2023/Uncensored-Jordan-7B",
"nlpguy/AlloyIngot",
"HuggingFaceTB/SmolLM3-3B",
"allenai/codetulu-2-7b",
"vihangd/dopeyshearedplats-2.7b-v1",
"uukuguy/speechless-code-mistral-7b-v2.0",
"j05hr3d/Llama-3.2-3B-Instruct-C_M_T-ALPACA",
"cognitivetech/Mistral-7B-Inst-0.2-Bulleted-Notes",
"sail/Qwen2.5-Math-1.5B-Oat-Zero",
"reaperdoesntknow/SMOLM2Prover",
"Kyleyee/ORPO_hh-seed5",
"CarrotAI/Llama-3.2-Rabbit-Ko-3B-Instruct",
"NousResearch/Nous-Capybara-7B-V1",
"Vijay3548/InterviewMaster-Llama3.1",
"ReviewHub/qwen3-4b-it-2507-sft-2018-2022-rl-step-20",
"Nos-PT/Llama-Carvalho-PT",
"Gille/StrangeMerges_49-7B-dare_ties",
"Kyleyee/CPO_hh-seed2",
"Kyleyee/cDPO_hh-seed3",
"Kyleyee/DrDPO_hh-seed2",
"sthenno-com/miscii-14b-0218",
"mtgv/MobileLLaMA-2.7B-Chat",
"Novaciano/Alice_In_The_Dark_2-Slerp-RP-3.2-1B",
"Himitsui/KuroMitsu-11B",
"owlninjam/nytheria-3b",
"Kyleyee/DrDPO_hh-seed4",
"Kyleyee/DrDPO_hh-seed5",
"shahzebnaveed/NeuralHermes-2.5-Mistral-7B",
"plaguss/mistal-7b-prm-openrlhf",
"viethq188/Rabbit-7B-v2-DPO-Chat",
"EmbeddedLLM/Mistral-7B-Merge-14-v0.3-ft-step-9984",
"dbpedia/nspm-starcoder-1b",
"psh3333/llama-3.2-3b-grpo-merged",
"saarvajanik/facebook-opt-6.7b-qcqa-ub-16-best-for-KV-cache",
"EmbeddedLLM/Mistral-7B-Merge-14-v0.3",
"xformAI/facebook-opt-125m-qcqa-ub-6-best-for-KV-cache",
"Rev124/llama-3-pruned",
"RatanRohith/NeuralPizza-7B-V0.3",
"mncai/DPO_BC_partial_epoch6",
"zeemen2723/museai-lyrics-gen",
"automerger/OgnoExperiment27-7B",
"sohamb37lexsi/qwen25-3b-legal-correction",
"swift/Meta-Llama-3-8B",
"m-a-p/MuPT-v0-8192-190M",
"Kquant03/Samlagast-7B-laser-bf16",
"VTSNLP/Llama3-ViettelSolutions-8B",
"vihangd/dopeyshearedplats-1.3b-v1",
"HCY123902/qwen25_7b_base_hc_tsss_n32_r1_dpo",
"coder3101/gemma-3-1b-it-heretic",
"Hemkant04/qwen05-resume-job-match-evaluator",
"yekon9/Qwen3-4B-Instruct-2507-heretic",
"uukuguy/Orca-2-13b-f16",
"Kquant03/NeuralTrix-7B-dpo-relaser",
"sambanovasystems/SambaLingo-Russian-Base",
"bineric/NorskGPT-Mistral-7b",
"ReviewHub/qwen3-4b-it-2507-sft-2018-2022-rl-step-10",
"beyoru/EvolLLM",
"driaforall/Dria-Agent-a-3B",
"tlphams/zoyllm-7b-slimorca",
"QuixiAI/WizardLM-33B-V1.0-Uncensored",
"bilalRahib/TinyLLama-NSFW-Chatbot",
"Ahatsham/Llama-3-8B-Instruct_Planning_Feedback_oldaug_v2",
"unsloth/Qwen2.5-Math-1.5B",
"wang7776/Llama-2-7b-chat-hf-30-sparsity",
"hector-gr/RLCR-v4-ks-uniqueness-buf5k-hotpot",
"m-a-p/neo_7b_instruct_v0.1",
"p208p2002/llama-traditional-chinese-120M",
"tartuNLP/Llammas-base",
"riotu-lab/ArabianGPT-01B",
"openaccess-ai-collective/DPOpenHermes-7B",
"Enxin/MovieChat-vicuna",
"Skywork/Skywork-OR1-Math-7B",
"Lugha-Llama/Lugha-Llama-8B-wura_edu",
"laion/allenai-sera-unified-316__Qwen3-8B",
"T1anyu/DeepInnovator",
"mideind/icelandic-gpt-sw3-6.7b-gec",
"Rayeeennnnnnnn/legalmind-chatbot",
"Wanfq/FuseLLM-7B",
"mrvinph/Qwen2.5-0.5B-Instruct-Gensyn-Swarm-placid_wily_woodpecker",
"shivanikerai/Llama-2-7b-chat-hf-title-ner-and-title-suggestions-v2.0",
"Invalid-Null/PeiYangMe-0.7",
"open-unlearning/unlearn_tofu_Llama-3.2-1B-Instruct_forget10_GradDiff_lr1e-05_alpha5_epoch5",
"Tesslate/Tessa-T1-3B",
"LorenaYannnnn/unsafe_compliance-Qwen3-0.6B-OURS_self-seed_1",
"HiTZ/latxa-7b-v1",
"huggyllama/llama-7b",
"FlyPig23/Llama3.2-3B_Paper_Impact_media_SFT_1ep",
"hongzhouyu/FineMedLM-o1",
"shisa-ai/shisa-v1-llama3-8b.lr-5e6",
"senseable/Westlake-7B",
"simplescaling/s1.1-3B",
"Borjan/finki-gpt-140M",
"TinyLlama/TinyLlama_v1.1_chinese",
"Manirajan/interview_tiny",
"ajibawa-2023/Young-Children-Storyteller-Mistral-7B",
"TinyLlama/TinyLlama_v1.1_math_code",
"manotham/Thai-dialogue-transalate_sft_80K",
"nassimjp/Maral-7B-alpha-1",
"MSL7/INEX16-7b",
"Rayeeennnnnnnn/mizan-legal-tunisian",
"maheshrawat18/Qwen3-4B-2507-sft1",
"prithivMLmods/Theta-Crucis-0.6B-Turbo1",
"mlabonne/llama-2-7b-miniguanaco",
"FreekCoolAI/privacy-gemma-qlora",
"lex-hue/Delexa-V0.1-7b",
"goldfish-models/tur_latn_100mb",
"shisa-ai/ablation-18-rafbestseq-shisa-v2-llama-3.1-8b-lr8e6",
"yash-lulla/Legal_AI_Assistant",
"prithivMLmods/Deepthink-Llama-3-8B-Preview",
"prithivMLmods/QwQ-R1-Distill-7B-CoT",
"sstoica12/acquisition_metamath_llama_instruct-3_1-8b-math_format_500_combined_openr1math",
"goldfish-models/rus_cyrl_1000mb",
"goldfish-models/ukr_cyrl_1000mb",
"eren23/dpo-binarized-NeutrixOmnibe-7B",
"RAANA-IA/Gheya-med",
"mesolitica/malaysian-tinyllama-1.1b-16k-instructions-v2",
"bue0912/ToolOmni-Qwen3-4B",
"BRlkl/distill-sft-qwen3-4b-full",
"prithivMLmods/PocketThinker-QwQ-3B-Instruct",
"prithivMLmods/Megatron-Bots-1.7B-Reasoning",
"kumarprince070107/geobot",
"ClaudioSavelli/FAME_GA_llama32-1b-instruct-qa",
"kairawal/Qwen3-0.6B-EL-SynthDolly-1A-E8",
"prithivMLmods/Poseidon-Reasoning-1.7B",
"PKU-Alignment/ProgressGym-HistLlama3-8B-C014-instruct-v0.2",
"unsloth/Qwen2-7B",
"prithivMLmods/Open-Xi-Math-Preview",
"MiniLLM/teacher-gpt2-1.5B",
"Rakancorle1/qwen2.5-7b_Instruct_policy_traj_30k_full",
"prithivMLmods/Lang-Exster-0.5B-Instruct",
"prithivMLmods/Nenque-MoT-0.6B-Elite14",
"posicube/Llama2-chat-AYT-13B",
"lomahony/pythia-70m-helpful-sft",
"kyubeen/code-grpo-checkpoint-950",
"nicholasKluge/TeenyTinyLlama-160m",
"allenai/Llama-3.1-Tulu-3-8B",
"BarraHome/Mistroll-7B-v2.2",
"posicube/Llama-chat-AY-13B",
"hongli-zhan/MINT-empathy-Qwen3-4B",
"jhhj25/qwen3-moe-neuron_structure_drop-p50-s1k-128samples-sft",
"Ikonz-Studios/seva-sarathi-intent-qwen3-1.7b",
"NECOUDBFM/Jellyfish-8B",
"gradients-io-tournaments/augmented-1db17e1d682d23fd",
"Locutusque/LocutusqueXFelladrin-TinyMistral248M-Instruct",
"ChuGyouk/R16",
"oveja1122/toolcalling-merged-demo",
"kmseong/llama3_2_3b-instruct-math-safedelta-scale0.8",
"EleutherAI/SmolLM2-1.7B-magpie-ultra-v1.0-math-431k-s",
"paulml/NeuralOmniBeagleMBX-v3-7B",
"skemessage/Qwen2.5-7B-Instruct-neuron",
2026-06-10 21:42:41 +08:00
]
2026-06-12 14:24:27 +08:00
# ══════════════════════════════════════════════════════════
# 全局状态(供 /status 展示)
# ══════════════════════════════════════════════════════════
_state = {
"strategy_id": STRATEGY_ID,
"phase": "starting", # starting | submitting | done | error
"total": len(ALL_MODEL_IDS),
"submitted": 0,
"failed": 0,
"started_at": None,
"finished_at": None,
}
_shutdown = threading.Event()
# ══════════════════════════════════════════════════════════
# HTTP 服务
# ══════════════════════════════════════════════════════════
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == "/health":
self._json({"status": "ok"})
elif self.path == "/status":
self._json(_state)
else:
self._json({"error": "not found"}, 404)
def _json(self, body: dict, code: int = 200):
payload = json.dumps(body, default=str).encode()
self.send_response(code)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(payload)))
self.end_headers()
self.wfile.write(payload)
def log_message(self, fmt, *args):
print(f"[http] {self.address_string()} {fmt % args}", flush=True)
def _run_http():
server = ThreadingHTTPServer((HTTP_HOST, HTTP_PORT), Handler)
server.timeout = 1
print(f"[http] 监听 {HTTP_HOST}:{HTTP_PORT}", flush=True)
while not _shutdown.is_set():
server.handle_request()
server.server_close()
print("[http] 已关闭", flush=True)
# ══════════════════════════════════════════════════════════
# 业务逻辑
# ══════════════════════════════════════════════════════════
def _submit_task(token: str, model_id: str) -> Tuple[bool, str]:
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {token}",
}
2026-07-13 18:38:55 +08:00
config_content = f"""gpu_type: ppu_zw_810e
2026-06-10 21:42:41 +08:00
framework: vllm
2026-07-13 18:38:55 +08:00
docker_image: harbor.4pd.io/hardcore-tech/asllm:1.10.1-pytorch2.10.0-ubuntu24.04-sail2.1.0-cuda13.0-sglang0.5.10-vllm0.19.0-py312
nv_docker_image: harbor-contest.4pd.io/sunruoxi/vllm-openai-fix-tokenizer:v0.11.0
2026-06-10 21:42:41 +08:00
modelhub_options:
srcRelativePath: leaderboard/modelHubXC/{model_id}
mountPoint: /model
sut_config:
values:
gpu_num: 1
env:
2026-07-13 18:38:55 +08:00
- name: test
value: fp16
command:
- bash
- /opt/t-head/entrypoint.sh
- python3
- -m
- asllm.entrypoints.api_server
- --model
- /model
- --port
- '30000'
- --host
- 0.0.0.0
- --served-model-name
- llm
2026-06-10 21:42:41 +08:00
ref_config:
values:
gpu_num: 1
env:
2026-07-13 18:38:55 +08:00
- name: test
value: fp16
command:
- vllm
- serve
- /model
- --port
- '80'
- --served-model-name
- llm
- --max-model-len
- '2048'
- --gpu-memory-utilization
- '0.9'
- --enforce-eager
- --trust-remote-code
- -tp
- '1'
2026-06-10 21:42:41 +08:00
"""
2026-06-12 14:24:27 +08:00
payload = {
2026-06-10 21:42:41 +08:00
"contestApiToken": CONTEST_API_TOKEN,
2026-06-12 14:24:27 +08:00
"contributors": CONTRIBUTORS,
"gpuTypes": [GPU_TYPE],
"taskType": TASK_TYPE,
"modelId": model_id,
"framework": "vllm",
"strategyId": STRATEGY_ID, # 平台要求
2026-06-10 21:42:41 +08:00
"submissionConfig": [{
2026-06-12 14:24:27 +08:00
"config": config_content,
"gpuType": GPU_TYPE,
"taskType": TASK_TYPE,
}],
2026-06-10 21:42:41 +08:00
}
2026-06-18 15:22:29 +08:00
print(f"[payload] {json.dumps(payload, indent=2, ensure_ascii=False)}", flush=True)
2026-06-10 21:42:41 +08:00
try:
2026-06-12 14:24:27 +08:00
resp = requests.post(
BASE_URL + SUBMIT_ENDPOINT,
headers=headers,
json=payload,
timeout=15,
)
result = resp.json()
if result.get("code") == 0:
task_id = result.get("data", {}).get("id", "")
print(f"[worker] OK {model_id} task_id={task_id}", flush=True)
return True, task_id
2026-06-10 21:42:41 +08:00
else:
2026-06-12 14:24:27 +08:00
print(f"[worker] FAIL {model_id}: {result.get('message')}", flush=True)
return False, ""
2026-06-10 21:42:41 +08:00
except Exception as e:
2026-06-12 14:24:27 +08:00
print(f"[worker] ERROR {model_id}: {e}", flush=True)
return False, ""
2026-06-10 21:42:41 +08:00
2026-06-12 14:24:27 +08:00
def _run_worker():
_state["started_at"] = datetime.utcnow().isoformat()
_state["phase"] = "submitting"
2026-06-10 21:42:41 +08:00
2026-06-12 14:24:27 +08:00
successful: List[Tuple[str, str]] = []
2026-06-14 23:54:02 +08:00
token = AUTH_TOKEN
print("[worker] 使用预设 Token跳过登录", flush=True)
2026-06-10 21:42:41 +08:00
for model_id in ALL_MODEL_IDS:
2026-06-12 14:24:27 +08:00
if _shutdown.is_set():
break
ok, task_id = _submit_task(token, model_id)
if ok:
_state["submitted"] += 1
successful.append((task_id, model_id))
else:
_state["failed"] += 1
# 写入结果文件
try:
with open("submitted_validation_tasks.txt", "w", encoding="utf-8") as f:
for tid, mid in successful:
f.write(f"{tid}\t{mid}\n")
except Exception:
pass
_state["finished_at"] = datetime.utcnow().isoformat()
_state["phase"] = "done"
print(
f"[worker] 完成 submitted={_state['submitted']} failed={_state['failed']}",
flush=True,
)
# 提交完成后继续保持进程存活,等待平台停止
# ══════════════════════════════════════════════════════════
# 入口
# ══════════════════════════════════════════════════════════
def _handle_signal(signum, _frame):
print(f"[main] 收到信号 {signum},正在关闭...", flush=True)
_shutdown.set()
def main():
signal.signal(signal.SIGTERM, _handle_signal)
signal.signal(signal.SIGINT, _handle_signal)
# HTTP 服务线程
http_thread = threading.Thread(target=_run_http, daemon=False)
http_thread.start()
# 提交任务线程
worker_thread = threading.Thread(target=_run_worker, daemon=True)
worker_thread.start()
# 主线程等待 shutdown
_shutdown.wait()
print("[main] 等待 HTTP 服务关闭...", flush=True)
http_thread.join(timeout=5)
print("[main] 退出", flush=True)
2026-06-10 21:42:41 +08:00
if __name__ == "__main__":
main()