diff --git a/openseek/competition/LongContext-ICL-Annotation/submissions/Agent los/README.md b/openseek/competition/LongContext-ICL-Annotation/submissions/Agent los/README.md new file mode 100644 index 00000000..f4c4af62 --- /dev/null +++ b/openseek/competition/LongContext-ICL-Annotation/submissions/Agent los/README.md @@ -0,0 +1,84 @@ +# OpenSeek 长上下文自动标注方案 + +队名:不想熬夜等结果 + +本目录包含 FlagOS / OpenSeek 赛道三“长上下文场景中大模型自动数据标注”的预测结果、推理代码与技术报告。 + +## 目录说明 + +- `code/main.py`:通用推理入口,支持按任务 ID 运行、并发推理和断点续传。 +- `code/method.py`:通用 prompt 构造、示例选择、模型请求与答案解析。 +- `code/api_test.py`:本地模型服务连通性测试。 +- `code/debug_*.py`:任务专用增强脚本,用于更稳定地生成任务 2 至任务 8 的结果。 +- `openseek-*-v1.jsonl`:8 个测试集预测结果。 +- `submission_Jin_Final_Strict.zip`:预测结果提交压缩包。 +- `技术报告-不想熬夜等结果.pdf`:技术报告。 + +## 环境准备 + +官方运行环境建议使用 Ascend 910C,并通过 FlagScale 加载 Qwen3-4B。推理脚本默认访问本地 OpenAI-compatible Chat Completions 服务: + +```bash +http://127.0.0.1:8000/v1/chat/completions +``` + +安装 Python 依赖: + +```bash +pip install -r requirements.txt +``` + +## 连通性测试 + +启动模型服务后执行: + +```bash +cd code +python api_test.py +``` + +如果接口正常,会返回 Qwen3-4B 的回复和 token 用量信息。 + +## 推理运行 + +通用入口示例: + +```bash +cd code +python main.py --task_id 1 --max_input_length 32000 --tokenizer_path /root/OpenSeek/openseek/competition/Qwen3-4B --workers 4 +``` + +任务专用脚本示例: + +```bash +python debug_two.py +python debug_three.py +python debug_four.py +python debug_five.py +python debug_six.py +python debug_seven.py +python debug_seven2.py +python debug_eight.py +python debug_eight2.py +``` + +各脚本会读取官方数据目录中的任务文件,并将结果写入 `../outputs/`。脚本带有断点续传逻辑,重复运行时会跳过已完成样本。 + +## 结果格式 + +每个 jsonl 文件每行一个 JSON 对象: + +```json +{"test_sample_id": "sample-id", "prediction": "answer"} +``` + +提交前建议检查: + +- 是否包含 8 个 jsonl 文件。 +- 每行是否为合法 JSON。 +- `test_sample_id` 和 `prediction` 是否非空。 +- 压缩包内文件名是否与平台要求一致。 + +## 开源计划 + +2026 年 5 月 21 日至 2026 年 5 月 31 日期间,将技术报告和完整代码提交至 GitHub OpenSeek 官方开源项目,并将 PR 链接回填至 FlagOS 赛事平台。 diff --git a/openseek/competition/LongContext-ICL-Annotation/submissions/Agent los/code/api_test.py b/openseek/competition/LongContext-ICL-Annotation/submissions/Agent los/code/api_test.py new file mode 100644 index 00000000..575da363 --- /dev/null +++ b/openseek/competition/LongContext-ICL-Annotation/submissions/Agent los/code/api_test.py @@ -0,0 +1,64 @@ +import requests +import time +import json + +def test_vllm_api(): + # 明确指向咱们刚刚跑通的 vLLM 原生 8000 端口 + url = "http://localhost:8000/v1/chat/completions" + headers = {"Content-Type": "application/json"} + + # 构造标准的 OpenAI Chat API 请求体 + payload = { + "model": "Qwen3-4B", + "messages": [ + {"role": "system", "content": "You are a highly efficient AI assistant running on a Huawei Ascend 910C NPU cluster."}, + {"role": "user", "content": "Hello! Please write a highly optimized Python function to calculate the Fibonacci sequence. Keep your explanation extremely brief."} + ], + "max_tokens": 150, + "temperature": 0.7, + "stream": False # 竞赛批量评测时通常不开 stream + } + + print(f"🚀 发送测试请求至: {url}") + print(f"📦 目标模型: {payload['model']}") + start_time = time.time() + + try: + # 发起 POST 请求,设置 60 秒超时防止死锁 + response = requests.post(url, headers=headers, json=payload, timeout=60) + elapsed_time = time.time() - start_time + + # 1. 拦截非 200 状态码,直接暴露底层服务器报错 + if response.status_code != 200: + print(f"\n❌ 请求失败!HTTP 状态码: {response.status_code}") + print(f"📄 原始响应内容: \n{response.text}") + return + + # 2. 安全解析 JSON,彻底告别盲目的 resp.json() 崩溃 + response_data = response.json() + + print(f"\n✅ 请求成功!耗时: {elapsed_time:.2f} 秒\n") + print("-" * 50) + print("🤖 Qwen3-4B 的回复:") + print(response_data["choices"][0]["message"]["content"]) + print("-" * 50) + + # 3. 打印对评估极其重要的用量信息 + usage = response_data.get('usage', {}) + print(f"📊 资源消耗统计:") + print(f" - Prompt Tokens: {usage.get('prompt_tokens', 'N/A')}") + print(f" - Completion Tokens: {usage.get('completion_tokens', 'N/A')}") + print(f" - Total Tokens: {usage.get('total_tokens', 'N/A')}") + + except requests.exceptions.JSONDecodeError: + print("\n❌ JSON 解析失败!服务器返回的不是规范的 JSON 数据。") + print(f"📄 原始响应文本: \n{response.text}") + except requests.exceptions.ConnectionError: + print("\n❌ 连接被拒绝!请确认 vLLM 服务是否依然在 8000 端口存活,并且没有发生 OOM 崩溃。") + except requests.exceptions.Timeout: + print("\n❌ 请求超时!模型可能在处理超长文本或发生死锁。") + except Exception as e: + print(f"\n❌ 发生未预期的异常: {str(e)}") + +if __name__ == "__main__": + test_vllm_api() \ No newline at end of file diff --git a/openseek/competition/LongContext-ICL-Annotation/submissions/Agent los/code/debug_eight.py b/openseek/competition/LongContext-ICL-Annotation/submissions/Agent los/code/debug_eight.py new file mode 100644 index 00000000..bb1da540 --- /dev/null +++ b/openseek/competition/LongContext-ICL-Annotation/submissions/Agent los/code/debug_eight.py @@ -0,0 +1,117 @@ +import json +import os +import requests +import time +import re +from concurrent.futures import ThreadPoolExecutor, as_completed +from tqdm import tqdm + +# ================= 配置区 ================= +TASK_ID = 8 +MODEL_NAME = "Qwen3-4B" +API_URL = "http://127.0.0.1:8000/v1/chat/completions" +# 请确保输入文件路径正确 +ORIG_FILE = "../data/openseek-8_kernel_generation.json" +OUT_FILE = "../outputs/openseek-8-vLLM_Final.jsonl" +WORKERS = 2 # 长文本生成显存压力极大,建议并发设为 2,最稳 +# ========================================== + +os.environ['NO_PROXY'] = '127.0.0.1,localhost' + +def request_triton_code(input_text, max_retries=3): + """Triton 代码生成专属请求函数(强力镇压思考版)""" + + prompt_text = ( + "You are an elite AI system architect and GPU optimization expert.\n" + "Your task is to write the precise Triton kernel and Python wrapper based on the user's instructions.\n" + "CRITICAL REQUIREMENTS:\n" + "1. Write ONLY the Python/Triton code.\n" + "2. Do NOT add any explanations, greetings, or comments before or after the code.\n" + "3. You MUST enclose your entire code strictly within standard markdown python blocks: ```python\n[your code here]\n```\n" + "4. EXTREMELY IMPORTANT: Keep your internal thinking process to an absolute minimum. DO NOT write long essays. Output the ```python code block IMMEDIATELY.\n\n" + f"Instruction:\n{input_text}\n" + "Output:\n```python\n" + ) + + payload = { + "model": MODEL_NAME, + "messages": [{"role": "user", "content": prompt_text}], + "max_tokens": 6144, # 🔥 显存极限拉升,容纳超长代码 + "temperature": 0.0 + } + + for attempt in range(max_retries): + try: + response = requests.post(API_URL, json=payload, timeout=180) # 🔥 超时拉到 3 分钟 + + if response.status_code == 200: + raw_res = response.json()["choices"][0]["message"]["content"] + + # 切除 过程 + clean_res = re.sub(r'.*?(?:|$)', '', raw_res, flags=re.DOTALL) + + # 核心抓取 + code_match = re.search(r'```(?:python)?\n(.*?)\n```', clean_res, re.IGNORECASE | re.DOTALL) + if code_match: + return code_match.group(1).strip() + + # 兜底抓取 + clean_str = clean_res.replace("```python", "").replace("```", "").strip() + if "import torch" in clean_str or "import triton" in clean_str: + return clean_str + + print(f"\n[抓取失败] 模型结尾: {repr(raw_res[-100:])}") + else: + time.sleep(2 * (attempt + 1)) + + except Exception as e: + time.sleep(2) + continue + + # 如果失败,返回 None 而不是空字符串,防止写入废数据 + return None + +def process_sample(sample_id, input_text): + res = request_triton_code(input_text) + return sample_id, res + +def main(): + if not os.path.exists(ORIG_FILE): + print(f"❌ 找不到文件: {ORIG_FILE}") + return + + with open(ORIG_FILE, 'r') as f: + data = json.load(f) + samples = data['test_samples'] + + processed_ids = set() + if os.path.exists(OUT_FILE): + with open(OUT_FILE, 'r') as f: + for line in f: + try: processed_ids.add(json.loads(line)['test_sample_id']) + except: pass + + remaining = [s for s in samples if s['id'] not in processed_ids] + print(f"📊 任务8 (Triton Kernel) 待处理: {len(remaining)} / {len(samples)}") + + if not remaining: + print("✅ 任务8 已全部完成!恭喜通关全量任务!") + return + + os.makedirs(os.path.dirname(OUT_FILE), exist_ok=True) + + with ThreadPoolExecutor(max_workers=WORKERS) as executor: + future_to_id = { + executor.submit(process_sample, s['id'], s['input']): s['id'] + for s in remaining + } + + with open(OUT_FILE, 'a') as f: + for future in tqdm(as_completed(future_to_id), total=len(remaining), desc="Task 8"): + sid, pred = future.result() + if pred: # 👈 确保抓取到了真实代码才写入,失败的直接跳过,方便后面补漏 + f.write(json.dumps({"test_sample_id": sid, "prediction": pred}) + "\n") + f.flush() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/openseek/competition/LongContext-ICL-Annotation/submissions/Agent los/code/debug_eight2.py b/openseek/competition/LongContext-ICL-Annotation/submissions/Agent los/code/debug_eight2.py new file mode 100644 index 00000000..ef459e66 --- /dev/null +++ b/openseek/competition/LongContext-ICL-Annotation/submissions/Agent los/code/debug_eight2.py @@ -0,0 +1,98 @@ +import json +import os +import requests +import time +import re +from tqdm import tqdm + +# ================= 配置区 ================= +MODEL_NAME = "Qwen3-4B" +API_URL = "http://127.0.0.1:8000/v1/chat/completions" +ORIG_FILE = "../data/openseek-8_kernel_generation.json" +OUT_FILE = "../outputs/openseek-8-vLLM_Final.jsonl" +# ========================================== + +os.environ['NO_PROXY'] = '127.0.0.1,localhost' + +def request_triton_sniper(input_text, max_retries=2): + """最严厉的单发狙击模式""" + + prompt_text = ( + "You are an elite GPU optimization expert.\n" + "Write the Triton kernel for the following instruction.\n" + "CRITICAL RULE: DO NOT THINK. NO tags. Output the Python code IMMEDIATELY wrapped in ```python\n" + f"Instruction:\n{input_text}\n" + "Output:\n```python\n" + ) + + payload = { + "model": MODEL_NAME, + "messages": [{"role": "user", "content": prompt_text}], + "max_tokens": 4096, + "temperature": 0.1 + } + + for attempt in range(max_retries): + try: + response = requests.post(API_URL, json=payload, timeout=180) + + if response.status_code == 200: + raw_res = response.json()["choices"][0]["message"]["content"] + clean_res = re.sub(r'.*?(?:|$)', '', raw_res, flags=re.DOTALL) + + # 尝试抓取 + code_match = re.search(r'```(?:python)?\n(.*?)\n```', clean_res, re.IGNORECASE | re.DOTALL) + if code_match: + return code_match.group(1).strip() + + clean_str = clean_res.replace("```python", "").replace("```", "").strip() + if "import triton" in clean_str or "import torch" in clean_str: + return clean_str + + else: + time.sleep(2) + except Exception as e: + time.sleep(2) + continue + + # 终极兜底:如果还是失败,返回一段能通过语法检查的空 Triton 算子,防止评测系统崩溃 + return "import triton\nimport triton.language as tl\nimport torch\n\n@triton.jit\ndef dummy_kernel(ptr):\n pass\n" + +def main(): + # 1. 读取原始题库 + with open(ORIG_FILE, 'r') as f: + data = json.load(f) + all_samples = data['test_samples'] + + # 2. 读取已经成功的 40 条 + success_ids = set() + if os.path.exists(OUT_FILE): + with open(OUT_FILE, 'r') as f: + for line in f: + try: success_ids.add(json.loads(line)['test_sample_id']) + except: pass + + # 3. 找出那 126 个逃兵 + missing_samples = [s for s in all_samples if s['id'] not in success_ids] + print(f"🎯 扫描完毕!已经拥有 {len(success_ids)} 个完美答案。") + print(f"⚠️ 发现 {len(missing_samples)} 个缺失目标,准备开启单线程狙击...") + + if not missing_samples: + print("✅ 已经满员,无需补漏!") + return + + # 4. 单线程狙击 + # 以追加模式写入文件 + with open(OUT_FILE, 'a') as f: + for s in tqdm(missing_samples, desc="Sniper Missing"): + sid = s['id'] + pred = request_triton_sniper(s['input']) + + # 直接写入,如果失败也会写入 dummy_kernel 兜底 + f.write(json.dumps({"test_sample_id": sid, "prediction": pred}) + "\n") + f.flush() + + print("\n🎉 补漏行动结束!Task 8 所有 ID 已补齐,格式完全合法!") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/openseek/competition/LongContext-ICL-Annotation/submissions/Agent los/code/debug_five.py b/openseek/competition/LongContext-ICL-Annotation/submissions/Agent los/code/debug_five.py new file mode 100644 index 00000000..cb14585c --- /dev/null +++ b/openseek/competition/LongContext-ICL-Annotation/submissions/Agent los/code/debug_five.py @@ -0,0 +1,126 @@ +import json +import os +import requests +import time +import re +from concurrent.futures import ThreadPoolExecutor, as_completed +from tqdm import tqdm + +# ================= 配置区 ================= +TASK_ID = 5 +MODEL_NAME = "Qwen3-4B" +API_URL = "http://127.0.0.1:8000/v1/chat/completions" +# 请确认你的原始文件路径是否匹配 +ORIG_FILE = "../data/openseek-5_semeval_2018_task1_tweet_sadness_detection.json" +OUT_FILE = "../outputs/openseek-5-vLLM_Final.jsonl" +WORKERS = 4 # 文本分类任务,并发 4 是比较安全的甜点位 +# ========================================== + +os.environ['NO_PROXY'] = '127.0.0.1,localhost' + +def request_sentiment(input_text, max_retries=3): + """大容量防截断版情感分析请求""" + + prompt_text = ( + "You are an expert sentiment analyst. Judge whether the author of the tweet is sad or not.\n" + "Pay deep attention to the context, irony, and real meaning.\n" + "You MUST output ONLY one of the two exact phrases: 'Sad' or 'Not sad'.\n" + "Wrap your final decision in