Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions openseek/competition/LongContext-ICL-Annotation/lsgksqj/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# 快速开始指引

## 1. 环境安装

首先,确保您的 Python 环境版本符合要求(建议 Python 3.9+),然后安装项目所需的依赖库:

```
pip install -r requirements.txt
```

注:您可以根据实际显卡驱动版本或特殊需求手动调整 torch 等核心库的版本。

## 2. 模型下载与验证
运行 model.py 脚本以同步 Qwen3-4B 模型权重。

默认使用 ModelScope 国内源,确保下载速度。

脚本运行结束后,若看到模型成功进行逻辑回复,即代表下载与加载测试完毕。

自定义路径:如需修改存储位置,请在 model.py 中调整 model_dir 参数。

```
python model.py
```

## 3. 部署推理服务 (vLLM)
在控制台启动推理后端。请将 --model 参数替换为您在第 2 步中实际的模型存储路径:

```
python -m vllm.entrypoints.openai.api_server \
--model /path/to/your/Qwen3-4B \
--served-model-name qwen3-4b \
--port 2026 \
--gpu-memory-utilization 0.90 \
--trust-remote-code \
--max-model-len 32768
```
启动成功标志:当控制台输出 Application startup complete. 时,表示 API 服务已就绪。

## 4. 执行自动化标注任务
保持推理服务控制台开启,新建一个控制台窗口并切换至源代码目录:

```
cd code/src
```
单任务运行 (以题目一为例):
```
python main.py --task_id 1
```
全任务一键运行 (依次执行 8 道赛题):
```
for i in {1..8}; do python main.py --task_id $i; done
```
## 项目结构说明
main.py: 标注任务的主入口,负责数据加载、版本控制及结果存证。

method.py: 核心逻辑层。包含 SSD 结构化提示词构建、Qwen 专属 Token 计算以及 count_answer 容错提取算法。

model.py: 模型下载与本地推理推演脚本。

requirements.txt: 项目环境依赖清单。

api_test.py: 用于快速校验 vLLM 服务联通性的测试工具。

## 标注结果输出
所有标注结果将自动存储于项目根目录下的 outputs/ 文件夹中:

.jsonl 文件:存储结构化标注结果(ID + Prediction)。

_responses.txt 文件:完整留存模型原始回复(含思维链),用于实验复盘与 Bug 溯源。

FlagOS 赛事技术方案 - 2026
53 changes: 53 additions & 0 deletions openseek/competition/LongContext-ICL-Annotation/lsgksqj/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from modelscope import snapshot_download
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

print("正在从国内源检查/下载模型...")
model_dir = snapshot_download('qwen/Qwen3-4B')
print(f"模型路径: {model_dir}")

tokenizer = AutoTokenizer.from_pretrained(
model_dir,
use_fast=False,
trust_remote_code=True
)

model = AutoModelForCausalLM.from_pretrained(
model_dir,
torch_dtype="auto",
device_map="auto",
trust_remote_code=True
)

prompt = "介绍一下你自己"
messages = [
{"role": "user", "content": prompt}
]

text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
enable_thinking=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)

print("正在生成回复...")
generated_ids = model.generate(
**model_inputs,
max_new_tokens=32768
)
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()

try:
stop_token_id = tokenizer.convert_tokens_to_ids("</think>")
index = len(output_ids) - output_ids[::-1].index(stop_token_id)
except ValueError:
index = 0

thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")

print("\n" + "="*20 + " 结果输出 " + "="*20)
print("thinking content:", thinking_content)
print("content:", content)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# --- 核心深度学习框架与模型加载 ---
# 支撑 model.py 中的 AutoModelForCausalLM 和 torch
torch>=2.0.0
transformers>=4.37.0
accelerate>=0.26.0
modelscope>=1.11.0

# --- 文本处理与分词 ---
# 支撑 method.py 中的 AutoTokenizer 以及 Qwen 模型的特殊分词需求
sentencepiece
tiktoken
einops

# --- 网络请求与 API 交互 ---
# 支撑 api_test.py 和 method.py 中的 requests 调用
requests>=2.31.0
urllib3>=2.0.0
openai>=1.0.0

# --- 数据处理与进度展示 ---
# 支撑 main.py 中的 tqdm 进度条和数据解析
tqdm
numpy
pandas

# --- 辅助工具 ---
# 处理 jsonl 格式及正则增强
jsonlines
regex
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import requests

url = "http://0.0.0.0:2026/v1/completions"
prompts = [
"Hello, FlagScale + vLLM!",
"Translate 'Hello World' to Chinese.",
"Write a short poem about autumn."
# '用中文写一首短诗,诗句开头用<label>,结尾用</label>包裹起来'
]

for prompt in prompts:
data = {
"model": "../Qwen3-4B",
"prompt": prompt,
"max_tokens": 1000
}
resp = requests.post(url, json=data)
print(f"Prompt: {prompt}")
print("Response:", resp.json(), "\n")

print("*"*50)
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

git clone https://github.com/FlagOpen/FlagScale.git
cd FlagScale

source ~/miniconda3/etc/profile.d/conda.sh
conda create -n flagscale python=3.11.11 -y
conda activate flagscale

pip install --upgrade setuptools

pip --trusted-host pypi.tuna.tsinghua.edu.cn install torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0 --index-url https://download.pytorch.org/whl/cu124

pip install -r ./requirements/requirements-base.txt
pip install -r ./requirements/requirements-common.txt

pip install deepspeed
pip3 install --no-build-isolation transformer_engine[pytorch]==2.6.0.post1
pip install nvidia-cudnn-frontend

cu=$(nvcc --version | grep "Cuda compilation tools" | awk '{print $5}' | cut -d '.' -f 1)
torch=$(pip show torch | grep Version | awk '{print $2}' | cut -d '+' -f 1 | cut -d '.' -f 1,2)
cp=$(python3 --version | awk '{print $2}' | awk -F. '{print $1$2}')
flash_attn_version="2.8.3"
echo "https://github.com/Dao-AILab/flash-attention/releases/download/v${flash_attn_version}/flash_attn-${flash_attn_version}+cu${cu}torch${torch}-cp${cp}-cp${cp}-linux_x86_64.whl"
wget --continue --timeout=60 --no-check-certificate --tries=5 --waitretry=10 https://github.com/Dao-AILab/flash-attention/releases/download/v${flash_attn_version}/flash_attn-${flash_attn_version}+cu${cu}torch${torch}-cp${cp}-cp${cp}-linux_x86_64.whl
flash_attn-${flash_attn_version}+cu${cu}torch${torch}-cp${cp}-cp${cp}-linux_x86_64.whl
# Recommend to download the wheel handly, for example flash_attn-2.8.3+cu12torch2.6cxx11abiFALSE-cp311-cp311-linux_x86_64
pip install flash_attn-2.8.3+cu124torch2.6-cp311-cp311-linux_x86_64.whl
Comment on lines +26 to +28

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

在第 26 行中,仅写了文件名而缺少了 pip install 命令,这会导致脚本执行时出现 command not found 错误。此外,第 28 行硬编码了特定的 flash_attn 版本文件名,如果下载的文件名与硬编码的文件名不一致,安装将会失败。建议直接使用前面定义的变量来动态安装下载好的 wheel 包。

Suggested change
flash_attn-${flash_attn_version}+cu${cu}torch${torch}-cp${cp}-cp${cp}-linux_x86_64.whl
# Recommend to download the wheel handly, for example flash_attn-2.8.3+cu12torch2.6cxx11abiFALSE-cp311-cp311-linux_x86_64
pip install flash_attn-2.8.3+cu124torch2.6-cp311-cp311-linux_x86_64.whl
pip install flash_attn-${flash_attn_version}+cu${cu}torch${torch}-cp${cp}-cp${cp}-linux_x86_64.whl


# maybe slow, be patient
pip install --no-build-isolation "git+https://github.com/Dao-AILab/flash-attention.git@v2.7.2#egg=flashattn-hopper&subdirectory=hopper"


# Maybe slow too, be patient
pip install -r ./requirements/inference/requirements.txt
pip install vllm==0.8.5
python tools/patch/unpatch.py --backend llama.cpp
python tools/patch/unpatch.py --backend omniinfer
python tools/patch/unpatch.py --backend Megatron-LM

pip install build
pip install setuptools-scm
pip install "git+https://github.com/state-spaces/mamba.git@v2.2.4"

pip install -r ./requirements/serving/requirements.txt
pip install --no-build-isolation git+https://github.com/FlagOpen/FlagGems.git@release_v1.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Datasets

This repository provides the official datasets for the **LLM Automatic Data Annotation**.
The datasets are specifically designed to evaluate the capability of Large Language Models (LLMs) to perform **automatic data annotation under ultra-long context settings** using the In-context Learning (ICL) paradigm.


## Overview

- Most tasks require a **minimum ICL context length of 30K tokens**, deliberately exceeding standard context limits to evaluate long-context understanding, prompt engineering, and example selection strategies.
- Task **openseek-8** is configured with a **shorter minimum context length (15K tokens)** and a **smaller test set**, reflecting the unique challenges of **kernel generation**.
- All datasets are released with **fixed and standardized test splits** to ensure fair comparison and reproducibility across submissions.
- The task suite covers a **diverse range of domains and reasoning types**, including symbolic reasoning, linguistic analysis, natural language inference, code-related tasks, and open-ended generation.


| Task ID | task name | Minimum ICL context | Test sample number |
| --- | --- | --- | --- |
| openseek-1 | closest_integers | 30K | 500 |
| openseek-2 | count_nouns_verbs | 30K | 500 |
| openseek-3 | collatz_conjecture | 30K | 500 |
| openseek-4 | conala_concat_strings | 30K | 500 |
| openseek-5 | semeval_2018_task1_tweet_sadness_detection | 30K | 500 |
| openseek-6 | mnli_same_genre_classification | 30K | 500 |
| openseek-7 | jeopardy_answer_generation_all | 30K | 500 |
| openseek-8 | kernel_genernation | 16K | 166 |


## Data Structure
The datasets are organized in JSON format, with each task having its own json file. Here's a brief overview of the data structure:

- `task_id`: A unique identifier for the task.
- "task_name": A short human-readable name of the task.
- `Definition`: A detailed description of what the model should do.
- `examples`: Demonstration samples intended for understanding the task format (not necessarily used for scoring). Each example typically includes: `id`, `input` and `output`.
- `test_samples`: The samples to be predicted by participants. Labels/ground truth is hidden. Each test sample typically includes: `id` and `input`.
- `License`: The dataset license name and/or a URL to the license text, describing allowed use and redistribution.


## Usage Notes

- Participants must use the **official datasets as provided**, without altering test splits or labels, for leaderboard evaluation.
- Any preprocessing steps, context construction strategies, or example selection mechanisms should be clearly described in the accompanying technical report.
- All experimental results must be **fully reproducible** using the datasets in this repository.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 数据集说明

本仓库提供 **LLM Automatic Data Annotation** 的官方数据集。

这些数据集专门用于评估大语言模型(LLMs)在 超长上下文设置 下,使用 In-context Learning(ICL)范式进行 自动数据标注 的能力。

---

## 概览

- 大多数任务要求 **最小 ICL 上下文长度为 30K tokens**,接近 **Qwen3-4B** 的标准上下文限制,以评估长上下文理解、提示工程以及示例选择策略。
- 任务 **openseek-8** 配置了 **更短的最小上下文长度(15K tokens)** 和 **更小的测试集**,以反映**算子生成**的独特挑战。
- 所有数据集均以 **固定且标准化的测试划分** 发布,以确保提交之间的公平比较与可复现性。
- 任务集合覆盖 **多样的领域与推理类型**,包括符号推理、语言学分析、自然语言推断、代码相关任务以及开放式生成。

| Task ID | task name | Minimum ICL context | Test sample number |
| --- | --- | --- | --- |
| openseek-1 | closest_integers | 30K | 500 |
| openseek-2 | count_nouns_verbs | 30K | 500 |
| openseek-3 | collatz_conjecture | 30K | 500 |
| openseek-4 | conala_concat_strings | 30K | 500 |
| openseek-5 | semeval_2018_task1_tweet_sadness_detection | 30K | 500 |
| openseek-6 | mnli_same_genre_classification | 30K | 500 |
| openseek-7 | jeopardy_answer_generation_all | 30K | 500 |
| openseek-8 | kernel_genernation | 16K | 166 |

---

## 数据结构

数据集以 `JSON` 格式组织,每个任务对应一个独立的 `.json` 文件。以下是数据结构的简要说明:

- `task_id`: 任务的唯一标识符。
- `task_name`: 任务的简短、便于理解的人类可读名称。
- `Definition`: 对模型应执行内容的详细描述。
- `examples`: 用于理解任务格式的演示样本(不一定用于计分)。每个示例包含:`id`、`input` 和 `output`。
- `test_samples`: 参赛者需要预测的样本。标签/真实值被隐藏。每个测试样本包含:`id` 和 `input`。
- `License`: 数据集许可证名称和/或许可证文本的 URL,用于说明允许的使用方式与再分发规则。

---

## 使用说明

- 参赛者必须使用**按原样提供的官方数据集**,不得更改测试划分或标签,以用于排行榜评测。
- 任何预处理步骤、上下文构建策略或示例选择机制,都应在随附的技术报告中清晰描述。
- 所有实验结果必须能够使用本仓库中的数据集**完全复现**。
Loading