Text Generation
Transformers
Safetensors
qwen3
code
reasoning
lora-merged
livecodebench
conversational
text-generation-inference
Instructions to use modrill/code-think-q4b-20260908 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use modrill/code-think-q4b-20260908 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="modrill/code-think-q4b-20260908") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("modrill/code-think-q4b-20260908") model = AutoModelForCausalLM.from_pretrained("modrill/code-think-q4b-20260908", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use modrill/code-think-q4b-20260908 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "modrill/code-think-q4b-20260908" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "modrill/code-think-q4b-20260908", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/modrill/code-think-q4b-20260908
- SGLang
How to use modrill/code-think-q4b-20260908 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "modrill/code-think-q4b-20260908" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "modrill/code-think-q4b-20260908", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "modrill/code-think-q4b-20260908" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "modrill/code-think-q4b-20260908", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use modrill/code-think-q4b-20260908 with Docker Model Runner:
docker model run hf.co/modrill/code-think-q4b-20260908
Add provenance/build_mix_distill_payload.py
Browse files
provenance/build_mix_distill_payload.py
ADDED
|
@@ -0,0 +1,789 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Build Mix Distillation 1ep/2ep payload for Q4B-THINK-MIX (Li et al. 2025 Mix-Large).
|
| 3 |
+
|
| 4 |
+
30B-A3B-Thinking : 4B-Thinking = 0.2 : 0.8 by row/problem count. One teacher
|
| 5 |
+
trace per problem. Dose target 32,436,894 assistant tokens/ep (±1%), physical
|
| 6 |
+
2ep concat same order. V4 recipe otherwise unchanged.
|
| 7 |
+
"""
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import hashlib
|
| 11 |
+
import json
|
| 12 |
+
import math
|
| 13 |
+
import random
|
| 14 |
+
import sys
|
| 15 |
+
from datetime import datetime, timezone
|
| 16 |
+
from pathlib import Path
|
| 17 |
+
from typing import Any
|
| 18 |
+
|
| 19 |
+
import pyarrow as pa
|
| 20 |
+
import pyarrow.parquet as pq
|
| 21 |
+
|
| 22 |
+
ROOT = Path("/workspace/code-sft-runs/t30b2507-q4b-tn-v2-lr1e4-e1-20260907")
|
| 23 |
+
ARM = ROOT / "arms" / "Q4B-THINK-MIX"
|
| 24 |
+
DATA = ARM / "data"
|
| 25 |
+
P30_2EP = ROOT / "data" / "THINK_PAIRED_V4_2EP.parquet"
|
| 26 |
+
P30_2EP_SHA = "c160713fea76eae124dbbc3b5c619d3164862da83f61d91d3970ede990a12540"
|
| 27 |
+
P30_1EP_ROWS = 4715
|
| 28 |
+
P4 = ROOT / "arms" / "Q4B-THINK-T4BDATA" / "data" / "joint-full-t4b_tail151643.parquet"
|
| 29 |
+
P4_SHA = "d09c4d6272de7e50c9b2df0e401878864f09bda33db05a5833c43575969fa524"
|
| 30 |
+
P4_ROWS = 3866
|
| 31 |
+
OUT_1EP = DATA / "mix_l0.2_s0.8_tail151643.parquet"
|
| 32 |
+
OUT_2EP = DATA / "mix_l0.2_s0.8_tail151643_2EP.parquet"
|
| 33 |
+
READY = DATA / "mix_l0.2_s0.8_tail151643_2EP_READY.json"
|
| 34 |
+
CENSUS = DATA / "TOKEN_CENSUS_MIX.json"
|
| 35 |
+
MQ0_OUT = DATA / "MQ0_NEAR_DUP.json"
|
| 36 |
+
V4_POLICY = ROOT / "arms" / "Q4B-THINK" / "POLICY.json"
|
| 37 |
+
V4_CFG = ROOT / "arms" / "Q4B-THINK-T4BDATA" / "TRAINING_CONFIG.json"
|
| 38 |
+
V4_LAUNCH = ROOT / "arms" / "Q4B-THINK-T4BDATA" / "control" / "LAUNCH.json"
|
| 39 |
+
WORKER = Path("/workspace/tools/rstar_dual_worker_v4.py")
|
| 40 |
+
RUN_ID = "t30b2507-q4b-think-mix-l0.2-s0.8-v4-tail151643"
|
| 41 |
+
ARM_ID = "Q4B-THINK-MIX"
|
| 42 |
+
SEED = 42
|
| 43 |
+
TARGET_1EP = 32_436_894
|
| 44 |
+
TOL = 0.01
|
| 45 |
+
RATIO_30, RATIO_4 = 1, 4
|
| 46 |
+
|
| 47 |
+
sys.path.insert(0, str(ROOT / "scripts"))
|
| 48 |
+
sys.path.insert(0, "/workspace/code-sft-infra/src")
|
| 49 |
+
sys.path.insert(0, "/workspace/tools")
|
| 50 |
+
sys.path.insert(0, "/workspace/code_think_30b_main_20260906/scripts")
|
| 51 |
+
|
| 52 |
+
from code_sft_infra.contracts import document_digest, sha256_file # noqa: E402
|
| 53 |
+
from code_sft_infra.evaluation import build_lcb_prompt_messages # noqa: E402
|
| 54 |
+
from code_sft_infra.rendering import render_completion_only # noqa: E402
|
| 55 |
+
from code_sft_infra.source_census import load_hash_denylist # noqa: E402
|
| 56 |
+
import materialize_t30b_g2_fenced as think_m # noqa: E402
|
| 57 |
+
import near_dup_scan # noqa: E402
|
| 58 |
+
import select_core # noqa: E402
|
| 59 |
+
import v4_render_lib # noqa: E402
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def _sha256_bytes_file(path: Path) -> str:
|
| 63 |
+
digest = hashlib.sha256()
|
| 64 |
+
with path.open("rb") as handle:
|
| 65 |
+
for chunk in iter(lambda: handle.read(8 << 20), b""):
|
| 66 |
+
digest.update(chunk)
|
| 67 |
+
return digest.hexdigest()
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def _pct(values: list[int], p: float) -> float:
|
| 71 |
+
if not values:
|
| 72 |
+
return float("nan")
|
| 73 |
+
xs = sorted(values)
|
| 74 |
+
if len(xs) == 1:
|
| 75 |
+
return float(xs[0])
|
| 76 |
+
k = (len(xs) - 1) * p / 100.0
|
| 77 |
+
lo = int(math.floor(k))
|
| 78 |
+
hi = int(math.ceil(k))
|
| 79 |
+
if lo == hi:
|
| 80 |
+
return float(xs[lo])
|
| 81 |
+
return xs[lo] + (xs[hi] - xs[lo]) * (k - lo)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def mq0_all_hits(rows: list[dict[str, Any]]) -> tuple[dict[str, Any], list[dict[str, Any]]]:
|
| 85 |
+
summary = think_m.run_mq0(rows)
|
| 86 |
+
if summary.get("coverage") != "6_OF_6":
|
| 87 |
+
raise SystemExit(f"MQ0 coverage not 6_OF_6: {summary}")
|
| 88 |
+
if summary.get("status") in {"blocked_before_train"}:
|
| 89 |
+
raise SystemExit(f"MQ0 blocked: {summary}")
|
| 90 |
+
denylist, _ = load_hash_denylist(think_m.DENYLIST_PATH)
|
| 91 |
+
extra, _ = think_m.load_eval_extra_signatures()
|
| 92 |
+
union = set(denylist) | extra
|
| 93 |
+
hits: list[dict[str, Any]] = []
|
| 94 |
+
for row in rows:
|
| 95 |
+
overlap = sorted(think_m.train_signatures(row) & union)
|
| 96 |
+
if overlap:
|
| 97 |
+
hits.append(
|
| 98 |
+
{
|
| 99 |
+
"problem_hash": row["problem_hash"],
|
| 100 |
+
"problem_id": row.get("problem_id"),
|
| 101 |
+
"overlap_n": len(overlap),
|
| 102 |
+
"overlap_head": overlap[:3],
|
| 103 |
+
"reason": "mq0_intersection",
|
| 104 |
+
}
|
| 105 |
+
)
|
| 106 |
+
if len(hits) != int(summary.get("intersection") or 0):
|
| 107 |
+
raise SystemExit(
|
| 108 |
+
f"MQ0 hit count mismatch full={len(hits)} summary={summary.get('intersection')}"
|
| 109 |
+
)
|
| 110 |
+
return summary, hits
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def _index(rows: list[dict[str, Any]], label: str) -> dict[str, dict[str, Any]]:
|
| 114 |
+
out: dict[str, dict[str, Any]] = {}
|
| 115 |
+
pids: dict[str, str] = {}
|
| 116 |
+
for row in rows:
|
| 117 |
+
h = str(row["problem_hash"])
|
| 118 |
+
pid = str(row["problem_id"])
|
| 119 |
+
if h in out:
|
| 120 |
+
raise SystemExit(f"{label} duplicate problem_hash {h}")
|
| 121 |
+
if pid in pids:
|
| 122 |
+
raise SystemExit(f"{label} duplicate problem_id {pid}")
|
| 123 |
+
out[h] = row
|
| 124 |
+
pids[pid] = h
|
| 125 |
+
return out
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def _fill(
|
| 129 |
+
union: list[str],
|
| 130 |
+
preferred: dict[str, str],
|
| 131 |
+
only30: set[str],
|
| 132 |
+
only4: set[str],
|
| 133 |
+
n30: int,
|
| 134 |
+
n4: int,
|
| 135 |
+
) -> tuple[list[str], list[str]]:
|
| 136 |
+
picked_30: list[str] = []
|
| 137 |
+
picked_4: list[str] = []
|
| 138 |
+
for h in union:
|
| 139 |
+
if len(picked_30) >= n30 and len(picked_4) >= n4:
|
| 140 |
+
break
|
| 141 |
+
if h in only30:
|
| 142 |
+
if len(picked_30) < n30:
|
| 143 |
+
picked_30.append(h)
|
| 144 |
+
continue
|
| 145 |
+
if h in only4:
|
| 146 |
+
if len(picked_4) < n4:
|
| 147 |
+
picked_4.append(h)
|
| 148 |
+
continue
|
| 149 |
+
pref = preferred[h]
|
| 150 |
+
if pref == "30b" and len(picked_30) < n30:
|
| 151 |
+
picked_30.append(h)
|
| 152 |
+
elif pref == "4b" and len(picked_4) < n4:
|
| 153 |
+
picked_4.append(h)
|
| 154 |
+
elif pref == "30b" and len(picked_4) < n4:
|
| 155 |
+
picked_4.append(h)
|
| 156 |
+
elif pref == "4b" and len(picked_30) < n30:
|
| 157 |
+
picked_30.append(h)
|
| 158 |
+
return picked_30, picked_4
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
def _sample_record(i: int, row: dict[str, Any], tok: Any) -> dict[str, Any]:
|
| 162 |
+
reason = str(row.get("reasoning") or "")
|
| 163 |
+
answer = str(row.get("final_answer") or "")
|
| 164 |
+
rendered = v4_render_lib.render_qwen(
|
| 165 |
+
tok,
|
| 166 |
+
mode="think",
|
| 167 |
+
prompt=str(row["prompt"] or ""),
|
| 168 |
+
reasoning=reason,
|
| 169 |
+
answer=answer,
|
| 170 |
+
)
|
| 171 |
+
rec = {
|
| 172 |
+
"i": i,
|
| 173 |
+
"teacher_source": row["teacher_source"],
|
| 174 |
+
"problem_id": row["problem_id"],
|
| 175 |
+
"problem_hash": row["problem_hash"],
|
| 176 |
+
"prompt_head": str(row["prompt"])[:160].replace("\n", " "),
|
| 177 |
+
"think_in_reason": "<think>" in reason,
|
| 178 |
+
"think_close_in_reason": "</think>" in reason,
|
| 179 |
+
"code_fence_in_answer": "```" in answer,
|
| 180 |
+
"final_answer_head": answer[:120].replace("\n", "\\n"),
|
| 181 |
+
"assistant_target_tokens": int(row["assistant_target_tokens"]),
|
| 182 |
+
"full_tokens": int(row["full_tokens"]),
|
| 183 |
+
"rendered_think_open": rendered.target_text.lower().count("<think>"),
|
| 184 |
+
"rendered_think_close": rendered.target_text.lower().count("</think>"),
|
| 185 |
+
"rendered_code_fence": "```" in rendered.target_text,
|
| 186 |
+
"last_token": rendered.last_token_id,
|
| 187 |
+
"active_match": rendered.active_tokens == int(row["assistant_target_tokens"]),
|
| 188 |
+
"full_match": rendered.full_tokens == int(row["full_tokens"]),
|
| 189 |
+
}
|
| 190 |
+
if rec["rendered_think_open"] != 1 or rec["rendered_think_close"] != 1:
|
| 191 |
+
raise SystemExit(f"think pair not 1/1 i={i} {rec}")
|
| 192 |
+
if not rec["rendered_code_fence"]:
|
| 193 |
+
raise SystemExit(f"missing code fence i={i} {rec}")
|
| 194 |
+
if rec["last_token"] != 151643:
|
| 195 |
+
raise SystemExit(f"tail not 151643 i={i} last={rec['last_token']}")
|
| 196 |
+
return rec
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
def main() -> int:
|
| 200 |
+
DATA.mkdir(parents=True, exist_ok=True)
|
| 201 |
+
for sub in ("out", "status", "logs", "control"):
|
| 202 |
+
(ARM / sub).mkdir(parents=True, exist_ok=True)
|
| 203 |
+
|
| 204 |
+
sha30 = _sha256_bytes_file(P30_2EP)
|
| 205 |
+
if sha30 != P30_2EP_SHA:
|
| 206 |
+
raise SystemExit(f"30B 2EP sha mismatch {sha30} != {P30_2EP_SHA}")
|
| 207 |
+
sha4 = _sha256_bytes_file(P4)
|
| 208 |
+
if sha4 != P4_SHA:
|
| 209 |
+
raise SystemExit(f"4B 1ep sha mismatch {sha4} != {P4_SHA}")
|
| 210 |
+
|
| 211 |
+
t30_all = pq.read_table(P30_2EP)
|
| 212 |
+
if t30_all.num_rows != P30_1EP_ROWS * 2:
|
| 213 |
+
raise SystemExit(f"30B 2EP rows {t30_all.num_rows} != {P30_1EP_ROWS * 2}")
|
| 214 |
+
t30 = t30_all.slice(0, P30_1EP_ROWS)
|
| 215 |
+
t4 = pq.read_table(P4)
|
| 216 |
+
if t4.num_rows != P4_ROWS:
|
| 217 |
+
raise SystemExit(f"4B rows {t4.num_rows} != {P4_ROWS}")
|
| 218 |
+
if list(t30.schema.names) != list(t4.schema.names):
|
| 219 |
+
raise SystemExit(f"schema names differ 30B={t30.schema.names} 4B={t4.schema.names}")
|
| 220 |
+
for name in t30.schema.names:
|
| 221 |
+
if str(t30.schema.field(name).type) != str(t4.schema.field(name).type):
|
| 222 |
+
raise SystemExit(f"schema type differ {name}")
|
| 223 |
+
|
| 224 |
+
rows30 = t30.to_pylist()
|
| 225 |
+
rows4 = t4.to_pylist()
|
| 226 |
+
tok30 = sum(int(r["assistant_target_tokens"]) for r in rows30)
|
| 227 |
+
tok4_pool = sum(int(r["assistant_target_tokens"]) for r in rows4)
|
| 228 |
+
if tok30 != TARGET_1EP:
|
| 229 |
+
raise SystemExit(f"30B 1ep tokens {tok30} != {TARGET_1EP}")
|
| 230 |
+
if tok4_pool != 30_327_765:
|
| 231 |
+
raise SystemExit(f"4B 1ep tokens {tok4_pool} != 30327765")
|
| 232 |
+
|
| 233 |
+
map30 = _index(rows30, "30B")
|
| 234 |
+
map4 = _index(rows4, "4B")
|
| 235 |
+
h30, h4 = set(map30), set(map4)
|
| 236 |
+
inter = h30 & h4
|
| 237 |
+
only30 = h30 - h4
|
| 238 |
+
only4 = h4 - h30
|
| 239 |
+
union_set = h30 | h4
|
| 240 |
+
pid30 = {str(map30[h]["problem_id"]) for h in h30}
|
| 241 |
+
pid4 = {str(map4[h]["problem_id"]) for h in h4}
|
| 242 |
+
if len(pid30 & pid4) != len(inter):
|
| 243 |
+
raise SystemExit("problem_id intersection size != problem_hash intersection")
|
| 244 |
+
for h in inter:
|
| 245 |
+
if str(map30[h]["problem_id"]) != str(map4[h]["problem_id"]):
|
| 246 |
+
raise SystemExit(f"hash/id mismatch {h}")
|
| 247 |
+
|
| 248 |
+
print(
|
| 249 |
+
"UNIVERSE",
|
| 250 |
+
json.dumps(
|
| 251 |
+
{
|
| 252 |
+
"union": len(union_set),
|
| 253 |
+
"intersect": len(inter),
|
| 254 |
+
"only30": len(only30),
|
| 255 |
+
"only4": len(only4),
|
| 256 |
+
"pid_intersect": len(pid30 & pid4),
|
| 257 |
+
"pid_only30": len(pid30 - pid4),
|
| 258 |
+
"pid_only4": len(pid4 - pid30),
|
| 259 |
+
}
|
| 260 |
+
),
|
| 261 |
+
)
|
| 262 |
+
|
| 263 |
+
mean30 = tok30 / len(rows30)
|
| 264 |
+
mean4 = tok4_pool / len(rows4)
|
| 265 |
+
n30_est = max(1, int(round(TARGET_1EP / (mean30 * RATIO_30 + mean4 * RATIO_4))))
|
| 266 |
+
n4_est = n30_est * RATIO_4
|
| 267 |
+
print("EST", n30_est, n4_est, "mean30", mean30, "mean4", mean4)
|
| 268 |
+
need4_tok = 0.8 * TARGET_1EP
|
| 269 |
+
shortfall_notes: list[str] = []
|
| 270 |
+
if n4_est > len(h4):
|
| 271 |
+
shortfall_notes.append(
|
| 272 |
+
f"4B pool rows {len(h4)} < needed {n4_est} for 1:4; not changing ratio"
|
| 273 |
+
)
|
| 274 |
+
if tok4_pool < need4_tok:
|
| 275 |
+
shortfall_notes.append(
|
| 276 |
+
f"4B pool tokens {tok4_pool} < 0.8*target {need4_tok}; not changing ratio"
|
| 277 |
+
)
|
| 278 |
+
if shortfall_notes:
|
| 279 |
+
print("SHORTFALL", shortfall_notes)
|
| 280 |
+
|
| 281 |
+
rng = random.Random(SEED)
|
| 282 |
+
union = sorted(union_set)
|
| 283 |
+
rng.shuffle(union)
|
| 284 |
+
preferred: dict[str, str] = {}
|
| 285 |
+
for h in union:
|
| 286 |
+
if h in inter:
|
| 287 |
+
preferred[h] = "30b" if rng.choice((0, 1)) == 0 else "4b"
|
| 288 |
+
|
| 289 |
+
def tokens_of(p30: list[str], p4: list[str]) -> int:
|
| 290 |
+
return sum(int(map30[h]["assistant_target_tokens"]) for h in p30) + sum(
|
| 291 |
+
int(map4[h]["assistant_target_tokens"]) for h in p4
|
| 292 |
+
)
|
| 293 |
+
|
| 294 |
+
candidates: list[tuple[int, int, list[str], list[str], int]] = []
|
| 295 |
+
n30_max = min(len(h30), len(h4) // RATIO_4)
|
| 296 |
+
for n30 in range(1, n30_max + 1):
|
| 297 |
+
n4 = n30 * RATIO_4
|
| 298 |
+
p30, p4 = _fill(union, preferred, only30, only4, n30, n4)
|
| 299 |
+
if len(p30) != n30 or len(p4) != n4:
|
| 300 |
+
continue
|
| 301 |
+
tok = tokens_of(p30, p4)
|
| 302 |
+
candidates.append((abs(tok - TARGET_1EP), n30, p30, p4, tok))
|
| 303 |
+
|
| 304 |
+
if not candidates:
|
| 305 |
+
raise SystemExit("no exact 1:4 fill succeeded")
|
| 306 |
+
in_band = [c for c in candidates if abs(c[4] - TARGET_1EP) <= TARGET_1EP * TOL]
|
| 307 |
+
pool = in_band if in_band else candidates
|
| 308 |
+
pool.sort(key=lambda c: (c[0], abs(c[1] - n30_est)))
|
| 309 |
+
_, n30, picked_30, picked_4, active_1ep = pool[0]
|
| 310 |
+
n4 = n30 * RATIO_4
|
| 311 |
+
rel = abs(active_1ep - TARGET_1EP) / TARGET_1EP
|
| 312 |
+
print(
|
| 313 |
+
"PICKED",
|
| 314 |
+
json.dumps(
|
| 315 |
+
{
|
| 316 |
+
"n30": n30,
|
| 317 |
+
"n4": n4,
|
| 318 |
+
"active_1ep": active_1ep,
|
| 319 |
+
"rel_err": rel,
|
| 320 |
+
"in_band": rel <= TOL,
|
| 321 |
+
"n30_est": n30_est,
|
| 322 |
+
"candidates_in_band": len(in_band),
|
| 323 |
+
}
|
| 324 |
+
),
|
| 325 |
+
)
|
| 326 |
+
if rel > TOL:
|
| 327 |
+
raise SystemExit(f"token dose {active_1ep} outside ±1% of {TARGET_1EP}")
|
| 328 |
+
|
| 329 |
+
mixed: list[dict[str, Any]] = []
|
| 330 |
+
for h in picked_30:
|
| 331 |
+
row = dict(map30[h])
|
| 332 |
+
row["teacher_source"] = "30b"
|
| 333 |
+
mixed.append(row)
|
| 334 |
+
for h in picked_4:
|
| 335 |
+
row = dict(map4[h])
|
| 336 |
+
row["teacher_source"] = "4b"
|
| 337 |
+
mixed.append(row)
|
| 338 |
+
if len({r["problem_hash"] for r in mixed}) != len(mixed):
|
| 339 |
+
raise SystemExit("duplicate problem in mix")
|
| 340 |
+
order_rng = random.Random(SEED)
|
| 341 |
+
order_rng.shuffle(mixed)
|
| 342 |
+
|
| 343 |
+
mq0_summary, mq0_hits = mq0_all_hits(mixed)
|
| 344 |
+
print(
|
| 345 |
+
"mq0",
|
| 346 |
+
mq0_summary.get("status"),
|
| 347 |
+
"intersection",
|
| 348 |
+
mq0_summary.get("intersection"),
|
| 349 |
+
"coverage",
|
| 350 |
+
mq0_summary.get("coverage"),
|
| 351 |
+
)
|
| 352 |
+
if mq0_hits or int(mq0_summary.get("intersection") or 0) != 0:
|
| 353 |
+
raise SystemExit(f"MQ0 intersection nonzero: {mq0_hits[:5]}")
|
| 354 |
+
if mq0_summary.get("coverage") != "6_OF_6":
|
| 355 |
+
raise SystemExit(f"MQ0 coverage {mq0_summary.get('coverage')}")
|
| 356 |
+
|
| 357 |
+
near = near_dup_scan.scan_training_rows(mixed)
|
| 358 |
+
print("near_dup hits", len(near["hit_hashes"]), "grey", near["grey_zone_count"])
|
| 359 |
+
if near["hit_hashes"]:
|
| 360 |
+
raise SystemExit(f"near-dup hits: {near['hit_hashes']}")
|
| 361 |
+
|
| 362 |
+
tok = v4_render_lib.load_qwen_tokenizer()
|
| 363 |
+
idx30 = [i for i, r in enumerate(mixed) if r["teacher_source"] == "30b"][:3]
|
| 364 |
+
idx4 = [i for i, r in enumerate(mixed) if r["teacher_source"] == "4b"][:3]
|
| 365 |
+
samples = [_sample_record(i, mixed[i], tok) for i in idx30 + idx4]
|
| 366 |
+
if len(samples) != 6:
|
| 367 |
+
raise SystemExit(f"expected 6 samples, got {len(samples)}")
|
| 368 |
+
|
| 369 |
+
v4_policy = json.loads(V4_POLICY.read_text())
|
| 370 |
+
renderer = v4_policy["arms"][0]["renderer"]
|
| 371 |
+
authority = v4_policy["arms"][0]["renderer_authority"]
|
| 372 |
+
contract = {"renderer": renderer, "sequence": {"max_sequence_length": 32768}}
|
| 373 |
+
for rec in samples:
|
| 374 |
+
row = mixed[rec["i"]]
|
| 375 |
+
worker = render_completion_only(
|
| 376 |
+
contract,
|
| 377 |
+
renderer_id="qwen3-8b-think-lcb-system-v2",
|
| 378 |
+
prompt_messages=build_lcb_prompt_messages(contract, row["prompt"]),
|
| 379 |
+
reasoning=row["reasoning"],
|
| 380 |
+
answer=row["final_answer"],
|
| 381 |
+
)
|
| 382 |
+
if worker.labels[-1] != 151643:
|
| 383 |
+
raise SystemExit(f"worker last label {worker.labels[-1]} i={rec['i']}")
|
| 384 |
+
rec["worker_last"] = worker.labels[-1]
|
| 385 |
+
rec["worker_active"] = sum(x != -100 for x in worker.labels)
|
| 386 |
+
rec["worker_full"] = len(worker.input_ids)
|
| 387 |
+
print("SAMPLE", json.dumps(rec, ensure_ascii=False))
|
| 388 |
+
|
| 389 |
+
schema = t30.schema
|
| 390 |
+
arrays = []
|
| 391 |
+
for name in schema.names:
|
| 392 |
+
arrays.append(pa.array([r[name] for r in mixed], type=schema.field(name).type))
|
| 393 |
+
arrays.append(pa.array([r["teacher_source"] for r in mixed], type=pa.string()))
|
| 394 |
+
names = list(schema.names) + ["teacher_source"]
|
| 395 |
+
one = pa.table(arrays, names=names)
|
| 396 |
+
two = pa.concat_tables([one, one])
|
| 397 |
+
if OUT_1EP.exists() or OUT_2EP.exists():
|
| 398 |
+
raise SystemExit("refusing to overwrite existing mix parquet")
|
| 399 |
+
pq.write_table(one, OUT_1EP)
|
| 400 |
+
pq.write_table(two, OUT_2EP)
|
| 401 |
+
sha1 = _sha256_bytes_file(OUT_1EP)
|
| 402 |
+
sha2 = _sha256_bytes_file(OUT_2EP)
|
| 403 |
+
actives = [int(r["assistant_target_tokens"]) for r in mixed]
|
| 404 |
+
fulls = [int(r["full_tokens"]) for r in mixed]
|
| 405 |
+
actives30 = [int(r["assistant_target_tokens"]) for r in mixed if r["teacher_source"] == "30b"]
|
| 406 |
+
actives4 = [int(r["assistant_target_tokens"]) for r in mixed if r["teacher_source"] == "4b"]
|
| 407 |
+
active_2ep = active_1ep * 2
|
| 408 |
+
print("wrote", OUT_1EP, one.num_rows, sha1, "active1ep", active_1ep)
|
| 409 |
+
print("wrote", OUT_2EP, two.num_rows, sha2, "active2ep", active_2ep)
|
| 410 |
+
|
| 411 |
+
stream_rows = [
|
| 412 |
+
{"problem_hash": r["problem_hash"], "active_tokens": int(r["assistant_target_tokens"])}
|
| 413 |
+
for r in mixed
|
| 414 |
+
]
|
| 415 |
+
derived = select_core.derive_after_materialize(stream_rows)
|
| 416 |
+
if derived["planned_active_tokens_2ep"] != active_2ep:
|
| 417 |
+
raise SystemExit("derived 2ep tokens != 2*1ep")
|
| 418 |
+
print(
|
| 419 |
+
"derived",
|
| 420 |
+
json.dumps(
|
| 421 |
+
{
|
| 422 |
+
k: derived[k]
|
| 423 |
+
for k in (
|
| 424 |
+
"unique_rows",
|
| 425 |
+
"physical_rows_2ep",
|
| 426 |
+
"unique_1ep_think_active_tokens",
|
| 427 |
+
"planned_active_tokens_2ep",
|
| 428 |
+
"optimizer_updates",
|
| 429 |
+
"warmup_target_tokens",
|
| 430 |
+
"milestone_updates_right_3",
|
| 431 |
+
"checkpoint_target_tokens_right_3",
|
| 432 |
+
)
|
| 433 |
+
}
|
| 434 |
+
),
|
| 435 |
+
)
|
| 436 |
+
|
| 437 |
+
mq0_body = {
|
| 438 |
+
"mq0": {
|
| 439 |
+
"status": mq0_summary.get("status"),
|
| 440 |
+
"coverage": mq0_summary.get("coverage"),
|
| 441 |
+
"intersection": mq0_summary.get("intersection"),
|
| 442 |
+
"denylist_path": mq0_summary.get("denylist_path"),
|
| 443 |
+
"denylist_sha256": mq0_summary.get("denylist_sha256"),
|
| 444 |
+
},
|
| 445 |
+
"near_dup_hit_hashes": near["hit_hashes"],
|
| 446 |
+
"near_dup_grey_zone_count": near["grey_zone_count"],
|
| 447 |
+
"dropped_n": 0,
|
| 448 |
+
"kept_n": len(mixed),
|
| 449 |
+
}
|
| 450 |
+
MQ0_OUT.write_text(json.dumps(mq0_body, indent=2, ensure_ascii=False) + "\n")
|
| 451 |
+
|
| 452 |
+
census = {
|
| 453 |
+
"schema": "TOKEN_CENSUS_MIX_L0.2_S0.8_TAIL151643",
|
| 454 |
+
"seed": SEED,
|
| 455 |
+
"n_rows": len(mixed),
|
| 456 |
+
"n_problems": len(mixed),
|
| 457 |
+
"parquet_1ep": str(OUT_1EP),
|
| 458 |
+
"parquet_1ep_sha256": sha1,
|
| 459 |
+
"parquet_2ep": str(OUT_2EP),
|
| 460 |
+
"parquet_2ep_sha256": sha2,
|
| 461 |
+
"supervised_tail": [151643],
|
| 462 |
+
"active_1ep": active_1ep,
|
| 463 |
+
"active_2ep": active_2ep,
|
| 464 |
+
"full_1ep": int(sum(fulls)),
|
| 465 |
+
"target_1ep": TARGET_1EP,
|
| 466 |
+
"rel_err": rel,
|
| 467 |
+
"ratio_rows_30_to_4": f"{n30}:{n4}",
|
| 468 |
+
"universe": {
|
| 469 |
+
"union": len(union_set),
|
| 470 |
+
"intersect": len(inter),
|
| 471 |
+
"only30": len(only30),
|
| 472 |
+
"only4": len(only4),
|
| 473 |
+
},
|
| 474 |
+
"teacher": {
|
| 475 |
+
"n30": n30,
|
| 476 |
+
"n4": n4,
|
| 477 |
+
"tok30": int(sum(actives30)),
|
| 478 |
+
"tok4": int(sum(actives4)),
|
| 479 |
+
"row_frac_30": n30 / len(mixed),
|
| 480 |
+
"row_frac_4": n4 / len(mixed),
|
| 481 |
+
"tok_frac_30": sum(actives30) / active_1ep,
|
| 482 |
+
"tok_frac_4": sum(actives4) / active_1ep,
|
| 483 |
+
"n30_from_intersect": sum(1 for h in picked_30 if h in inter),
|
| 484 |
+
"n30_from_only30": sum(1 for h in picked_30 if h in only30),
|
| 485 |
+
"n4_from_intersect": sum(1 for h in picked_4 if h in inter),
|
| 486 |
+
"n4_from_only4": sum(1 for h in picked_4 if h in only4),
|
| 487 |
+
},
|
| 488 |
+
"shortfall_notes": shortfall_notes,
|
| 489 |
+
"active": {
|
| 490 |
+
"n": len(actives),
|
| 491 |
+
"sum": active_1ep,
|
| 492 |
+
"min": min(actives),
|
| 493 |
+
"p10": _pct(actives, 10),
|
| 494 |
+
"p50": _pct(actives, 50),
|
| 495 |
+
"p90": _pct(actives, 90),
|
| 496 |
+
"p95": _pct(actives, 95),
|
| 497 |
+
"max": max(actives),
|
| 498 |
+
},
|
| 499 |
+
"active_30b": {
|
| 500 |
+
"n": len(actives30),
|
| 501 |
+
"sum": int(sum(actives30)),
|
| 502 |
+
"min": min(actives30),
|
| 503 |
+
"p50": _pct(actives30, 50),
|
| 504 |
+
"max": max(actives30),
|
| 505 |
+
},
|
| 506 |
+
"active_4b": {
|
| 507 |
+
"n": len(actives4),
|
| 508 |
+
"sum": int(sum(actives4)),
|
| 509 |
+
"min": min(actives4),
|
| 510 |
+
"p50": _pct(actives4, 50),
|
| 511 |
+
"max": max(actives4),
|
| 512 |
+
},
|
| 513 |
+
"derived": {
|
| 514 |
+
k: derived[k]
|
| 515 |
+
for k in (
|
| 516 |
+
"unique_rows",
|
| 517 |
+
"physical_rows_2ep",
|
| 518 |
+
"unique_1ep_think_active_tokens",
|
| 519 |
+
"planned_active_tokens_2ep",
|
| 520 |
+
"optimizer_updates",
|
| 521 |
+
"warmup_target_tokens",
|
| 522 |
+
"milestone_updates_right_3",
|
| 523 |
+
"checkpoint_target_tokens_right_3",
|
| 524 |
+
)
|
| 525 |
+
},
|
| 526 |
+
"samples": samples,
|
| 527 |
+
"sources": {
|
| 528 |
+
"30b_2ep": str(P30_2EP),
|
| 529 |
+
"30b_2ep_sha256": sha30,
|
| 530 |
+
"30b_1ep_rows_used": P30_1EP_ROWS,
|
| 531 |
+
"4b_1ep": str(P4),
|
| 532 |
+
"4b_1ep_sha256": sha4,
|
| 533 |
+
},
|
| 534 |
+
}
|
| 535 |
+
CENSUS.write_text(json.dumps(census, indent=2, ensure_ascii=False) + "\n")
|
| 536 |
+
|
| 537 |
+
ready_body = {
|
| 538 |
+
"physical_2ep": "concat(mix_table, mix_table) same order; tail [151643]; teacher_source kept",
|
| 539 |
+
"schema": "CODE_SFT_OR1RECIPE_READY_V1",
|
| 540 |
+
"status": "READY",
|
| 541 |
+
"training_payload": {
|
| 542 |
+
"active_tokens": active_2ep,
|
| 543 |
+
"path": OUT_2EP.name,
|
| 544 |
+
"rows": two.num_rows,
|
| 545 |
+
"sha256": sha2,
|
| 546 |
+
},
|
| 547 |
+
}
|
| 548 |
+
READY.write_text(json.dumps(ready_body, indent=2, sort_keys=True) + "\n")
|
| 549 |
+
ready_sha = sha256_file(READY)
|
| 550 |
+
|
| 551 |
+
cfg = json.loads(V4_CFG.read_text())
|
| 552 |
+
cfg["status"] = "READY_NOT_STARTED"
|
| 553 |
+
cfg["config_id"] = ARM_ID
|
| 554 |
+
cfg["arm_id"] = ARM_ID
|
| 555 |
+
cfg["corrects"] = "Q4B-THINK Mix Distillation 0.2:0.8 (30B:4B by rows)"
|
| 556 |
+
cfg["checkpoint"]["milestone_updates"] = derived["milestone_updates_right_3"]
|
| 557 |
+
cfg["checkpoint"]["checkpoint_target_tokens"] = derived["checkpoint_target_tokens_right_3"]
|
| 558 |
+
cfg["data"]["path"] = str(OUT_2EP)
|
| 559 |
+
cfg["data"]["sha256"] = sha2
|
| 560 |
+
cfg["data"]["unique_rows"] = len(mixed)
|
| 561 |
+
cfg["data"]["payload_rows"] = two.num_rows
|
| 562 |
+
cfg["data"]["physical_rows"] = two.num_rows
|
| 563 |
+
cfg["data"]["physical_2ep_rule"] = (
|
| 564 |
+
"concat(mix_l0.2_s0.8, mix_l0.2_s0.8) same order; 1ep is unique mixed rows"
|
| 565 |
+
)
|
| 566 |
+
cfg["data"]["planned_active_tokens"] = active_2ep
|
| 567 |
+
cfg["data"]["active_tokens_1ep"] = active_1ep
|
| 568 |
+
cfg["data"]["full_tokens_1ep"] = int(sum(fulls))
|
| 569 |
+
cfg["data"]["optimizer_updates"] = derived["optimizer_updates"]
|
| 570 |
+
cfg["data"]["census"] = str(CENSUS)
|
| 571 |
+
cfg["data"]["token_columns_in_parquet"] = "supervised tail [151643]; matches v4 worker render"
|
| 572 |
+
cfg["data"]["source_1ep_sha256"] = sha1
|
| 573 |
+
cfg["data"].pop("source_old_payload", None)
|
| 574 |
+
cfg["data"].pop("source_old_sha256", None)
|
| 575 |
+
cfg["optimization"]["warmup_target_tokens"] = derived["warmup_target_tokens"]
|
| 576 |
+
cfg["optimization"]["scheduler_horizon_optimizer_updates"] = derived["optimizer_updates"]
|
| 577 |
+
cfg["optimization"]["target_assistant_tokens"] = active_2ep
|
| 578 |
+
worker_sha = _sha256_bytes_file(WORKER)
|
| 579 |
+
cfg["runner"]["sha256"] = worker_sha
|
| 580 |
+
(ARM / "TRAINING_CONFIG.json").write_text(json.dumps(cfg, indent=2, ensure_ascii=False) + "\n")
|
| 581 |
+
|
| 582 |
+
(ARM / "TOKEN_ROWS_META.json").write_text(
|
| 583 |
+
json.dumps(
|
| 584 |
+
{
|
| 585 |
+
"schema": "TOKEN_ROWS_META_V1",
|
| 586 |
+
"ids": [151643, 151667, 151668],
|
| 587 |
+
"dtype": "float32",
|
| 588 |
+
"tied_before": True,
|
| 589 |
+
"untied": True,
|
| 590 |
+
"worker": "rstar_dual_worker_v4",
|
| 591 |
+
"hidden": 2560,
|
| 592 |
+
"base_rev": "906bfd4b4dc7f14ee4320094d8b41684abff8539",
|
| 593 |
+
},
|
| 594 |
+
indent=2,
|
| 595 |
+
)
|
| 596 |
+
+ "\n"
|
| 597 |
+
)
|
| 598 |
+
|
| 599 |
+
identity = {
|
| 600 |
+
"schema": "RUN_IDENTITY_V1",
|
| 601 |
+
"run_id": RUN_ID,
|
| 602 |
+
"corrects": "Q4B-THINK Mix Distillation 0.2:0.8 (30B-A3B-Thinking : 4B-Thinking by rows)",
|
| 603 |
+
"notes": (
|
| 604 |
+
"Mix Distillation Mix-Large (Li et al. 2025 arXiv 2502.12143): "
|
| 605 |
+
"30B-A3B-Thinking : 4B-Thinking = 0.2 : 0.8 by row/problem; one teacher "
|
| 606 |
+
f"trace per problem; dose target {TARGET_1EP}/ep ±1%, actual 1ep "
|
| 607 |
+
f"{active_1ep}, 2ep {active_2ep}. 30B source={P30_2EP} sha={sha30} "
|
| 608 |
+
f"(2EP first half {P30_1EP_ROWS} rows). 4B source={P4} sha={sha4}. "
|
| 609 |
+
"V4 recipe unchanged (LoRA r64/α128, lr 1e-4, both-sides B-row "
|
| 610 |
+
"[151643,151667,151668], physical 2ep concat, seed 42). "
|
| 611 |
+
"PI approved 2026-09-09."
|
| 612 |
+
),
|
| 613 |
+
"model": {
|
| 614 |
+
"hf_id": "Qwen/Qwen3-4B-Base",
|
| 615 |
+
"revision": "906bfd4b4dc7f14ee4320094d8b41684abff8539",
|
| 616 |
+
"local_path": "/workspace/code-sft-infra/models/qwen3-4b-base",
|
| 617 |
+
"tied_embeddings": True,
|
| 618 |
+
},
|
| 619 |
+
"data": {
|
| 620 |
+
"path": str(OUT_2EP),
|
| 621 |
+
"rows": two.num_rows,
|
| 622 |
+
"sha256": sha2,
|
| 623 |
+
"census": str(CENSUS),
|
| 624 |
+
"physical_2ep": "concat(mix, mix) same order; teacher_source 30b/4b; tail 151643",
|
| 625 |
+
"source_1ep_path": str(OUT_1EP),
|
| 626 |
+
"source_1ep_sha256": sha1,
|
| 627 |
+
"source_1ep_rows": one.num_rows,
|
| 628 |
+
"teacher_30b_path": str(P30_2EP),
|
| 629 |
+
"teacher_30b_sha256": sha30,
|
| 630 |
+
"teacher_4b_path": str(P4),
|
| 631 |
+
"teacher_4b_sha256": sha4,
|
| 632 |
+
"mix_ratio_rows": "0.2:0.8",
|
| 633 |
+
"n30": n30,
|
| 634 |
+
"n4": n4,
|
| 635 |
+
"active_tokens_1ep": active_1ep,
|
| 636 |
+
},
|
| 637 |
+
"seeds": {"train": 42, "eval": 3407, "mix": 42},
|
| 638 |
+
"parameters": {
|
| 639 |
+
"epochs": 2,
|
| 640 |
+
"target_assistant_tokens": active_2ep,
|
| 641 |
+
"active_tokens_1ep": active_1ep,
|
| 642 |
+
"checkpoint_target_tokens": derived["checkpoint_target_tokens_right_3"],
|
| 643 |
+
"milestone_updates": derived["milestone_updates_right_3"],
|
| 644 |
+
"warmup_target_tokens": derived["warmup_target_tokens"],
|
| 645 |
+
"learning_rate": 0.0001,
|
| 646 |
+
"row_lr": 0.0001,
|
| 647 |
+
"optimizer": "adamw",
|
| 648 |
+
"optimizer_betas": [0.9, 0.95],
|
| 649 |
+
"optimizer_eps": 1e-08,
|
| 650 |
+
"lora_rank": 64,
|
| 651 |
+
"lora_alpha": 128,
|
| 652 |
+
"lora_dropout": 0.0,
|
| 653 |
+
"lora_target_modules": [
|
| 654 |
+
"q_proj",
|
| 655 |
+
"k_proj",
|
| 656 |
+
"v_proj",
|
| 657 |
+
"o_proj",
|
| 658 |
+
"gate_proj",
|
| 659 |
+
"up_proj",
|
| 660 |
+
"down_proj",
|
| 661 |
+
],
|
| 662 |
+
"lora_weight_decay": 0.1,
|
| 663 |
+
"row_weight_decay": 0.0,
|
| 664 |
+
"max_grad_norm": 1.0,
|
| 665 |
+
"tokens_per_optimizer_update": 65536,
|
| 666 |
+
"packing": False,
|
| 667 |
+
"truncation": False,
|
| 668 |
+
"repeat_examples": False,
|
| 669 |
+
"precision": "bfloat16",
|
| 670 |
+
"trainable_dtype": "float32",
|
| 671 |
+
"gradient_checkpointing": True,
|
| 672 |
+
"eos_weight": 1.0,
|
| 673 |
+
"scheduler": "cosine_by_assistant_target_token_dose",
|
| 674 |
+
"worker_lr_scale": "rstar_dual_worker_v4._lr_scale",
|
| 675 |
+
"supervised_tail": [151643],
|
| 676 |
+
"trainable_token_indices": {
|
| 677 |
+
"embed_tokens": [151643, 151667, 151668],
|
| 678 |
+
"lm_head": [151643, 151667, 151668],
|
| 679 |
+
},
|
| 680 |
+
"untie_tied_embeddings": True,
|
| 681 |
+
"context": 32768,
|
| 682 |
+
"eval": {
|
| 683 |
+
"suite": "DEV256",
|
| 684 |
+
"seed": 3407,
|
| 685 |
+
"temperature": 0.6,
|
| 686 |
+
"top_p": 0.95,
|
| 687 |
+
"top_k": 20,
|
| 688 |
+
"ctx": 32768,
|
| 689 |
+
"stop_ids": [151643, 151645],
|
| 690 |
+
"base_reeval_same_mode": True,
|
| 691 |
+
},
|
| 692 |
+
},
|
| 693 |
+
"code": {
|
| 694 |
+
"path": str(WORKER),
|
| 695 |
+
"commit_or_sha256": worker_sha,
|
| 696 |
+
"prep": str(Path(__file__).resolve()),
|
| 697 |
+
"prep_sha256": _sha256_bytes_file(Path(__file__).resolve()),
|
| 698 |
+
},
|
| 699 |
+
"started_at": None,
|
| 700 |
+
"endpoint": f"2EP_ONLY @{active_2ep} assistant tokens; no checkpoint picking",
|
| 701 |
+
"status": "READY_NOT_STARTED",
|
| 702 |
+
}
|
| 703 |
+
(ARM / "RUN_IDENTITY.json").write_text(json.dumps(identity, indent=2, ensure_ascii=False) + "\n")
|
| 704 |
+
|
| 705 |
+
v4_launch = json.loads(V4_LAUNCH.read_text())
|
| 706 |
+
policy = {
|
| 707 |
+
"schema": "CODE_SFT_RSTAR_DUAL_TRAINING_POLICY_V1",
|
| 708 |
+
"status": "SEALED",
|
| 709 |
+
"owner_authorization": "PI 2026-09-09 Q4B-THINK-MIX Mix Distillation 0.2:0.8",
|
| 710 |
+
"generation_behavior_gate": None,
|
| 711 |
+
"arms": [
|
| 712 |
+
{
|
| 713 |
+
"arm_id": ARM_ID,
|
| 714 |
+
"gpu": 2,
|
| 715 |
+
"model_id": "qwen3-4b-base",
|
| 716 |
+
"source_id": "rstar-coder",
|
| 717 |
+
"renderer_id": "qwen3-8b-think-lcb-system-v2",
|
| 718 |
+
"renderer": renderer,
|
| 719 |
+
"renderer_authority": authority,
|
| 720 |
+
"model": json.loads(json.dumps(v4_policy["arms"][0]["model"])),
|
| 721 |
+
"data": {
|
| 722 |
+
"assistant_target_tokens": active_2ep,
|
| 723 |
+
"manifest_path": str(READY),
|
| 724 |
+
"manifest_file_sha256": ready_sha,
|
| 725 |
+
"manifest_sha256": ready_sha,
|
| 726 |
+
"payload_rows": two.num_rows,
|
| 727 |
+
"payload_sha256": sha2,
|
| 728 |
+
"source_revision": "3a7a0a0636ec96e3c1ec42ebe79ade467caa040d",
|
| 729 |
+
"max_assistant_target_tokens_per_example": 16384,
|
| 730 |
+
},
|
| 731 |
+
}
|
| 732 |
+
],
|
| 733 |
+
"recipe": json.loads(json.dumps(v4_policy["recipe"])),
|
| 734 |
+
"runtime": {
|
| 735 |
+
"state_root": str(ARM),
|
| 736 |
+
"checkpoint_root": str(ARM / "out"),
|
| 737 |
+
},
|
| 738 |
+
}
|
| 739 |
+
policy["recipe"]["target_assistant_tokens"] = active_2ep
|
| 740 |
+
policy["recipe"]["warmup_target_tokens"] = derived["warmup_target_tokens"]
|
| 741 |
+
policy["recipe"]["checkpoint_target_tokens"] = derived["checkpoint_target_tokens_right_3"]
|
| 742 |
+
policy_path = ARM / "POLICY.json"
|
| 743 |
+
policy_path.write_text(json.dumps(policy, indent=2, sort_keys=True) + "\n")
|
| 744 |
+
policy_sha = sha256_file(policy_path)
|
| 745 |
+
|
| 746 |
+
job = {
|
| 747 |
+
"arm_id": ARM_ID,
|
| 748 |
+
"assistant_target_tokens": active_2ep,
|
| 749 |
+
"gpu": 2,
|
| 750 |
+
"materialized_manifest_path": str(READY),
|
| 751 |
+
"materialized_manifest_sha256": ready_sha,
|
| 752 |
+
"model_hf_id": "Qwen/Qwen3-4B-Base",
|
| 753 |
+
"model_revision": "906bfd4b4dc7f14ee4320094d8b41684abff8539",
|
| 754 |
+
"payload_sha256": sha2,
|
| 755 |
+
"renderer_authority_sha256": authority["sha256"],
|
| 756 |
+
"renderer_id": "qwen3-8b-think-lcb-system-v2",
|
| 757 |
+
"source_id": "rstar-coder",
|
| 758 |
+
}
|
| 759 |
+
job["job_sha256"] = document_digest(job, "job_sha256")
|
| 760 |
+
launch = {
|
| 761 |
+
"schema": "CODE_SFT_RSTAR_DUAL_LAUNCH_V1",
|
| 762 |
+
"status": "ATOMICALLY_RELEASED",
|
| 763 |
+
"run_id": RUN_ID,
|
| 764 |
+
"automation_policy_sha256": v4_launch["automation_policy_sha256"],
|
| 765 |
+
"delegation_sha256": v4_launch["delegation_sha256"],
|
| 766 |
+
"launch_critical_go_sha256": v4_launch["launch_critical_go_sha256"],
|
| 767 |
+
"release_sha256": v4_launch["release_sha256"],
|
| 768 |
+
"release_nonce": v4_launch["release_nonce"],
|
| 769 |
+
"release_claim_path": v4_launch["release_claim_path"],
|
| 770 |
+
"release_claim_file_sha256": v4_launch["release_claim_file_sha256"],
|
| 771 |
+
"evidence_path": v4_launch["evidence_path"],
|
| 772 |
+
"evidence_file_sha256": v4_launch["evidence_file_sha256"],
|
| 773 |
+
"training_policy_path": str(policy_path),
|
| 774 |
+
"training_policy_sha256": policy_sha,
|
| 775 |
+
"jobs": [job],
|
| 776 |
+
}
|
| 777 |
+
launch["launch_sha256"] = document_digest(launch, "launch_sha256")
|
| 778 |
+
launch_path = ARM / "control" / "LAUNCH.json"
|
| 779 |
+
launch_path.write_text(json.dumps(launch, indent=2, sort_keys=True) + "\n")
|
| 780 |
+
if document_digest(json.loads(launch_path.read_text()), "launch_sha256") != launch["launch_sha256"]:
|
| 781 |
+
raise SystemExit("launch digest drifted after write")
|
| 782 |
+
print("wrote", policy_path, policy_sha)
|
| 783 |
+
print("wrote", launch_path, launch["launch_sha256"])
|
| 784 |
+
print("PREP_OK", datetime.now(timezone.utc).isoformat())
|
| 785 |
+
return 0
|
| 786 |
+
|
| 787 |
+
|
| 788 |
+
if __name__ == "__main__":
|
| 789 |
+
raise SystemExit(main())
|