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
38 changes: 18 additions & 20 deletions openseek/competition/LongContext-ICL-Annotation/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@

from method import build_prompt, select_examples

from method import annotate_nvidia as annotate # For Nvidia GPU
# from method import annotate_ascend as annotate # For Huawei Ascend
# from method import annotate_nvidia as annotate # For Nvidia GPU
from method import annotate_ascend as annotate # For Huawei Ascend

TASK_FILES = {
1: './data/openseek-1_closest_integers.json',
2: './data/openseek-2_count_nouns_verbs.json',
3: './data/openseek-3_collatz_conjecture.json',
4: './data/openseek-4_conala_concat_strings.json',
5: './data/openseek-5_semeval_2018_task1_tweet_sadness_detection.json',
6: './data/openseek-6_mnli_same_genre_classification.json',
7: './data/openseek-7_jeopardy_answer_generation_all.json',
8: '../data/openseek-8_kernel_generation.json',
1: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-1_closest_integers.json',
2: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-2_count_nouns_verbs.json',
3: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-3_collatz_conjecture.json',
4: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-4_conala_concat_strings.json',
5: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-5_semeval_2018_task1_tweet_sadness_detection.json',
6: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-6_mnli_same_genre_classification.json',
7: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-7_jeopardy_answer_generation_all.json',
8: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-8_kernel_generation.json',
Comment on lines +13 to +20

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Hardcoding absolute paths like /root/OpenSeek/... makes the codebase non-portable and will break on any other environment. It is highly recommended to resolve these paths dynamically relative to the current file's directory.

Suggested change
1: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-1_closest_integers.json',
2: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-2_count_nouns_verbs.json',
3: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-3_collatz_conjecture.json',
4: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-4_conala_concat_strings.json',
5: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-5_semeval_2018_task1_tweet_sadness_detection.json',
6: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-6_mnli_same_genre_classification.json',
7: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-7_jeopardy_answer_generation_all.json',
8: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-8_kernel_generation.json',
1: os.path.join(os.path.dirname(__file__), '../data/openseek-1_closest_integers.json'),
2: os.path.join(os.path.dirname(__file__), '../data/openseek-2_count_nouns_verbs.json'),
3: os.path.join(os.path.dirname(__file__), '../data/openseek-3_collatz_conjecture.json'),
4: os.path.join(os.path.dirname(__file__), '../data/openseek-4_conala_concat_strings.json'),
5: os.path.join(os.path.dirname(__file__), '../data/openseek-5_semeval_2018_task1_tweet_sadness_detection.json'),
6: os.path.join(os.path.dirname(__file__), '../data/openseek-6_mnli_same_genre_classification.json'),
7: os.path.join(os.path.dirname(__file__), '../data/openseek-7_jeopardy_answer_generation_all.json'),
8: os.path.join(os.path.dirname(__file__), '../data/openseek-8_kernel_generation.json'),

}

def parser_args():
Expand All @@ -30,7 +30,7 @@ def parser_args():
default='../outputs/',
help='Prefix path to save the evaluation logs.')
parser.add_argument('--tokenizer_path', type=str,
default='/share/project/wuhaiming/spaces/data_agent/OpenSeek-main/openseek/competition/LongContext-ICL-Annotation/src/Qwen3-4B')
default='/root/Qwen3-4B')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Hardcoding the absolute path /root/Qwen3-4B as the default tokenizer path reduces portability. Consider using an environment variable with a sensible relative default instead.

Suggested change
default='/root/Qwen3-4B')
default=os.environ.get('TOKENIZER_PATH', './Qwen3-4B'))

args = parser.parse_args()
return args

Expand All @@ -48,16 +48,14 @@ def evaluate(task_id:int,

task_name = task_dict['task_name']
task_description = task_dict['Definition'][0]
icl_examples = task_dict['examples'][:100]
icl_examples = task_dict['examples'][:50]
test_samples = task_dict['test_samples']

version = 1
output_file = f'{log_path_prefix}openseek-{task_id}-v{version}.jsonl'
# The evaluation platform currently expects the submission filename to be
# exactly openseek-{task_id}-v1.jsonl.
output_file = f'{log_path_prefix}openseek-{task_id}-v1.jsonl'
output_path = os.path.dirname(output_file)
os.makedirs(output_path, exist_ok=True)
while os.path.exists(output_file):
version += 1
output_file = f'{log_path_prefix}openseek-{task_id}-v{version}.jsonl'
with open(output_file, 'w') as f:
pass

Expand All @@ -79,14 +77,14 @@ def evaluate(task_id:int,
# if tokenized_input['input_ids'].shape[1] > max_input_length:
# test_record['prediction'] = None
# else:
# prediction = annotate(input_prompt)
# prediction = annotate(input_prompt, task_id)
# test_record['prediction'] = prediction
prediction = annotate(input_prompt)
prediction = annotate(input_prompt, task_id)

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

Toggling the active annotation function to annotate_nvidia (by uncommenting line 9 and commenting line 10) will cause a runtime TypeError because annotate_nvidia does not accept the task_id parameter.

To ensure compatibility, please update the signature of annotate_nvidia in method.py to accept task_id: int = None as well, even if it is not used inside the function.

test_record['prediction'] = prediction
with open(output_file, 'a') as f:
f.write(json.dumps(test_record)+'\n')

if __name__ == '__main__':
args = parser_args()
qwen_tokenizer = AutoTokenizer.from_pretrained(args.tokenizer_path)
evaluate(args.task_id, qwen_tokenizer, args.max_input_length, args.log_path_prefix)
evaluate(args.task_id, qwen_tokenizer, args.max_input_length, args.log_path_prefix)
19 changes: 12 additions & 7 deletions openseek/competition/LongContext-ICL-Annotation/src/method.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def select_examples(all_examples: list[dict], task_description: str, text2annota
"""
# 初始化Qwen3-4B的tokenizer(自动下载/加载千问3-4B的分词器)
# 若本地已下载模型,可替换为本地路径,如 "./qwen3-4b"
tokenizer = AutoTokenizer.from_pretrained("/share/project/wuhaiming/spaces/data_agent/OpenSeek-main/openseek/competition/LongContext-ICL-Annotation/src/Qwen3-4B", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("/root/Qwen3-4B", trust_remote_code=True)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Hardcoding the absolute path /root/Qwen3-4B reduces portability. Consider using an environment variable with a relative path fallback.

Suggested change
tokenizer = AutoTokenizer.from_pretrained("/root/Qwen3-4B", trust_remote_code=True)
import os
tokenizer = AutoTokenizer.from_pretrained(os.environ.get("TOKENIZER_PATH", "./Qwen3-4B"), trust_remote_code=True)


# 最大上下文长度限制(Qwen3-4B的上下文窗口默认是8k/32k,可根据实际调整)
target_length = 8192 # 若需严格适配Qwen3-4B,建议改为8192(8k)
Expand Down Expand Up @@ -217,8 +217,6 @@ def count_answer(text: str) -> tuple[list, dict]:
max_count = max(content_counter.values())
answer = [content for content, count in content_counter.items() if count == max_count]

if (len(answer[0]) >= 100):
return None
return answer[0]


Expand All @@ -235,7 +233,7 @@ def annotate_nvidia(input_prompt:str)->list[str]:
data = {
"model": "../Qwen3-4B",
"prompt": input_prompt,
"max_tokens": 10_000, # max_token = 10k
"max_tokens": 1024, # max_token = 10k
}

try:
Expand All @@ -248,7 +246,7 @@ def annotate_nvidia(input_prompt:str)->list[str]:
prediction = count_answer(whole_result)
return prediction

def annotate_ascend(input_prompt:str)->list[str]:
def annotate_ascend(input_prompt:str, task_id:int=None)->list[str]:

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

While adding task_id support to annotate_ascend to handle Task 8 (returning raw Triton code), annotate_nvidia was not updated. If a user switches to annotate_nvidia for Task 8, it will fail to return the raw code because it lacks the task_id check and will instead run count_answer (which returns None since Task 8 output has no <label> tags).

Please update annotate_nvidia to also support task_id and handle Task 8 similarly.

"""
Annotate the unlabeled data using an LLM API (Huawei Ascend).
prompts:
Expand All @@ -258,7 +256,7 @@ def annotate_ascend(input_prompt:str)->list[str]:
import openai
openai.api_key = "EMPTY"
openai.base_url = "http://localhost:9010/v1/"
model = "Qwen3-4B-ascend-flagos"
model = "/root/Qwen3-4B"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Hardcoding the absolute path /root/Qwen3-4B as the model name reduces portability. Consider using an environment variable with a fallback.

Suggested change
model = "/root/Qwen3-4B"
import os
model = os.environ.get("MODEL_PATH", "/root/Qwen3-4B")


messages = [
{"role": "system", "content": "You are a helpful assistant."},
Expand All @@ -269,9 +267,16 @@ def annotate_ascend(input_prompt:str)->list[str]:
messages=messages,
temperature=0.7,
top_p=0.95,
max_tokens=10_000,
max_tokens=1024,
stream=False,
)
whole_result = response.choices[0].message.content

# Special handling for Task 8 (code generation): return raw model output
# Task 8 generates Triton code without <label> tags
if task_id == 8:
return whole_result.strip()

# For other tasks, extract label-tagged content
prediction = count_answer(whole_result)
return prediction
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Python依赖环境配置
# 适用于 Huawei Ascend 910C 环境

# 基础依赖
numpy>=1.24.0
torch>=2.8.0
torch_npu>=2.8.0
Comment on lines +6 to +7

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

PyTorch version 2.8.0 does not exist on PyPI (as of early 2025, the latest stable versions are in the 2.5.x/2.6.x range). Specifying torch>=2.8.0 and torch_npu>=2.8.0 will cause pip install -r requirements.txt to fail with a resolution error. Please update these to the correct, existing versions compatible with your Huawei Ascend environment (e.g., 2.4.0 or 2.1.0).

torchvision>=0.23.0

# 模型与推理
transformers>=4.57.0
vllm_ascend>=0.13.0rc1

# 工具库
tqdm>=4.67.0
requests>=2.32.0
openai>=2.14.0
Binary file not shown.