初始化项目,由ModelHub XC社区提供模型
Model: rockerritesh/qwen25-14b-awq-offline Source: Original Platform
This commit is contained in:
35
.gitattributes
vendored
Normal file
35
.gitattributes
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||
*.arrow filter=lfs diff=lfs merge=lfs -text
|
||||
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
||||
*.ftz filter=lfs diff=lfs merge=lfs -text
|
||||
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||
*.h5 filter=lfs diff=lfs merge=lfs -text
|
||||
*.joblib filter=lfs diff=lfs merge=lfs -text
|
||||
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
||||
*.model filter=lfs diff=lfs merge=lfs -text
|
||||
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||
*.npy filter=lfs diff=lfs merge=lfs -text
|
||||
*.npz filter=lfs diff=lfs merge=lfs -text
|
||||
*.onnx filter=lfs diff=lfs merge=lfs -text
|
||||
*.ot filter=lfs diff=lfs merge=lfs -text
|
||||
*.parquet filter=lfs diff=lfs merge=lfs -text
|
||||
*.pb filter=lfs diff=lfs merge=lfs -text
|
||||
*.pickle filter=lfs diff=lfs merge=lfs -text
|
||||
*.pkl filter=lfs diff=lfs merge=lfs -text
|
||||
*.pt filter=lfs diff=lfs merge=lfs -text
|
||||
*.pth filter=lfs diff=lfs merge=lfs -text
|
||||
*.rar filter=lfs diff=lfs merge=lfs -text
|
||||
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
||||
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
||||
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.tar filter=lfs diff=lfs merge=lfs -text
|
||||
*.tflite filter=lfs diff=lfs merge=lfs -text
|
||||
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||
*.wasm filter=lfs diff=lfs merge=lfs -text
|
||||
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||
*.zst filter=lfs diff=lfs merge=lfs -text
|
||||
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||
7
README.md
Normal file
7
README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
license: apache-2.0
|
||||
---
|
||||
|
||||
# Qwen2.5-14B-Instruct-AWQ — offline inference bundle
|
||||
|
||||
AWQ 4-bit weights of Qwen2.5-14B-Instruct with a self-contained script.py that runs fully offline (loads from `.`). Fits a 16 GB GPU.
|
||||
35
config.json
Normal file
35
config.json
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"architectures": [
|
||||
"Qwen2ForCausalLM"
|
||||
],
|
||||
"attention_dropout": 0.0,
|
||||
"bos_token_id": 151643,
|
||||
"eos_token_id": 151645,
|
||||
"hidden_act": "silu",
|
||||
"hidden_size": 5120,
|
||||
"initializer_range": 0.02,
|
||||
"intermediate_size": 13824,
|
||||
"max_position_embeddings": 32768,
|
||||
"max_window_layers": 70,
|
||||
"model_type": "qwen2",
|
||||
"num_attention_heads": 40,
|
||||
"num_hidden_layers": 48,
|
||||
"num_key_value_heads": 8,
|
||||
"quantization_config": {
|
||||
"bits": 4,
|
||||
"group_size": 128,
|
||||
"modules_to_not_convert": null,
|
||||
"quant_method": "awq",
|
||||
"version": "gemm",
|
||||
"zero_point": true
|
||||
},
|
||||
"rms_norm_eps": 1e-06,
|
||||
"rope_theta": 1000000.0,
|
||||
"sliding_window": 131072,
|
||||
"tie_word_embeddings": false,
|
||||
"torch_dtype": "float16",
|
||||
"transformers_version": "4.41.1",
|
||||
"use_cache": true,
|
||||
"use_sliding_window": false,
|
||||
"vocab_size": 152064
|
||||
}
|
||||
14
generation_config.json
Normal file
14
generation_config.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"bos_token_id": 151643,
|
||||
"do_sample": true,
|
||||
"eos_token_id": [
|
||||
151645,
|
||||
151643
|
||||
],
|
||||
"pad_token_id": 151643,
|
||||
"repetition_penalty": 1.05,
|
||||
"temperature": 0.7,
|
||||
"top_k": 20,
|
||||
"top_p": 0.8,
|
||||
"transformers_version": "4.41.1"
|
||||
}
|
||||
1
harness_cfg.json
Normal file
1
harness_cfg.json
Normal file
@@ -0,0 +1 @@
|
||||
{"sc_max_passes": 1}
|
||||
360
iol_harness.py
Normal file
360
iol_harness.py
Normal file
@@ -0,0 +1,360 @@
|
||||
"""Pure-Python harness logic for the IOL-AI 2026 submission.
|
||||
|
||||
Kept free of torch/transformers so it can be unit-tested locally without a GPU
|
||||
or the model. ``script.py`` (which runs on the T4) imports from here; so does
|
||||
``test_parsing.py``. Both this file and ``script.py`` are uploaded to the
|
||||
submission repo, so ``import iol_harness`` resolves at run time (the repo root is
|
||||
the working directory and on sys.path[0]).
|
||||
"""
|
||||
|
||||
import ast
|
||||
import json
|
||||
import re
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Item counting
|
||||
# --------------------------------------------------------------------------- #
|
||||
|
||||
# "17. ", "18) ", ... anywhere after start/space/comma/semicolon, followed by
|
||||
# whitespace or end-of-line. Requires whitespace after the . or ) so decimals
|
||||
# like "3.14" are NOT matched.
|
||||
_NUMBERED = re.compile(r"(?:^|[\s,;])(\d{1,3})[.)](?=\s|$)", re.MULTILINE)
|
||||
# "(1)", "(2)" — parenthesised single number. "(1-2)" is NOT matched.
|
||||
_PAREN = re.compile(r"\((\d{1,3})\)")
|
||||
# Explicit item range in the query, e.g. "(1-9)", "(13–16)", "(1—10)".
|
||||
_RANGE = re.compile(r"\((\d{1,3})\s*[-–—]\s*(\d{1,3})\)")
|
||||
|
||||
|
||||
def _distinct(rx, text):
|
||||
return sorted(set(int(x) for x in rx.findall(text or "")))
|
||||
|
||||
|
||||
def _range_count(query):
|
||||
"""Count from an explicit "(a-b)" range in the query, else 0."""
|
||||
best = 0
|
||||
for a, b in _RANGE.findall(query or ""):
|
||||
a, b = int(a), int(b)
|
||||
if b >= a:
|
||||
best = max(best, b - a + 1)
|
||||
return best
|
||||
|
||||
|
||||
def _item_lines(query):
|
||||
"""Non-empty lines after the first non-empty (instruction) line."""
|
||||
lines = [ln for ln in (query or "").splitlines() if ln.strip()]
|
||||
return max(0, len(lines) - 1)
|
||||
|
||||
|
||||
def count_items(context, query, task_type=""):
|
||||
"""How many answers the problem expects (validated on real Linguini data).
|
||||
|
||||
Items live in different places by task type: numbered/bare lines in the
|
||||
query, blanks "(N)" or a numbered list in the context, or an explicit
|
||||
"(a-b)" range in the query. Returns an int >= 1. Biased so that when in
|
||||
doubt it does not under-count (the scorer ignores extra predictions but
|
||||
zero-scores any item a short prediction fails to cover).
|
||||
"""
|
||||
tt = (task_type or "").strip()
|
||||
|
||||
# 1. An explicit range in the query is the strongest, cleanest signal.
|
||||
r = _range_count(query)
|
||||
if r:
|
||||
return r
|
||||
|
||||
qn, qp = _distinct(_NUMBERED, query), _distinct(_PAREN, query)
|
||||
cn, cp = _distinct(_NUMBERED, context), _distinct(_PAREN, context)
|
||||
il = _item_lines(query)
|
||||
|
||||
if tt in ("text_to_num", "num_to_text"):
|
||||
# numbers/words listed as bare lines after the instruction line
|
||||
return max(il, len(qn), len(qp), 1)
|
||||
if tt == "match_letters":
|
||||
# items numbered in the query if present, else numbered in the context
|
||||
return len(qn) or len(cn) or il or 1
|
||||
if tt == "fill_blanks":
|
||||
return max(len(qp), len(qn), len(cp), il, 1)
|
||||
# translation / default
|
||||
n = max(len(qn), len(qp))
|
||||
if n <= 1:
|
||||
# bare item lines in the query, else blanks enumerated in the context
|
||||
n = il if il >= 1 else max(len(cp), 1)
|
||||
return max(n, 1)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Prompt building (task-type aware)
|
||||
# --------------------------------------------------------------------------- #
|
||||
|
||||
SYSTEM_BASE = (
|
||||
"You are an expert solver of International Linguistics Olympiad (IOL) "
|
||||
"problems. Every problem is fully self-contained: use ONLY the data, "
|
||||
"examples and hints given to deduce the grammar, vocabulary and rules of "
|
||||
"the language. Never rely on outside knowledge of the language — work the "
|
||||
"pattern out from the given data. First reason it out silently, then answer "
|
||||
"every numbered item.\n"
|
||||
"OUTPUT FORMAT: respond with ONLY a JSON array of strings — one string per "
|
||||
"numbered item, in the SAME order as the query. No keys, no numbering, no "
|
||||
"commentary, nothing outside the array."
|
||||
)
|
||||
|
||||
_TASK_GUIDANCE = {
|
||||
"translation": (
|
||||
"Each answer is the translation of that item, using the vocabulary and "
|
||||
"grammar you deduced from the data. Answer in the language the query "
|
||||
"names: 'into English' -> English; 'into <language>' -> that language. "
|
||||
"Output only the translated text."
|
||||
),
|
||||
"fill_blanks": (
|
||||
"Work out the rule from the complete rows, then fill each blank with the "
|
||||
"missing form IN THE LANGUAGE BEING ANALYSED (the non-English / target "
|
||||
"language) — never its English meaning. Output only that form."
|
||||
),
|
||||
"match_letters": (
|
||||
"For each numbered item, output ONLY the single UPPERCASE LETTER "
|
||||
"(A, B, C, ...) of its correct match. Never output the matched word, its "
|
||||
"translation, or any text other than the letter."
|
||||
),
|
||||
"text_to_num": (
|
||||
"Work out the number system from the examples, then COMPUTE each value "
|
||||
'and write it in digits (e.g. "285"). Do NOT copy a number from the '
|
||||
"examples — derive the value for each new item. Output only the digits."
|
||||
),
|
||||
"num_to_text": (
|
||||
"Work out the number system from the examples, then CONSTRUCT each number "
|
||||
"as words in the target (task) language using those rules. Do NOT copy an "
|
||||
"example — build the form for the given number. Output only those words."
|
||||
),
|
||||
}
|
||||
_TASK_GUIDANCE_DEFAULT = (
|
||||
"Give exactly what each numbered item asks for, in the form the query "
|
||||
"requests."
|
||||
)
|
||||
|
||||
|
||||
def task_guidance(task_type):
|
||||
return _TASK_GUIDANCE.get((task_type or "").strip(), _TASK_GUIDANCE_DEFAULT)
|
||||
|
||||
|
||||
SYSTEM_COT = (
|
||||
"You are an expert solver of International Linguistics Olympiad (IOL) "
|
||||
"problems. Every problem is self-contained: use ONLY the given data to deduce "
|
||||
"the language's rules — never outside knowledge of the language. Reason "
|
||||
"step by step to work out the pattern, then give your answers.\n"
|
||||
"FINAL LINE: after your reasoning, output ONLY a JSON array of strings — one "
|
||||
"per numbered item, in order — as the very last thing in your reply."
|
||||
)
|
||||
|
||||
|
||||
# One compact, fully synthetic worked example per task type. These teach the
|
||||
# deduce-then-answer pattern and the terse JSON output form WITHOUT using any
|
||||
# real IOL/Linguini data (no contamination). Each answer is verified correct.
|
||||
FEWSHOT = {
|
||||
"translation": [{
|
||||
"user": ("Data from the language Nuu:\nka mi = I see\nka tu = you see\n"
|
||||
"lo mi = I go\nka mi ne = I saw\n\nTranslate into English:\n"
|
||||
"1. lo tu\n2. ka tu ne"),
|
||||
"assistant": '["you go", "you saw"]'}],
|
||||
"text_to_num": [{
|
||||
"user": ("Numbers in Zaz: ta = 1, ba = 2, ka = 10. Tens come before "
|
||||
"ones: 'ka ta' = 11.\n\nWrite in digits:\n1. ka ba\n2. ta"),
|
||||
"assistant": '["12", "1"]'}],
|
||||
"num_to_text": [{
|
||||
"user": ("Numbers in Zaz: ta = 1, ba = 2, ka = 10. Tens come before "
|
||||
"ones: 'ka ta' = 11.\n\nWrite in Zaz:\n1. 12\n2. 10"),
|
||||
"assistant": '["ka ba", "ka"]'}],
|
||||
"fill_blanks": [{
|
||||
"user": ("Verb forms:\nsing | singem | to sing\ndance | (1) | to dance\n\n"
|
||||
"Fill the blanks (1)."),
|
||||
"assistant": '["dancem"]'}],
|
||||
"match_letters": [{
|
||||
"user": ("Clues: 'bo' occurs with fire, 'ka' with stone, 'mi' with water.\n"
|
||||
"Words:\n1. mi\n2. bo\n3. ka\nMeanings:\nA. stone\nB. water\nC. fire\n\n"
|
||||
"Determine the correct correspondences."),
|
||||
"assistant": '["B", "C", "A"]'}],
|
||||
}
|
||||
|
||||
|
||||
def build_messages(context, query, task_type, n, cot=False, fewshot=False):
|
||||
"""Return chat messages. ``n`` = required answer count. ``cot`` = let the
|
||||
model reason before the final JSON array. ``fewshot`` = prepend a synthetic
|
||||
worked example for this task type (demonstrates the deduce-then-answer
|
||||
pattern and terse output form)."""
|
||||
base = SYSTEM_COT if cot else SYSTEM_BASE
|
||||
system = (
|
||||
f"{base}\n{task_guidance(task_type)}\n"
|
||||
f"The JSON array must have EXACTLY {n} string{'s' if n != 1 else ''}."
|
||||
)
|
||||
tail = (
|
||||
f"Answer all {n} item{'s' if n != 1 else ''} as a JSON array of "
|
||||
f"{n} string{'s' if n != 1 else ''}, in order"
|
||||
+ (", after your step-by-step reasoning." if cot else ".")
|
||||
)
|
||||
user = f"{(context or '').strip()}\n\n{(query or '').strip()}\n\n{tail}"
|
||||
|
||||
msgs = [{"role": "system", "content": system}]
|
||||
if fewshot:
|
||||
for ex in FEWSHOT.get((task_type or "").strip(), []):
|
||||
msgs.append({"role": "user", "content": ex["user"]})
|
||||
msgs.append({"role": "assistant", "content": ex["assistant"]})
|
||||
msgs.append({"role": "user", "content": user})
|
||||
return msgs
|
||||
|
||||
|
||||
def max_new_tokens_for(task_type, n, cot=False, cap=1024):
|
||||
"""Heuristic generation budget. ``cot`` adds room for reasoning (bounded by
|
||||
``cap`` to protect the 30-min limit on a T4)."""
|
||||
per_item = 96 if (task_type or "") == "translation" else 40
|
||||
answer_room = 160 + per_item * max(1, n)
|
||||
if cot:
|
||||
return int(min(cap, answer_room + 640))
|
||||
return int(min(cap, answer_room))
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Answer parsing (robust, multi-layer)
|
||||
# --------------------------------------------------------------------------- #
|
||||
|
||||
_FENCE = re.compile(r"```(?:json|python)?\s*(.*?)```", re.DOTALL | re.IGNORECASE)
|
||||
_LINE_NUM = re.compile(r"^\s*[\(\[]?(\d{1,3})[\).\]:]\s*(.*\S)?\s*$")
|
||||
_PREFIX = re.compile(r"^\s*(?:answers?|output|result)\s*[:\-]\s*", re.IGNORECASE)
|
||||
|
||||
|
||||
def _to_str(x):
|
||||
if x is None:
|
||||
return ""
|
||||
if isinstance(x, (list, tuple)):
|
||||
# A nested item (e.g. multiple accepted forms) — join readably.
|
||||
return " ".join(_to_str(e) for e in x)
|
||||
return str(x)
|
||||
|
||||
|
||||
def _strip_quotes(s):
|
||||
s = s.strip()
|
||||
if len(s) >= 2 and s[0] == s[-1] and s[0] in "\"'`":
|
||||
s = s[1:-1].strip()
|
||||
return s
|
||||
|
||||
|
||||
def _clean(s):
|
||||
return _strip_quotes(_to_str(s).strip())
|
||||
|
||||
|
||||
def _strip_fences(text):
|
||||
m = _FENCE.search(text or "")
|
||||
return m.group(1) if m else (text or "")
|
||||
|
||||
|
||||
def _balanced_arrays(text):
|
||||
"""Yield every top-level [...] substring (handles nesting)."""
|
||||
depth, start = 0, -1
|
||||
for i, ch in enumerate(text):
|
||||
if ch == "[":
|
||||
if depth == 0:
|
||||
start = i
|
||||
depth += 1
|
||||
elif ch == "]" and depth > 0:
|
||||
depth -= 1
|
||||
if depth == 0 and start >= 0:
|
||||
yield text[start : i + 1]
|
||||
|
||||
|
||||
def extract_json_array(text):
|
||||
"""Return the LAST bracketed list that parses, as a list of strings, else None.
|
||||
|
||||
'Last' matters for reasoning models: they emit <think>...</think> (often
|
||||
containing brackets) and then the final answer array — we want that final one.
|
||||
"""
|
||||
if not text:
|
||||
return None
|
||||
for frag in reversed(list(_balanced_arrays(text))):
|
||||
for parser in (json.loads, ast.literal_eval):
|
||||
try:
|
||||
value = parser(frag)
|
||||
except Exception:
|
||||
continue
|
||||
if isinstance(value, list):
|
||||
return [_clean(x) for x in value]
|
||||
return None
|
||||
|
||||
|
||||
def parse_numbered_lines(text):
|
||||
"""Parse 'N. answer' / 'N) answer' / '(N) answer' lines -> ordered answers."""
|
||||
found = {}
|
||||
for line in (text or "").splitlines():
|
||||
m = _LINE_NUM.match(line)
|
||||
if m and m.group(2):
|
||||
found[int(m.group(1))] = _clean(m.group(2))
|
||||
if not found:
|
||||
return []
|
||||
return [found[k] for k in sorted(found)]
|
||||
|
||||
|
||||
def _fit(values, n):
|
||||
"""Force ``values`` to exactly ``n`` entries (truncate / pad with '')."""
|
||||
values = list(values)[:n]
|
||||
values += [""] * (n - len(values))
|
||||
return values
|
||||
|
||||
|
||||
def parse_answers(text, n):
|
||||
"""Turn raw model output into exactly ``n`` cleaned answer strings.
|
||||
|
||||
Layers: JSON array -> numbered lines -> plain non-empty lines. Always
|
||||
returns a list of length ``n``; extras are dropped, shortfalls padded so no
|
||||
item is silently missing (the scorer aligns predictions by position).
|
||||
"""
|
||||
n = max(1, int(n))
|
||||
inner = _strip_fences(text)
|
||||
# Reasoning models wrap their scratch-work in <think>...</think>; the answer
|
||||
# follows the closing tag. Keep only what comes after it.
|
||||
if "</think>" in inner:
|
||||
inner = inner.rsplit("</think>", 1)[1]
|
||||
|
||||
arr = extract_json_array(inner)
|
||||
if arr:
|
||||
return _fit(arr, n)
|
||||
|
||||
numbered = parse_numbered_lines(inner)
|
||||
if numbered:
|
||||
return _fit(numbered, n)
|
||||
|
||||
lines = [_clean(_PREFIX.sub("", ln)) for ln in inner.splitlines()]
|
||||
lines = [ln for ln in lines if ln]
|
||||
if lines:
|
||||
return _fit(lines, n)
|
||||
|
||||
single = _clean(inner)
|
||||
return _fit([single] if single else [], n)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Self-consistency: majority vote across passes
|
||||
# --------------------------------------------------------------------------- #
|
||||
|
||||
def majority_vote(passes, n):
|
||||
"""Per-item majority vote across ``passes`` (each a length-n answer list).
|
||||
|
||||
Votes are counted case/space-insensitively but the winner keeps its original
|
||||
casing. Ties break toward the EARLIEST pass — so pass 0 (greedy) acts as a
|
||||
floor: confident items keep the greedy answer, uncertain ones adopt the
|
||||
consensus. Non-empty answers are preferred over blanks. Always returns n items.
|
||||
"""
|
||||
n = max(1, int(n))
|
||||
out = []
|
||||
for i in range(n):
|
||||
col = [p[i] for p in passes if i < len(p)]
|
||||
counts, first = {}, {}
|
||||
for k, ans in enumerate(col):
|
||||
key = _to_str(ans).strip().lower()
|
||||
counts[key] = counts.get(key, 0) + 1
|
||||
if key not in first:
|
||||
first[key] = (k, ans)
|
||||
# drop the empty-string option unless it is all we have
|
||||
nonblank = {k_: v for k_, v in counts.items() if k_ != ""}
|
||||
pool = nonblank or counts
|
||||
if not pool:
|
||||
out.append("")
|
||||
continue
|
||||
best = max(pool, key=lambda kk: (pool[kk], -first[kk][0]))
|
||||
out.append(first[best][1])
|
||||
return out
|
||||
151387
merges.txt
Normal file
151387
merges.txt
Normal file
File diff suppressed because it is too large
Load Diff
3
model-00001-of-00003.safetensors
Normal file
3
model-00001-of-00003.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:4e874dc3b1febb5b22fe74a8793066ae430d90cdbc51765d0a4eb44a82a1fbbd
|
||||
size 3988804408
|
||||
3
model-00002-of-00003.safetensors
Normal file
3
model-00002-of-00003.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:b3b25da74cc854cdc726956f8152f1dda8519c7bb7d4724ac12c1312463e61c8
|
||||
size 3968309440
|
||||
3
model-00003-of-00003.safetensors
Normal file
3
model-00003-of-00003.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:25b97bf28033ed4560387293ce76bd3dc55a22882fea005a10c137b6478dae85
|
||||
size 2023056736
|
||||
1258
model.safetensors.index.json
Normal file
1258
model.safetensors.index.json
Normal file
File diff suppressed because it is too large
Load Diff
117
script.py
Normal file
117
script.py
Normal file
@@ -0,0 +1,117 @@
|
||||
"""IOL-AI 2026 submission entrypoint — PLAIN baseline harness.
|
||||
|
||||
Faithful replica of the official How_to_submit.md baseline (the config the
|
||||
organizers posted as "Baseline-Qwen2.5-14B-AWQ", public score 0.1227): a minimal
|
||||
system prompt, the raw context+query, greedy decoding, 512 new tokens, and a
|
||||
naive newline split of the output with NO forced item count. The only additions
|
||||
are timeout-safe incremental writes (an all-blank submission.csv up front + a
|
||||
periodic flush), which never change the output of a run that finishes in time —
|
||||
they only guarantee a valid partial file if we were ever killed.
|
||||
|
||||
Runs on the platform's T4 (16 GB), offline, within the 30-minute limit. Reads
|
||||
/tmp/data/test.csv, writes submission.csv (id,pred) to the working directory.
|
||||
Model weights (Qwen2.5-14B-Instruct-AWQ) ship in this repo and load from ".".
|
||||
"""
|
||||
|
||||
import os
|
||||
import time
|
||||
|
||||
# Must be set BEFORE importing transformers: no network at run time.
|
||||
os.environ["HF_HUB_OFFLINE"] = "1"
|
||||
os.environ["TRANSFORMERS_OFFLINE"] = "1"
|
||||
os.environ.setdefault("TOKENIZERS_PARALLELISM", "false")
|
||||
|
||||
import json
|
||||
|
||||
import pandas as pd
|
||||
import torch
|
||||
from transformers import AutoModelForCausalLM, AutoTokenizer
|
||||
|
||||
MODEL_ID = "." # weights are shipped in this repo (offline)
|
||||
TEST_CSV = "/tmp/data/test.csv"
|
||||
OUT_CSV = "submission.csv"
|
||||
|
||||
MAX_NEW_TOKENS = 512 # same as the official baseline
|
||||
SAFETY_S = 25 * 60 # stop generating past this; buffer before the 30-min cap
|
||||
WRITE_EVERY = 3 # flush submission.csv every N problems (timeout safety)
|
||||
_START = time.monotonic()
|
||||
|
||||
# The official baseline's exact system prompt.
|
||||
SYSTEM = (
|
||||
"You solve International Linguistics Olympiad problems. Answer every numbered "
|
||||
"item. Put each answer on its own line, in order, with no numbering and no "
|
||||
"extra text."
|
||||
)
|
||||
|
||||
|
||||
def elapsed():
|
||||
return time.monotonic() - _START
|
||||
|
||||
|
||||
def load_model():
|
||||
tok = AutoTokenizer.from_pretrained(MODEL_ID)
|
||||
model = AutoModelForCausalLM.from_pretrained(
|
||||
MODEL_ID,
|
||||
torch_dtype=torch.float16, # T4 has no bfloat16
|
||||
device_map="auto",
|
||||
).eval()
|
||||
if tok.pad_token_id is None:
|
||||
tok.pad_token = tok.eos_token
|
||||
return tok, model
|
||||
|
||||
|
||||
def main():
|
||||
df = pd.read_csv(TEST_CSV, dtype=str).fillna("")
|
||||
total = len(df)
|
||||
print(f"loaded {total} problems from {TEST_CSV}", flush=True)
|
||||
|
||||
# Write a COMPLETE all-blank submission.csv up front so a valid file with
|
||||
# every id always exists, even if we are killed during load or generation.
|
||||
records = [
|
||||
{"id": df.iloc[i]["id"], "pred": json.dumps([], ensure_ascii=False)}
|
||||
for i in range(total)
|
||||
]
|
||||
|
||||
def flush():
|
||||
pd.DataFrame(records, columns=["id", "pred"]).to_csv(OUT_CSV, index=False)
|
||||
|
||||
flush()
|
||||
print(f"wrote blank {OUT_CSV} ({total} rows) at {elapsed():.0f}s", flush=True)
|
||||
|
||||
tok, model = load_model()
|
||||
print(f"model loaded at {elapsed():.0f}s", flush=True)
|
||||
|
||||
for i in range(total):
|
||||
if elapsed() > SAFETY_S:
|
||||
print(f"[warn] time budget hit at problem {i}; leaving the rest blank", flush=True)
|
||||
break
|
||||
r = df.iloc[i]
|
||||
messages = [
|
||||
{"role": "system", "content": SYSTEM},
|
||||
{"role": "user", "content": f"{r['context'].strip()}\n\n{r['query'].strip()}"},
|
||||
]
|
||||
try:
|
||||
ids = tok.apply_chat_template(
|
||||
messages, add_generation_prompt=True, return_tensors="pt",
|
||||
).to(model.device)
|
||||
with torch.no_grad():
|
||||
out = model.generate(
|
||||
ids, max_new_tokens=MAX_NEW_TOKENS,
|
||||
do_sample=False, pad_token_id=tok.pad_token_id,
|
||||
)
|
||||
text = tok.decode(out[0][ids.shape[-1]:], skip_special_tokens=True).strip()
|
||||
answers = [ln.strip() for ln in text.splitlines() if ln.strip()]
|
||||
except Exception as exc:
|
||||
print(f"[warn] id={r['id']} failed: {exc!r}", flush=True)
|
||||
answers = []
|
||||
records[i]["pred"] = json.dumps(answers, ensure_ascii=False)
|
||||
if (i + 1) % WRITE_EVERY == 0:
|
||||
flush()
|
||||
print(f"{i + 1}/{total} done at {elapsed():.0f}s", flush=True)
|
||||
|
||||
flush()
|
||||
print(f"final {OUT_CSV} ({total} rows) at {elapsed():.0f}s", flush=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
303282
tokenizer.json
Normal file
303282
tokenizer.json
Normal file
File diff suppressed because it is too large
Load Diff
207
tokenizer_config.json
Normal file
207
tokenizer_config.json
Normal file
@@ -0,0 +1,207 @@
|
||||
{
|
||||
"add_bos_token": false,
|
||||
"add_prefix_space": false,
|
||||
"added_tokens_decoder": {
|
||||
"151643": {
|
||||
"content": "<|endoftext|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151644": {
|
||||
"content": "<|im_start|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151645": {
|
||||
"content": "<|im_end|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151646": {
|
||||
"content": "<|object_ref_start|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151647": {
|
||||
"content": "<|object_ref_end|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151648": {
|
||||
"content": "<|box_start|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151649": {
|
||||
"content": "<|box_end|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151650": {
|
||||
"content": "<|quad_start|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151651": {
|
||||
"content": "<|quad_end|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151652": {
|
||||
"content": "<|vision_start|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151653": {
|
||||
"content": "<|vision_end|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151654": {
|
||||
"content": "<|vision_pad|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151655": {
|
||||
"content": "<|image_pad|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151656": {
|
||||
"content": "<|video_pad|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151657": {
|
||||
"content": "<tool_call>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": false
|
||||
},
|
||||
"151658": {
|
||||
"content": "</tool_call>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": false
|
||||
},
|
||||
"151659": {
|
||||
"content": "<|fim_prefix|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": false
|
||||
},
|
||||
"151660": {
|
||||
"content": "<|fim_middle|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": false
|
||||
},
|
||||
"151661": {
|
||||
"content": "<|fim_suffix|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": false
|
||||
},
|
||||
"151662": {
|
||||
"content": "<|fim_pad|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": false
|
||||
},
|
||||
"151663": {
|
||||
"content": "<|repo_name|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": false
|
||||
},
|
||||
"151664": {
|
||||
"content": "<|file_sep|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": false
|
||||
}
|
||||
},
|
||||
"additional_special_tokens": [
|
||||
"<|im_start|>",
|
||||
"<|im_end|>",
|
||||
"<|object_ref_start|>",
|
||||
"<|object_ref_end|>",
|
||||
"<|box_start|>",
|
||||
"<|box_end|>",
|
||||
"<|quad_start|>",
|
||||
"<|quad_end|>",
|
||||
"<|vision_start|>",
|
||||
"<|vision_end|>",
|
||||
"<|vision_pad|>",
|
||||
"<|image_pad|>",
|
||||
"<|video_pad|>"
|
||||
],
|
||||
"bos_token": null,
|
||||
"chat_template": "{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if messages[0]['role'] == 'system' %}\n {{- messages[0]['content'] }}\n {%- else %}\n {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}\n {%- endif %}\n {{- \"\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\\n\\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{\\\"name\\\": <function-name>, \\\"arguments\\\": <args-json-object>}\\n</tool_call><|im_end|>\\n\" }}\n{%- else %}\n {%- if messages[0]['role'] == 'system' %}\n {{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }}\n {%- else %}\n {{- '<|im_start|>system\\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- for message in messages %}\n {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) or (message.role == \"assistant\" and not message.tool_calls) %}\n {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {{- '<|im_start|>' + message.role }}\n {%- if message.content %}\n {{- '\\n' + message.content }}\n {%- endif %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '\\n<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {{- tool_call.arguments | tojson }}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- message.content }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n{%- endif %}\n",
|
||||
"clean_up_tokenization_spaces": false,
|
||||
"eos_token": "<|im_end|>",
|
||||
"errors": "replace",
|
||||
"model_max_length": 131072,
|
||||
"pad_token": "<|endoftext|>",
|
||||
"split_special_tokens": false,
|
||||
"tokenizer_class": "Qwen2Tokenizer",
|
||||
"unk_token": null
|
||||
}
|
||||
1
vocab.json
Normal file
1
vocab.json
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user