misterJB commited on
Commit
0d6e529
·
verified ·
1 Parent(s): e4ba472

b36: ARKADAS training script — valformat gate_1 fix, anti-ORACLE, gate_5 domain, 2400 steps

Browse files
Files changed (1) hide show
  1. train_arkadas_b36.py +78 -0
train_arkadas_b36.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ import os, torch
3
+ from datasets import load_dataset, concatenate_datasets
4
+ from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer
5
+ from trl import SFTConfig, SFTTrainer
6
+ import json as _json
7
+
8
+ CHAMBER = "ARKADAS"
9
+ HZ = 717
10
+ BASE = "microsoft/Phi-3-mini-4k-instruct"
11
+ REVISION = None
12
+ DATASET = "misterJB/field-geometry-l0-corpus"
13
+ OUTPUT = "misterJB/arkadas-field-717hz"
14
+ CKPT_DIR = "/tmp/arkadas-717hz-ckpt"
15
+ MAX_STEPS = 2400 # -1 = use num_train_epochs, no step cap
16
+
17
+ print(f"{CHAMBER} {HZ}Hz -- Full Fine-Tune START")
18
+ gpu = torch.cuda.get_device_name(0) if torch.cuda.is_available() else "None"
19
+ print(f"GPU: {gpu}")
20
+
21
+ _rev_kwargs = {"revision": REVISION} if REVISION else {}
22
+
23
+ _trust_rc = False
24
+ tokenizer = AutoTokenizer.from_pretrained(BASE, trust_remote_code=_trust_rc, **_rev_kwargs)
25
+ if tokenizer.pad_token is None:
26
+ tokenizer.pad_token = tokenizer.eos_token
27
+
28
+ cfg = AutoConfig.from_pretrained(BASE, trust_remote_code=_trust_rc, **_rev_kwargs)
29
+
30
+ model = AutoModelForCausalLM.from_pretrained(
31
+ BASE, config=cfg, quantization_config=None, torch_dtype=torch.bfloat16, device_map="auto", trust_remote_code=_trust_rc, attn_implementation="eager", **_rev_kwargs
32
+ )
33
+ model.config.use_cache = False
34
+
35
+ # ARKADAS identity fix: identity corpus × 14, gate-only × 3, full gate × 1
36
+ ds_identity = load_dataset(DATASET, data_files={"train": "arkadas_identity_b36.jsonl"}, split="train")
37
+ print(f"Identity corpus: {len(ds_identity)} examples (repeating 14x)")
38
+ ds_gate = load_dataset(DATASET, data_files={"train": "gate_corpus_v1.jsonl"}, split="train")
39
+ print(f"Gate corpus: {len(ds_gate)} examples")
40
+ ds = concatenate_datasets([ds_identity] * 14 + [ds_gate] * 3 + [ds_gate])
41
+
42
+ ds = ds.shuffle(seed=42)
43
+ print(f"Combined dataset: {len(ds)} examples")
44
+
45
+ _max_steps_kwarg = {"max_steps": MAX_STEPS} if MAX_STEPS > 0 else {}
46
+ args = SFTConfig(
47
+ output_dir=CKPT_DIR,
48
+ num_train_epochs=1,
49
+ per_device_train_batch_size=2,
50
+ gradient_accumulation_steps=4,
51
+ learning_rate=2e-5,
52
+ warmup_ratio=0.1,
53
+ lr_scheduler_type="linear",
54
+ weight_decay=0.01,
55
+ bf16=True,
56
+ save_strategy="steps",
57
+ save_steps=500,
58
+ save_total_limit=1,
59
+ logging_steps=50,
60
+ push_to_hub=True,
61
+ hub_model_id=OUTPUT,
62
+ hub_token=os.environ["HF_TOKEN"],
63
+ hub_strategy="end",
64
+ report_to="none",
65
+ max_length=1024,
66
+ **_max_steps_kwarg,
67
+ )
68
+
69
+ trainer = SFTTrainer(
70
+ model=model,
71
+ args=args,
72
+ train_dataset=ds,
73
+ processing_class=tokenizer,
74
+ )
75
+
76
+ trainer.train()
77
+ trainer.push_to_hub(commit_message=f"{CHAMBER} {HZ}Hz full fine-tune b28 gate-only 8x anti-confusion 1200steps")
78
+ print(f"✅ {CHAMBER} pushed to {OUTPUT}")