Update chatcode/train.py
Browse files- chatcode/train.py +13 -5
chatcode/train.py
CHANGED
|
@@ -13,7 +13,11 @@ def read_data(folder):
|
|
| 13 |
manifest = json.loads((folder / "manifest.json").read_text(encoding="utf-8"))
|
| 14 |
if manifest["config"] != CONFIG:
|
| 15 |
raise ValueError("Data manifest does not match the pinned experiment configuration.")
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
for split in ["train", "validation", "test"]:
|
| 18 |
raw = (folder / f"{split}.jsonl").read_bytes()
|
| 19 |
if hashlib.sha256(raw).hexdigest() != manifest["sha256"][split]:
|
|
@@ -26,6 +30,10 @@ def read_data(folder):
|
|
| 26 |
if key != row["prompt_hash"] or key in seen:
|
| 27 |
raise ValueError("Duplicate or inconsistent prompts across dataset splits.")
|
| 28 |
seen.add(key)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
return records
|
| 30 |
|
| 31 |
|
|
@@ -92,16 +100,16 @@ def train(args):
|
|
| 92 |
shutil.copy2(Path(args.data) / "manifest.json", destination / "data_manifest.json")
|
| 93 |
report = {"config": CONFIG, "baseline_validation": baseline, "final_validation": final,
|
| 94 |
"training": trained.metrics, "counts": {k: len(v) for k, v in records.items()},
|
| 95 |
-
"status": "
|
| 96 |
(destination / "training_report.json").write_text(json.dumps(report, indent=2), encoding="utf-8")
|
| 97 |
(destination / "README.md").write_text(
|
| 98 |
"---\nlicense: gpl-3.0\nlibrary_name: peft\npipeline_tag: text-generation\n"
|
| 99 |
f"base_model: {CONFIG['base_model']}\nbase_model_relation: adapter\n"
|
| 100 |
"datasets:\n- HuggingFaceTB/smoltalk\ntags:\n- lora\n- code\n- experimental\n---\n\n"
|
| 101 |
-
"# PocketVision Chat &
|
| 102 |
-
"This candidate has validation-loss measurements only; no claim of better chat or
|
| 103 |
"See training_report.json and data_manifest.json. "
|
| 104 |
-
"Training data: Smol-Magpie-Ultra (Apache-2.0) and the Self-OSS-Instruct subset "
|
| 105 |
"(original: bigcode/self-oss-instruct-sc2-exec-filter-50k, ODC-BY). "
|
| 106 |
"Original base weights remain Apache-2.0; project code and adapter use GPL-3.0-only.\n",
|
| 107 |
encoding="utf-8")
|
|
|
|
| 13 |
manifest = json.loads((folder / "manifest.json").read_text(encoding="utf-8"))
|
| 14 |
if manifest["config"] != CONFIG:
|
| 15 |
raise ValueError("Data manifest does not match the pinned experiment configuration.")
|
| 16 |
+
if "article_examples_sha256" in manifest:
|
| 17 |
+
current = hashlib.sha256(Path(__file__).with_name("article_examples.json").read_bytes()).hexdigest()
|
| 18 |
+
if manifest["article_examples_sha256"] != current:
|
| 19 |
+
raise ValueError("Article behavior examples changed after preparation.")
|
| 20 |
+
records, seen, groups = {}, set(), {}
|
| 21 |
for split in ["train", "validation", "test"]:
|
| 22 |
raw = (folder / f"{split}.jsonl").read_bytes()
|
| 23 |
if hashlib.sha256(raw).hexdigest() != manifest["sha256"][split]:
|
|
|
|
| 30 |
if key != row["prompt_hash"] or key in seen:
|
| 31 |
raise ValueError("Duplicate or inconsistent prompts across dataset splits.")
|
| 32 |
seen.add(key)
|
| 33 |
+
group = row.get("group_id", key)
|
| 34 |
+
if group in groups and groups[group] != split:
|
| 35 |
+
raise ValueError("A source packet appears in multiple dataset splits.")
|
| 36 |
+
groups[group] = split
|
| 37 |
return records
|
| 38 |
|
| 39 |
|
|
|
|
| 100 |
shutil.copy2(Path(args.data) / "manifest.json", destination / "data_manifest.json")
|
| 101 |
report = {"config": CONFIG, "baseline_validation": baseline, "final_validation": final,
|
| 102 |
"training": trained.metrics, "counts": {k: len(v) for k, v in records.items()},
|
| 103 |
+
"status": "candidate_requires_chat_code_and_article_evaluation", "max_steps": args.max_steps}
|
| 104 |
(destination / "training_report.json").write_text(json.dumps(report, indent=2), encoding="utf-8")
|
| 105 |
(destination / "README.md").write_text(
|
| 106 |
"---\nlicense: gpl-3.0\nlibrary_name: peft\npipeline_tag: text-generation\n"
|
| 107 |
f"base_model: {CONFIG['base_model']}\nbase_model_relation: adapter\n"
|
| 108 |
"datasets:\n- HuggingFaceTB/smoltalk\ntags:\n- lora\n- code\n- experimental\n---\n\n"
|
| 109 |
+
"# PocketVision Chat, Code & Writing candidate\n\nText-only QLoRA adapter. "
|
| 110 |
+
"This candidate has validation-loss measurements only; no claim of better chat, coding or factual article quality. "
|
| 111 |
"See training_report.json and data_manifest.json. "
|
| 112 |
+
"Training data: Smol-Magpie-Ultra, Smol-rewrite, Smol-summarize (Apache-2.0), authored fictional article behavior examples (GPL-3.0-only), and the Self-OSS-Instruct subset "
|
| 113 |
"(original: bigcode/self-oss-instruct-sc2-exec-filter-50k, ODC-BY). "
|
| 114 |
"Original base weights remain Apache-2.0; project code and adapter use GPL-3.0-only.\n",
|
| 115 |
encoding="utf-8")
|