worker v6 upload
Browse files- workers/canary_worker_v6.py +299 -0
workers/canary_worker_v6.py
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# stack400 vertical-slice canary worker v6. Incremental marker pushes (HF commit channel). Runs ON Salad (pytorch 2.14.1-cuda12.6-cudnn9-runtime image).
|
| 2 |
+
# Doctrine (Kimi review, adopted): markers protocol, pinned installs, snapshot_download (complete models),
|
| 3 |
+
# effective-delta LoRA no-op quarantine, szl.receipt/v1 mint, outbox + exponential backoff upload, EVAL_EXIT line.
|
| 4 |
+
# Env: MODEL_ID, RUN_ID, HF_TOKEN, WORK_DIR.
|
| 5 |
+
import os, json, time, hashlib, base64, random, sys, traceback
|
| 6 |
+
t0 = time.time()
|
| 7 |
+
RUN_ID = os.environ.get("RUN_ID", "stack400-canary-r1")
|
| 8 |
+
MODEL_ID = os.environ.get("MODEL_ID", "Qwen/Qwen2.5-0.5B")
|
| 9 |
+
NOOP = os.environ.get("NOOP_INJECT", "0") == "1"
|
| 10 |
+
JOB_SEED = int(os.environ.get("JOB_SEED", "1337"))
|
| 11 |
+
OUT_DIR = os.environ.get("WORK_DIR", "/tmp/stack400")
|
| 12 |
+
os.makedirs(OUT_DIR, exist_ok=True)
|
| 13 |
+
MARK = open(os.path.join(OUT_DIR, "markers.txt"), "a")
|
| 14 |
+
os.environ.setdefault("HF_HUB_ETAG_TIMEOUT", "30")
|
| 15 |
+
os.environ.setdefault("HF_HUB_DOWNLOAD_TIMEOUT", "60")
|
| 16 |
+
def _pm(tag, line):
|
| 17 |
+
if os.environ.get("MARKERS", "1") != "1": return
|
| 18 |
+
try:
|
| 19 |
+
import urllib.request as _ur
|
| 20 |
+
tok = os.environ.get("HF_TOKEN", "")
|
| 21 |
+
url = "https://huggingface.co/api/datasets/SZLHOLDINGS/stack400-runs/commit/main"
|
| 22 |
+
data = (chr(10).join([
|
| 23 |
+
json.dumps({"key": "header", "value": {"summary": "marker " + RUN_ID}}),
|
| 24 |
+
json.dumps({"key": "file", "value": {"path": "markers/" + RUN_ID + "/progress.txt", "content": line, "encoding": "utf-8"}})
|
| 25 |
+
])).encode()
|
| 26 |
+
rq = _ur.Request(url, data=data, method="POST")
|
| 27 |
+
rq.add_header("Authorization", "Bearer " + tok)
|
| 28 |
+
rq.add_header("Content-Type", "application/x-ndjson")
|
| 29 |
+
_ur.urlopen(rq, timeout=45).read()
|
| 30 |
+
except Exception:
|
| 31 |
+
pass
|
| 32 |
+
def mark(tag, **kv):
|
| 33 |
+
line = json.dumps({"t": round(time.time() - t0, 1), "tag": tag, **kv}, sort_keys=True)
|
| 34 |
+
MARK.write(line + chr(10)); MARK.flush()
|
| 35 |
+
print("MARK " + line, flush=True)
|
| 36 |
+
try: _pm(tag, line)
|
| 37 |
+
except Exception: pass
|
| 38 |
+
def canon(o): return json.dumps(o, sort_keys=True, separators=(",", ":"), ensure_ascii=True)
|
| 39 |
+
def H(s): return "sha256:" + hashlib.sha256(s.encode("utf-8")).hexdigest()
|
| 40 |
+
import signal
|
| 41 |
+
def _term(signum, frame):
|
| 42 |
+
mark("TERM_RECEIVED", signum=signum)
|
| 43 |
+
open(os.path.join(OUT_DIR, 'term.flag'), 'w').write(str(signum))
|
| 44 |
+
raise SystemExit(7)
|
| 45 |
+
if hasattr(signal, 'SIGTERM'): signal.signal(signal.SIGTERM, _term)
|
| 46 |
+
if hasattr(signal, 'SIGINT'):
|
| 47 |
+
try: signal.signal(signal.SIGINT, _term)
|
| 48 |
+
except Exception: pass
|
| 49 |
+
mark("BOOT_OK", run=RUN_ID, model=MODEL_ID, py=sys.version.split()[0], cwd=os.getcwd())
|
| 50 |
+
def stage_pip():
|
| 51 |
+
import subprocess
|
| 52 |
+
pins = ["transformers==4.46.3", "peft==0.13.2", "huggingface_hub", "pynvml", "datasets==3.6.0"]
|
| 53 |
+
r = subprocess.run(["pip", "install", "--no-input", "-q"] + pins, capture_output=True, text=True, timeout=600)
|
| 54 |
+
mark("PINS_DONE", rc=r.returncode, pins=",".join(pins))
|
| 55 |
+
if r.returncode != 0: mark("PINS_FAIL", err=(r.stderr or "")[-400:]); raise SystemExit(2)
|
| 56 |
+
try:
|
| 57 |
+
if os.environ.get("NO_PINS", "0") != "1":
|
| 58 |
+
stage_pip()
|
| 59 |
+
import transformers, peft, huggingface_hub
|
| 60 |
+
mark("IMPORTS_OK", transformers=transformers.__version__, peft=peft.__version__)
|
| 61 |
+
except SystemExit: raise
|
| 62 |
+
except Exception as e:
|
| 63 |
+
mark("STAGE0_FAIL", err=str(e)[:300]); raise SystemExit(2)
|
| 64 |
+
# ---- STAGE 1: fetch complete model via snapshot_download (Kimi: never per-file) ----
|
| 65 |
+
def stage_fetch(hub):
|
| 66 |
+
from huggingface_hub import snapshot_download
|
| 67 |
+
t1 = time.time()
|
| 68 |
+
path = snapshot_download(repo_id=MODEL_ID, token=os.environ.get("HF_TOKEN"), revision="main")
|
| 69 |
+
dt = round(time.time() - t1, 1)
|
| 70 |
+
import os as _o
|
| 71 |
+
total = 0
|
| 72 |
+
for root, dirs, files in _o.walk(path):
|
| 73 |
+
for f in files:
|
| 74 |
+
try: total += _o.path.getsize(_o.path.join(root, f))
|
| 75 |
+
except OSError: pass
|
| 76 |
+
mark("FETCH_OK", path=path, bytes=total, dt=dt)
|
| 77 |
+
return path
|
| 78 |
+
|
| 79 |
+
# ---- base model + tokenizer load ----
|
| 80 |
+
def stage_load(path):
|
| 81 |
+
import torch
|
| 82 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 83 |
+
tok = AutoTokenizer.from_pretrained(path)
|
| 84 |
+
model = AutoModelForCausalLM.from_pretrained(path, torch_dtype=torch.bfloat16)
|
| 85 |
+
dev = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 86 |
+
model = model.to(dev)
|
| 87 |
+
mark("LOAD_OK", device=dev, params=sum(p.numel() for p in model.parameters()), dtype=str(next(model.parameters()).dtype))
|
| 88 |
+
return model, tok, dev, torch
|
| 89 |
+
|
| 90 |
+
STAGE = 0
|
| 91 |
+
try:
|
| 92 |
+
from huggingface_hub import HfApi
|
| 93 |
+
api = HfApi(token=os.environ.get("HF_TOKEN"))
|
| 94 |
+
MODEL_PATH = stage_fetch(api)
|
| 95 |
+
STAGE = 1
|
| 96 |
+
mark("STAGE_FETCH_DONE")
|
| 97 |
+
except SystemExit: raise
|
| 98 |
+
except Exception as e:
|
| 99 |
+
mark("FETCH_FAIL", err=str(e)[:400], stage=STAGE)
|
| 100 |
+
traceback.print_exc()
|
| 101 |
+
raise SystemExit(3)
|
| 102 |
+
# ---- STAGE 2: tiny LoRA train (seeded, few steps, synthetic task) ----
|
| 103 |
+
SEED = JOB_SEED
|
| 104 |
+
def stage_train(model, tok, torch):
|
| 105 |
+
import random as _r
|
| 106 |
+
_r.seed(SEED); random.seed(SEED)
|
| 107 |
+
torch.manual_seed(SEED); torch.cuda.manual_seed_all(SEED)
|
| 108 |
+
from peft import LoraConfig, get_peft_model
|
| 109 |
+
lcfg = LoraConfig(r=8, lora_alpha=16, lora_dropout=0.0, bias='none', task_type='CAUSAL_LM', target_modules=['q_proj', 'v_proj'])
|
| 110 |
+
pm = get_peft_model(model, lcfg)
|
| 111 |
+
trainable = [(n, p.numel()) for n, p in pm.named_parameters() if p.requires_grad]
|
| 112 |
+
tp = [p for n, p in pm.named_parameters() if p.requires_grad]
|
| 113 |
+
opt = torch.optim.AdamW(tp, lr=5e-4)
|
| 114 |
+
# synthetic task: model memorizes a fixed token pattern
|
| 115 |
+
iid = tok('alpha beta gamma delta epsilon', return_tensors='pt').input_ids.to(model.device)
|
| 116 |
+
losses = []
|
| 117 |
+
pm.train()
|
| 118 |
+
if NOOP:
|
| 119 |
+
mark("NOOP_INJECT_ACTIVE")
|
| 120 |
+
losses = [0.0]
|
| 121 |
+
else:
|
| 122 |
+
for step in range(12):
|
| 123 |
+
opt.zero_grad()
|
| 124 |
+
out = pm(input_ids=iid, labels=iid)
|
| 125 |
+
out.loss.backward()
|
| 126 |
+
opt.step()
|
| 127 |
+
losses.append(round(out.loss.item(), 4))
|
| 128 |
+
pm.eval()
|
| 129 |
+
ad = os.path.join(OUT_DIR, 'adapter')
|
| 130 |
+
pm.save_pretrained(ad, safe_serialization=True)
|
| 131 |
+
adapter_bytes = 0
|
| 132 |
+
for root, dirs, files in os.walk(ad):
|
| 133 |
+
for f in files: adapter_bytes += os.path.getsize(os.path.join(root, f))
|
| 134 |
+
mark("TRAIN_OK", steps=12, loss_first=losses[0], loss_last=losses[-1], lora_params=sum(n for _, n in trainable), adapter_bytes=adapter_bytes)
|
| 135 |
+
return pm, ad, losses
|
| 136 |
+
|
| 137 |
+
try:
|
| 138 |
+
BASE_MODEL, TOK, DEV, TORCH = stage_load(MODEL_PATH)
|
| 139 |
+
gname, gmem, free_b = "unknown", 0, None
|
| 140 |
+
if DEV == "cuda":
|
| 141 |
+
free_b, total_b = TORCH.cuda.mem_get_info()
|
| 142 |
+
try:
|
| 143 |
+
import pynvml
|
| 144 |
+
pynvml.nvmlInit()
|
| 145 |
+
hdl = pynvml.nvmlDeviceGetHandleByIndex(0)
|
| 146 |
+
gname = str(pynvml.nvmlDeviceGetName(hdl))
|
| 147 |
+
gmem = pynvml.nvmlDeviceGetMemoryInfo(hdl).total
|
| 148 |
+
pynvml.nvmlShutdown()
|
| 149 |
+
except Exception:
|
| 150 |
+
pass
|
| 151 |
+
mark("GPU_ATTEST", free_gb=round(free_b/1e9, 3), total_gb=round(total_b/1e9, 3), name=gname, vram_total=int(gmem))
|
| 152 |
+
if free_b is not None and free_b < 1.2e9:
|
| 153 |
+
mark("SKIP_MEM", free_gb=round(free_b/1e9, 3))
|
| 154 |
+
raise SystemExit(8)
|
| 155 |
+
STAGE = 2
|
| 156 |
+
ADAPTER_MODEL, ADAPTER_DIR, LOSSES = stage_train(BASE_MODEL, TOK, TORCH)
|
| 157 |
+
STAGE = 3
|
| 158 |
+
mark("STAGE_TRAIN_DONE")
|
| 159 |
+
except SystemExit: raise
|
| 160 |
+
except Exception as e:
|
| 161 |
+
mark("TRAIN_FAIL", err=str(e)[:400], stage=STAGE)
|
| 162 |
+
traceback.print_exc()
|
| 163 |
+
raise SystemExit(4)
|
| 164 |
+
# ---- STAGE 3: effective-delta probe (Kimi: base-vs-adapted logits, quarantine no-ops) ----
|
| 165 |
+
def stage_probe(pm, tok, torch):
|
| 166 |
+
text = 'alpha beta gamma'
|
| 167 |
+
ids = tok(text, return_tensors='pt').input_ids.to(next(pm.parameters()).device)
|
| 168 |
+
torch.manual_seed(SEED)
|
| 169 |
+
with pm.disable_adapter():
|
| 170 |
+
lb = pm(input_ids=ids).logits.float()
|
| 171 |
+
la = pm(input_ids=ids).logits.float()
|
| 172 |
+
delta = (la - lb).abs()
|
| 173 |
+
mean_delta = float(delta.mean().item())
|
| 174 |
+
max_delta = float(delta.max().item())
|
| 175 |
+
# trap check: trainable A nonzero while BA effective delta zero => no-op adapter quarantine
|
| 176 |
+
a_norm = float(sum(p.detach().float().norm().item() for n, p in pm.named_parameters() if 'lora_A' in n))
|
| 177 |
+
no_op = (mean_delta < 1e-4) or (a_norm > 0 and max_delta < 1e-4)
|
| 178 |
+
mark("PROBE_MEASURED", mean_delta=round(mean_delta, 6), max_delta=round(max_delta, 6), a_norm=round(a_norm, 6), no_op=bool(no_op))
|
| 179 |
+
if no_op:
|
| 180 |
+
mark("DELTA_QUARANTINED", reason="effective_delta_below_floor")
|
| 181 |
+
return None, mean_delta, max_delta
|
| 182 |
+
return 'PASS', mean_delta, max_delta
|
| 183 |
+
|
| 184 |
+
# ---- STAGE 4: eval stub score (fixed prompts, greedy, self-scored) ----
|
| 185 |
+
def stage_eval(pm, tok, torch):
|
| 186 |
+
prompts = ['alpha beta', 'one two three', 'red green blue']
|
| 187 |
+
outs = []
|
| 188 |
+
for p in prompts:
|
| 189 |
+
ids = tok(p, return_tensors='pt').input_ids.to(next(pm.parameters()).device)
|
| 190 |
+
with torch.no_grad():
|
| 191 |
+
o = pm.generate(input_ids=ids, max_new_tokens=6, do_sample=False)
|
| 192 |
+
outs.append(tok.decode(o[0][ids.shape[1]:], skip_special_tokens=True))
|
| 193 |
+
score = round(sum(len(o.strip()) > 0 for o in outs) / len(prompts), 4)
|
| 194 |
+
mark("EVAL_OK", generations=[o[:40] for o in outs], score=score)
|
| 195 |
+
return score
|
| 196 |
+
|
| 197 |
+
PROBE_RESULT = None
|
| 198 |
+
try:
|
| 199 |
+
PROBE_RESULT, MEAN_D, MAX_D = stage_probe(ADAPTER_MODEL, TOK, TORCH)
|
| 200 |
+
if PROBE_RESULT is None:
|
| 201 |
+
mark("QUARANTINE_PATH")
|
| 202 |
+
try:
|
| 203 |
+
REC, RP = mint_receipt()
|
| 204 |
+
upload_all(api, REC, RP)
|
| 205 |
+
except Exception as e:
|
| 206 |
+
mark("QUAR_UPLOAD_FAIL", err=str(e)[:200])
|
| 207 |
+
raise SystemExit(4)
|
| 208 |
+
STAGE = 4
|
| 209 |
+
EVAL_SCORE = stage_eval(ADAPTER_MODEL, TOK, TORCH)
|
| 210 |
+
STAGE = 5
|
| 211 |
+
mark("STAGE_PROBE_EVAL_DONE")
|
| 212 |
+
except SystemExit: raise
|
| 213 |
+
except Exception as e:
|
| 214 |
+
mark("PROBE_FAIL", err=str(e)[:400], stage=STAGE)
|
| 215 |
+
traceback.print_exc()
|
| 216 |
+
raise SystemExit(5)
|
| 217 |
+
# ---- STAGE 5: mint szl.receipt/v1 (verified locally by verify_receipt.py) ----
|
| 218 |
+
DS_REPO = 'SZLHOLDINGS/stack400-runs'
|
| 219 |
+
def mint_receipt():
|
| 220 |
+
policy = {'schema_policy': 'stack400-canary-v1', 'lora_floor': 1e-4, 'stage_plops': 'BOOT,PINS,IMPORTS,FETCH,LOAD,TRAIN,PROBE,EVAL,RECEIPT,UPLOAD'}
|
| 221 |
+
markers_text = open(os.path.join(OUT_DIR, 'markers.txt')).read()
|
| 222 |
+
rec = {
|
| 223 |
+
'schema': 'szl.receipt/v1',
|
| 224 |
+
'seq': 1,
|
| 225 |
+
'actor': 'szl-stack400-canary-worker/v1',
|
| 226 |
+
'repo': DS_REPO,
|
| 227 |
+
'head': 'salad:' + RUN_ID,
|
| 228 |
+
'base': MODEL_ID + '@snapshot',
|
| 229 |
+
'policy_digest': H(canon(policy)),
|
| 230 |
+
'verifier_digest': H('probe=base_vs_adapted_logits;floor=1e-4;verify=verify_receipt.py'),
|
| 231 |
+
'artifact_digest': H(markers_text),
|
| 232 |
+
'effects': [
|
| 233 |
+
{'path': 'receipts/' + RUN_ID + '/receipt.json', 'action': 'create'},
|
| 234 |
+
{'path': 'receipts/' + RUN_ID + '/markers.txt', 'action': 'create'},
|
| 235 |
+
],
|
| 236 |
+
'prev': 'genesis',
|
| 237 |
+
}
|
| 238 |
+
tinfo = {'job_seed': SEED, 'no_op_inject': NOOP, 'mean_delta': MEAN_D, 'max_delta': MAX_D}
|
| 239 |
+
wsum = 0.0
|
| 240 |
+
try:
|
| 241 |
+
for n, p in ADAPTER_MODEL.named_parameters():
|
| 242 |
+
if p.requires_grad: wsum += float(p.detach().float().abs().sum())
|
| 243 |
+
except Exception: pass
|
| 244 |
+
tinfo['adapter_trainable_l1'] = wsum
|
| 245 |
+
if 'EVAL_SCORE' in globals(): tinfo['eval_score'] = EVAL_SCORE
|
| 246 |
+
if 'LOSSES' in globals() and LOSSES: tinfo['loss_first'] = LOSSES[0]; tinfo['loss_last'] = LOSSES[-1]
|
| 247 |
+
rec['training'] = tinfo
|
| 248 |
+
rec['recorded_hash'] = H(canon(rec))
|
| 249 |
+
rp = os.path.join(OUT_DIR, 'receipt.json')
|
| 250 |
+
json.dump(rec, open(rp, 'w'), indent=1)
|
| 251 |
+
mark("RECEIPT_MINTED", recorded_hash=rec["recorded_hash"], seq=1)
|
| 252 |
+
return rec, rp
|
| 253 |
+
|
| 254 |
+
# ---- STAGE 6: outbox upload, exponential backoff, honor Retry-After ----
|
| 255 |
+
def upload_all(api, rec, rp):
|
| 256 |
+
try:
|
| 257 |
+
api.create_repo(repo_id=DS_REPO, repo_type='dataset', exist_ok=True)
|
| 258 |
+
except Exception as e:
|
| 259 |
+
mark("CREATE_REPO_WARN", err=str(e)[:200])
|
| 260 |
+
mp = os.path.join(OUT_DIR, 'markers.txt')
|
| 261 |
+
files = [(rp, 'receipts/' + RUN_ID + '/receipt.json'), (mp, 'receipts/' + RUN_ID + '/markers.txt')]
|
| 262 |
+
attempt = 0
|
| 263 |
+
backoff = 30
|
| 264 |
+
while attempt < 6 and files:
|
| 265 |
+
attempt += 1
|
| 266 |
+
rest = []
|
| 267 |
+
for local, rpath in files:
|
| 268 |
+
try:
|
| 269 |
+
api.upload_file(path_or_fileobj=local, path_in_repo=rpath, repo_id=DS_REPO, repo_type='dataset')
|
| 270 |
+
mark("UPLOAD_OK", path=rpath, attempt=attempt)
|
| 271 |
+
except Exception as e:
|
| 272 |
+
rest.append((local, rpath))
|
| 273 |
+
msg = str(e)
|
| 274 |
+
ra = None
|
| 275 |
+
for part in msg.replace(',', ' ').split():
|
| 276 |
+
if part.isdigit(): ra = int(part)
|
| 277 |
+
mark('UPLOAD_RETRY', path=rpath, attempt=attempt, wait=backoff, err=msg[:120])
|
| 278 |
+
files = rest
|
| 279 |
+
if files:
|
| 280 |
+
time.sleep(min(backoff, 900) + random.randint(1, 15))
|
| 281 |
+
backoff = backoff * 2
|
| 282 |
+
return not files
|
| 283 |
+
|
| 284 |
+
try:
|
| 285 |
+
REC, RP = mint_receipt()
|
| 286 |
+
STAGE = 6
|
| 287 |
+
UP_OK = upload_all(api, REC, RP)
|
| 288 |
+
if not UP_OK:
|
| 289 |
+
mark("UPLOAD_FAIL_FINAL", attempts=6)
|
| 290 |
+
raise SystemExit(6)
|
| 291 |
+
STAGE = 99
|
| 292 |
+
mark("ALL_DONE", exit=0)
|
| 293 |
+
print('EVAL_EXIT ' + json.dumps({'run': RUN_ID, 'exit': 0, 'loss_first': LOSSES[0], 'loss_last': LOSSES[-1], 'mean_delta': round(MEAN_D, 6), 'max_delta': round(MAX_D, 6), 'eval_score': EVAL_SCORE, 'receipt': REC['recorded_hash']}), flush=True)
|
| 294 |
+
except SystemExit: raise
|
| 295 |
+
except Exception as e:
|
| 296 |
+
mark("RECEIPT_FAIL", err=str(e)[:400], stage=STAGE)
|
| 297 |
+
traceback.print_exc()
|
| 298 |
+
raise SystemExit(6)
|
| 299 |
+
# exit codes: 0 ALL_DONE ; 2 pins/stage0 ; 3 fetch ; 4 train-or-quarantine ; 5 probe/eval ; 6 receipt/upload ; 7 TERM'd
|