eyad-silx commited on
Commit
7b8dc35
·
verified ·
1 Parent(s): 808220e

Upload podflow/gen_data.sh with huggingface_hub

Browse files
Files changed (1) hide show
  1. podflow/gen_data.sh +90 -0
podflow/gen_data.sh ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Training + measurement data: diverse corpus rows (12/shard) -> teacher trajectories (train)
3
+ # + one pooled 128-row eval set. Selector written inline (make_traindata.py kept as reference).
4
+ set -euo pipefail
5
+ cd /root/ingot
6
+ export PATH=/root/ingot/.venv/bin:/usr/local/cuda/bin:$PATH
7
+ export INGOT_TEACHER_GPUS=0 INGOT_KING_GPUS=0 INGOT_CHALLENGER_GPUS=0
8
+ export INGOT_HIDDEN_STATES_DIR=/root/states-live
9
+ export HF_HUB_OFFLINE=1
10
+ PY=/root/ingot/.venv/bin/python
11
+
12
+ echo "== corpus rows -> /root/drawn.jsonl (12/shard across ~17 shards) =="
13
+ if [ ! -s /root/drawn.jsonl ]; then
14
+ $PY - <<'MK'
15
+ import json, os, urllib.request
16
+ from pathlib import Path
17
+ import pyarrow.parquet as pq
18
+ TOK = os.environ.get("HFTOKEN", "")
19
+ HDR = {"User-Agent": "mk", **({"Authorization": f"Bearer {TOK}"} if TOK else {})}
20
+
21
+ COMMIT = "70d2121e5dcbfc9f2c2e79c890563d96429eeb98"
22
+ REPO = "dendriteholdings/ingot_corpus"
23
+ BASE = f"https://huggingface.co/datasets/{REPO}/resolve/{COMMIT}/"
24
+ req = urllib.request.Request(
25
+ f"https://huggingface.co/api/datasets/{REPO}/tree/{COMMIT}?recursive=true",
26
+ headers=HDR)
27
+ tree = json.load(urllib.request.urlopen(req))
28
+ shards = sorted(t["path"] for t in tree
29
+ if t["path"].startswith("data/chungus-") and t["path"].endswith(".parquet"))
30
+ print("shards:", len(shards))
31
+
32
+ out = []
33
+ tmp = Path("/tmp/shards")
34
+ tmp.mkdir(exist_ok=True)
35
+ for shard in shards:
36
+ local = tmp / Path(shard).name
37
+ if not local.exists():
38
+ r = urllib.request.urlopen(urllib.request.Request(BASE + shard, headers=HDR))
39
+ local.write_bytes(r.read())
40
+
41
+ parq = pq.ParquetFile(local)
42
+ cols = ["dataset", "split", "entry_name", "domain", "language", "user_prompt"]
43
+ if "conversation" in parq.schema_arrow.names:
44
+ cols.append("conversation")
45
+ df = parq.read(columns=cols).to_pylist()
46
+ kept_shard = 0
47
+ for row in df:
48
+ if row.get("conversation"):
49
+ conv = json.loads(row["conversation"])
50
+ msgs, tools = conv["messages"], conv.get("tools")
51
+ else:
52
+ msgs = [{"role": "user", "content": row["user_prompt"]}]
53
+ tools = None
54
+ size = sum(len(m["content"].encode()) for m in msgs)
55
+ if size > 12000:
56
+ continue
57
+ sid = f"{row['dataset']}/{row['split']}/{row['entry_name']}/{row['language']}"
58
+ out.append({"id": sid, "messages": msgs, "tools": tools})
59
+ kept_shard += 1
60
+ if kept_shard >= 12:
61
+ break
62
+ print(f"{shard}: kept {kept_shard}", flush=True)
63
+ local.unlink(missing_ok=True) # stream: /tmp can't hold all shards
64
+ if len(out) >= 200:
65
+ break
66
+
67
+ Path("/root/drawn.jsonl").write_text(
68
+ "".join(json.dumps(r, ensure_ascii=False) + "\n" for r in out[:200]))
69
+ print("wrote /root/drawn.jsonl:", min(len(out), 200), "rows from",
70
+ len({r["id"].split("/")[0] for r in out}), "sources")
71
+ MK
72
+ fi
73
+
74
+ echo "== split: 48 train rows + one pooled 128-row eval set (disjoint) =="
75
+ $PY - <<'PY'
76
+ import json
77
+ rows = [json.loads(l) for l in open("/root/drawn.jsonl")][:176]
78
+ with open("/root/evalset.jsonl", "w") as f:
79
+ for r in rows[48:176]:
80
+ f.write(json.dumps(r, ensure_ascii=False) + "\n")
81
+ with open("/root/trainrows.jsonl", "w") as f:
82
+ for r in rows[:48]:
83
+ f.write(json.dumps(r, ensure_ascii=False) + "\n")
84
+ print("trainrows 48, evalset", min(128, max(0, len(rows) - 48)))
85
+ PY
86
+
87
+ echo "== teacher trajectories (vLLM, ~40-70 min) =="
88
+ [ -s /root/train_samples.json ] || $PY /root/gen_teacher.py --dataset /root/trainrows.jsonl \
89
+ --samples 48 --max-prompt 1200 --workers 8 --out /root/train_samples.json
90
+ echo "GEN_DATA COMPLETE"