Text Generation
Transformers
prism_custom
feature-extraction
prism
custom-architecture
trust-remote-code
neural-architecture-search
custom_code
Instructions to use BaseIntelligence/top-prism-architecture with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use BaseIntelligence/top-prism-architecture with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="BaseIntelligence/top-prism-architecture", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("BaseIntelligence/top-prism-architecture", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use BaseIntelligence/top-prism-architecture with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "BaseIntelligence/top-prism-architecture" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "BaseIntelligence/top-prism-architecture", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/BaseIntelligence/top-prism-architecture
- SGLang
How to use BaseIntelligence/top-prism-architecture 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 "BaseIntelligence/top-prism-architecture" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "BaseIntelligence/top-prism-architecture", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "BaseIntelligence/top-prism-architecture" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "BaseIntelligence/top-prism-architecture", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use BaseIntelligence/top-prism-architecture with Docker Model Runner:
docker model run hf.co/BaseIntelligence/top-prism-architecture
top-model: arch_f17d92b32a8c79f7 bpb=3.7181
Browse files- METRICS.json +286 -284
- README.md +19 -19
- architecture.py +540 -621
- checkpoint.pt +2 -2
- config.json +3 -3
- sources/.prism/automodel.patch +0 -0
- sources/.prism/diffstat.json +1 -1
- sources/nemo_automodel/recipes/llm/prism_entry.py +53 -6
- sources/prism.toml +1 -38
- sources/tokenizer/tokenizer.json +0 -0
- sources/tokenizer/tokenizer_config.json +2 -2
- training.py +620 -0
METRICS.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
{
|
| 2 |
-
"submission_id": "
|
| 3 |
-
"arch_id": "
|
| 4 |
-
"owner_hotkey": "
|
| 5 |
-
"bpb": 3.
|
| 6 |
-
"n_params":
|
| 7 |
"tokens_seen": 2048,
|
| 8 |
-
"wall_clock_seconds":
|
| 9 |
"battery": {
|
| 10 |
"tier": "public",
|
| 11 |
"groups": {
|
|
@@ -13,61 +13,61 @@
|
|
| 13 |
"module": "g1_intrinsic",
|
| 14 |
"status": "ok",
|
| 15 |
"metrics": {
|
| 16 |
-
"g1.bpb.val": 3.
|
| 17 |
-
"g1.bpb.fresh": 4.
|
| 18 |
-
"g1.bpb.key_token": 5.
|
| 19 |
-
"g1.posloss.p0_128":
|
| 20 |
-
"g1.bpb.domain.code": 3.
|
| 21 |
-
"g1.bpb.domain.math": 4.
|
| 22 |
-
"g1.bpb.domain.news": 5.
|
| 23 |
-
"g1.bpb.multidomain": 4.
|
| 24 |
-
"g1.bpb.domain.prose": 4.
|
| 25 |
-
"g1.posloss.p128_256": 3.
|
| 26 |
-
"g1.posloss.p256_384": 3.
|
| 27 |
-
"g1.posloss.p384_512": 3.
|
| 28 |
-
"g1.posloss.p512_end": 3.
|
| 29 |
-
"g1.bits_per_byte.val": 0.
|
| 30 |
-
"g1.bits_per_byte.fresh": 1.
|
| 31 |
"g1.assets.domains_present": 4.0,
|
| 32 |
-
"g1.bits_per_byte.key_token": 0.
|
| 33 |
-
"g1.bits_per_byte.domain.code": 1.
|
| 34 |
-
"g1.bits_per_byte.domain.math": 1.
|
| 35 |
-
"g1.bits_per_byte.domain.news": 1.
|
| 36 |
-
"g1.bits_per_byte.multidomain": 1.
|
| 37 |
-
"g1.bits_per_byte.domain.prose": 1.
|
| 38 |
}
|
| 39 |
},
|
| 40 |
"g2": {
|
| 41 |
"module": "g2_downstream",
|
| 42 |
"status": "ok",
|
| 43 |
"metrics": {
|
| 44 |
-
"g2.core.mean_nll": 4.
|
| 45 |
-
"g2.piqa.acc_norm": 0.
|
| 46 |
-
"g2.boolq.acc_norm": 0.
|
| 47 |
-
"g2.lambada.acc_norm": 0.
|
| 48 |
-
"g2.arc_easy.acc_norm": 0.
|
| 49 |
-
"g2.core.mean_acc_norm": 0.
|
| 50 |
-
"g2.hellaswag.acc_norm": 0.
|
| 51 |
-
"g2.openbookqa.acc_norm": 0.
|
| 52 |
-
"g2.winogrande.acc_norm": 0.
|
| 53 |
"g2.assets.tasks_present": 8.0,
|
| 54 |
-
"g2.arc_challenge.acc_norm": 0.
|
| 55 |
}
|
| 56 |
},
|
| 57 |
"g3": {
|
| 58 |
"module": "g3_recall",
|
| 59 |
"status": "ok",
|
| 60 |
"metrics": {
|
| 61 |
-
"g3.copy.acc": 0.
|
| 62 |
-
"g3.mqar.acc": 0.
|
| 63 |
"g3.copy.g0.acc": 0.4166666666666667,
|
| 64 |
-
"g3.mqar.n4.acc": 0.
|
| 65 |
"g3.mqar.n8.acc": 0.25,
|
| 66 |
-
"g3.copy.g16.acc": 0.
|
| 67 |
-
"g3.copy.g64.acc": 0.
|
| 68 |
"g3.mqar.n16.acc": 0.0625,
|
| 69 |
-
"g3.recall.mean_acc": 0.
|
| 70 |
-
"g3.recall.mean_nll": 5.
|
| 71 |
"g3.passkey.base.acc": 1.0,
|
| 72 |
"g3.induction.base.acc": 1.0
|
| 73 |
}
|
|
@@ -76,133 +76,133 @@
|
|
| 76 |
"module": "g4_reasoning",
|
| 77 |
"status": "ok",
|
| 78 |
"metrics": {
|
| 79 |
-
"g4.kk.acc": 0.
|
| 80 |
-
"g4.s5.acc": 0.
|
| 81 |
-
"g4.mod.acc": 0.
|
| 82 |
-
"g4.bool.acc": 0.
|
| 83 |
-
"g4.dyck.acc": 0.
|
| 84 |
-
"g4.arith.acc": 0.
|
| 85 |
-
"g4.kk.n3.acc": 0.
|
| 86 |
-
"g4.proof.acc": 0.
|
| 87 |
-
"g4.s5.k5.acc": 0.
|
| 88 |
"g4.mod.id.acc": 0.25,
|
| 89 |
"g4.s5.k10.acc": 0.0,
|
| 90 |
-
"g4.dyck.k1.acc": 0.
|
| 91 |
-
"g4.dyck.k2.acc": 0.
|
| 92 |
-
"g4.mod.ood.acc": 0.
|
| 93 |
-
"g4.arith.t1.acc": 0.
|
| 94 |
-
"g4.arith.t2.acc": 0.
|
| 95 |
"g4.arith.t3.acc": 0.0,
|
| 96 |
-
"g4.proof.d0.acc":
|
| 97 |
-
"g4.proof.d1.acc":
|
| 98 |
-
"g4.proof.d2.acc":
|
| 99 |
"g4.proof.d3.acc": 0.25,
|
| 100 |
-
"g4.bool.base.acc": 0.
|
| 101 |
"g4.arith.noop.acc": 0.25,
|
| 102 |
-
"g4.mod.id_ood_gap": 0.25,
|
| 103 |
-
"g4.dyck.k2long.acc": 0.
|
| 104 |
-
"g4.arith.extrap.acc": 0.
|
| 105 |
-
"g4.reasoning.mean_acc": 0.
|
| 106 |
-
"g4.reasoning.mean_nll":
|
| 107 |
}
|
| 108 |
},
|
| 109 |
"g5": {
|
| 110 |
"module": "g5_longctx",
|
| 111 |
"status": "ok",
|
| 112 |
"metrics": {
|
| 113 |
-
"g5.lstar":
|
| 114 |
-
"g5.retention":
|
| 115 |
-
"g5.ruler.acc": 0.
|
| 116 |
-
"g5.babilong.acc": 0.
|
| 117 |
"g5.helmet_rag.n": 20.0,
|
| 118 |
-
"g5.ruler.qa.acc": 0.
|
| 119 |
-
"g5.ruler.vt.acc": 0.
|
| 120 |
"g5.natural_mcq.n": 40.0,
|
| 121 |
"g5.ruler.qa.pack": 1.0,
|
| 122 |
-
"g5.helmet_rag.acc": 0.
|
| 123 |
-
"g5.mean.L4096.acc": 0.
|
| 124 |
-
"g5.mean.L8192.acc": 0.
|
| 125 |
"g5.natural.staged": 1.0,
|
| 126 |
-
"g5.ruler.mean_nll": 3.
|
| 127 |
-
"g5.mean.L16384.acc": 0.
|
| 128 |
-
"g5.mean.L32768.acc": 0.
|
| 129 |
"g5.mean.L65536.acc": 0.3,
|
| 130 |
-
"g5.natural_mcq.acc": 0.
|
| 131 |
-
"g5.ruler.L4096.acc": 0.
|
| 132 |
-
"g5.ruler.L8192.acc": 0.
|
| 133 |
"g5.ruler.shot_rate": 0.8181818181818182,
|
| 134 |
-
"g5.babilong.qa1.acc": 0.
|
| 135 |
-
"g5.babilong.qa2.acc": 0.
|
| 136 |
-
"g5.babilong.qa3.acc": 0.
|
| 137 |
-
"g5.babilong.qa4.acc": 0.
|
| 138 |
"g5.babilong.qa5.acc": 0.16666666666666666,
|
| 139 |
-
"g5.ruler.L16384.acc": 0.
|
| 140 |
-
"g5.ruler.L32768.acc": 0.
|
| 141 |
"g5.ruler.L65536.acc": 0.3,
|
| 142 |
-
"g5.ruler.mean_depth": 0.
|
| 143 |
-
"g5.babilong.mean_nll":
|
| 144 |
"g5.helmet_rag.rank_n": 20.0,
|
| 145 |
-
"g5.ruler.niah_mk.acc": 0.
|
| 146 |
"g5.ruler.niah_mq.acc": 0.09375,
|
| 147 |
"g5.ruler.niah_mv.acc": 0.3125,
|
| 148 |
-
"g5.babilong.L4096.acc": 0.
|
| 149 |
-
"g5.babilong.L8192.acc": 0.
|
| 150 |
-
"g5.ruler.qa.L4096.acc": 0.
|
| 151 |
-
"g5.ruler.qa.L8192.acc":
|
| 152 |
-
"g5.ruler.vt.L4096.acc": 0.
|
| 153 |
-
"g5.ruler.vt.L8192.acc": 0.
|
| 154 |
-
"g5.babilong.L16384.acc": 0.
|
| 155 |
-
"g5.babilong.mean_depth": 0.
|
| 156 |
"g5.babilong.mean_shots": 2.0,
|
| 157 |
-
"g5.helmet_rag.gold_nll": 4.
|
| 158 |
"g5.helmet_rag.rank_acc": 0.5,
|
| 159 |
-
"g5.ruler.L4096.len_err": 0.
|
| 160 |
-
"g5.ruler.L8192.len_err": 0.
|
| 161 |
"g5.ruler.evidence_miss": 0.0,
|
| 162 |
"g5.ruler.qa.L16384.acc": 0.0,
|
| 163 |
"g5.ruler.qa.L32768.acc": 0.0,
|
| 164 |
-
"g5.ruler.vt.L16384.acc": 0.
|
| 165 |
-
"g5.ruler.vt.L32768.acc": 0.
|
| 166 |
"g5.ruler.vt.L65536.acc": 0.1,
|
| 167 |
"g5.babilong.filler_pack": 1.0,
|
| 168 |
-
"g5.helmet_rag.L8192.acc": 0.
|
| 169 |
-
"g5.natural_mcq.mean_nll": 3.
|
| 170 |
-
"g5.ruler.L16384.len_err": 0.
|
| 171 |
"g5.ruler.L32768.len_err": 0.0,
|
| 172 |
"g5.ruler.L65536.len_err": 0.0,
|
| 173 |
-
"g5.natural_mcq.L8192.acc": 0.
|
| 174 |
"g5.babilong.L4096.len_err": 0.0,
|
| 175 |
"g5.babilong.L8192.len_err": 0.0,
|
| 176 |
"g5.babilong.evidence_miss": 0.0,
|
| 177 |
-
"g5.babilong.qa1.L4096.acc": 0.
|
| 178 |
"g5.babilong.qa1.L8192.acc": 0.0,
|
| 179 |
-
"g5.babilong.qa2.L4096.acc": 0.
|
| 180 |
-
"g5.babilong.qa2.L8192.acc": 0.
|
| 181 |
-
"g5.babilong.qa3.L4096.acc": 0.
|
| 182 |
"g5.babilong.qa3.L8192.acc": 0.0,
|
| 183 |
"g5.babilong.qa4.L4096.acc": 0.0,
|
| 184 |
-
"g5.babilong.qa4.L8192.acc": 0.
|
| 185 |
"g5.babilong.qa5.L4096.acc": 0.0,
|
| 186 |
-
"g5.babilong.qa5.L8192.acc": 0.
|
| 187 |
"g5.babilong.L16384.len_err": 0.0,
|
| 188 |
"g5.babilong.qa1.L16384.acc": 0.0,
|
| 189 |
-
"g5.babilong.qa2.L16384.acc": 0.
|
| 190 |
"g5.babilong.qa3.L16384.acc": 0.0,
|
| 191 |
-
"g5.babilong.qa4.L16384.acc": 0.
|
| 192 |
-
"g5.babilong.qa5.L16384.acc": 0.
|
| 193 |
-
"g5.ruler.niah_mk.L4096.acc":
|
| 194 |
"g5.ruler.niah_mk.L8192.acc": 0.0,
|
| 195 |
-
"g5.ruler.niah_mq.L4096.acc": 0.
|
| 196 |
"g5.ruler.niah_mq.L8192.acc": 0.0,
|
| 197 |
-
"g5.ruler.niah_mv.L4096.acc": 0.
|
| 198 |
-
"g5.ruler.niah_mv.L8192.acc": 0.
|
| 199 |
-
"g5.ruler.niah_mk.L16384.acc": 0.
|
| 200 |
"g5.ruler.niah_mk.L32768.acc": 0.5,
|
| 201 |
"g5.ruler.niah_mk.L65536.acc": 0.5,
|
| 202 |
"g5.ruler.niah_mq.L16384.acc": 0.125,
|
| 203 |
-
"g5.ruler.niah_mq.L32768.acc": 0.
|
| 204 |
-
"g5.ruler.niah_mv.L16384.acc": 0.
|
| 205 |
-
"g5.ruler.niah_mv.L32768.acc": 0.
|
| 206 |
"g5.natural.pool_rows.helmet_rag": 96.0,
|
| 207 |
"g5.natural.pool_rows.natural_mcq": 64.0
|
| 208 |
}
|
|
@@ -219,20 +219,20 @@
|
|
| 219 |
"module": "g7_inference",
|
| 220 |
"status": "ok",
|
| 221 |
"metrics": {
|
| 222 |
-
"g7.vram.peak_gb":
|
| 223 |
-
"g7.tpot.L1024.ms":
|
| 224 |
-
"g7.tpot.L4096.ms":
|
| 225 |
-
"g7.ttft.L1024.ms":
|
| 226 |
-
"g7.ttft.L4096.ms":
|
| 227 |
-
"g7.tpot.L16384.ms":
|
| 228 |
-
"g7.tpot.L32768.ms":
|
| 229 |
-
"g7.ttft.L16384.ms":
|
| 230 |
-
"g7.ttft.L32768.ms":
|
| 231 |
-
"g7.quant.w8a8.dbpb": 0.
|
| 232 |
-
"g7.quant.w4a16.dbpb": 0.
|
| 233 |
-
"g7.energy.j_per_token": 0.
|
| 234 |
-
"g7.throughput.b1.toks":
|
| 235 |
-
"g7.throughput.b32.toks":
|
| 236 |
"g7.state.analytic_unavailable": 1.0,
|
| 237 |
"g7.state.bytes_per_token.measured": 8.0
|
| 238 |
}
|
|
@@ -241,91 +241,91 @@
|
|
| 241 |
"module": "g8_stability",
|
| 242 |
"status": "ok",
|
| 243 |
"metrics": {
|
| 244 |
-
"g8.mup.stub":
|
| 245 |
"g8.spikes.count": 0.0,
|
| 246 |
-
"g8.mup.stability":
|
| 247 |
"g8.spikes.per_1k_steps": 0.0,
|
| 248 |
-
"g8.mup.lr_ratio_log2_abs": 0.0,
|
| 249 |
"g8.divergence.probe_nan_frac": 0.0,
|
| 250 |
-
"g8.divergence.series_nan_frac": 0.0
|
|
|
|
| 251 |
}
|
| 252 |
}
|
| 253 |
},
|
| 254 |
"metrics": {
|
| 255 |
-
"org.g5.lstar":
|
| 256 |
"org.g2.obqa_acc": {
|
| 257 |
-
"value": 0.
|
| 258 |
"clusters": {
|
| 259 |
-
"g2/openbookqa": 0.
|
| 260 |
}
|
| 261 |
},
|
| 262 |
"org.g2.piqa_acc": {
|
| 263 |
-
"value": 0.
|
| 264 |
"clusters": {
|
| 265 |
-
"g2/piqa": 0.
|
| 266 |
}
|
| 267 |
},
|
| 268 |
"org.g3.mqar_acc": {
|
| 269 |
-
"value": 0.
|
| 270 |
"clusters": {
|
| 271 |
-
"mqar/n4": 0.
|
| 272 |
"mqar/n8": 0.25,
|
| 273 |
"mqar/n16": 0.0625
|
| 274 |
}
|
| 275 |
},
|
| 276 |
"org.g4.dyck_acc": {
|
| 277 |
-
"value": 0.
|
| 278 |
"clusters": {
|
| 279 |
-
"dyck/k1/len10": 0.
|
| 280 |
-
"dyck/k2/len10": 0.
|
| 281 |
-
"dyck/k2/len28": 0.
|
| 282 |
}
|
| 283 |
},
|
| 284 |
"org.g2.boolq_acc": {
|
| 285 |
-
"value": 0.
|
| 286 |
"clusters": {
|
| 287 |
-
"g2/boolq": 0.
|
| 288 |
}
|
| 289 |
},
|
| 290 |
"org.g5.ruler_acc": {
|
| 291 |
-
"value": 0.
|
| 292 |
"clusters": {
|
| 293 |
-
"qa@4096": 0.
|
| 294 |
-
"qa@8192":
|
| 295 |
-
"vt@4096": 0.
|
| 296 |
-
"vt@8192": 0.
|
| 297 |
"qa@16384": 0.0,
|
| 298 |
"qa@32768": 0.0,
|
| 299 |
-
"vt@16384": 0.
|
| 300 |
-
"vt@32768": 0.
|
| 301 |
"vt@65536": 0.1,
|
| 302 |
-
"niah_mk@4096":
|
| 303 |
"niah_mk@8192": 0.0,
|
| 304 |
-
"niah_mq@4096": 0.
|
| 305 |
"niah_mq@8192": 0.0,
|
| 306 |
-
"niah_mv@4096": 0.
|
| 307 |
-
"niah_mv@8192": 0.
|
| 308 |
-
"niah_mk@16384": 0.
|
| 309 |
"niah_mk@32768": 0.5,
|
| 310 |
"niah_mk@65536": 0.5,
|
| 311 |
"niah_mq@16384": 0.125,
|
| 312 |
-
"niah_mq@32768": 0.
|
| 313 |
-
"niah_mv@16384": 0.
|
| 314 |
-
"niah_mv@32768": 0.
|
| 315 |
}
|
| 316 |
},
|
| 317 |
"org.g2.lambada_acc": {
|
| 318 |
-
"value": 0.
|
| 319 |
"clusters": {
|
| 320 |
-
"g2/lambada": 0.
|
| 321 |
}
|
| 322 |
},
|
| 323 |
"org.g3.copying_acc": {
|
| 324 |
-
"value": 0.
|
| 325 |
"clusters": {
|
| 326 |
"copy/len16/gap0": 0.4166666666666667,
|
| 327 |
-
"copy/len16/gap16": 0.
|
| 328 |
-
"copy/len16/gap64": 0.
|
| 329 |
}
|
| 330 |
},
|
| 331 |
"org.g3.passkey_acc": {
|
|
@@ -335,49 +335,49 @@
|
|
| 335 |
}
|
| 336 |
},
|
| 337 |
"org.g4.modular_acc": {
|
| 338 |
-
"value": 0.
|
| 339 |
"clusters": {
|
| 340 |
"mod/p97/id": 0.25,
|
| 341 |
-
"mod/p97/ood": 0.
|
| 342 |
}
|
| 343 |
},
|
| 344 |
-
"org.g7.tpot_ms_32k":
|
| 345 |
"org.g7.ttft_ms_32k": {
|
| 346 |
-
"value":
|
| 347 |
"clusters": {
|
| 348 |
-
"L32768":
|
| 349 |
}
|
| 350 |
},
|
| 351 |
"org.g2.arc_easy_acc": {
|
| 352 |
-
"value": 0.
|
| 353 |
"clusters": {
|
| 354 |
-
"g2/arc_easy": 0.
|
| 355 |
}
|
| 356 |
},
|
| 357 |
"org.g5.babilong_acc": {
|
| 358 |
-
"value": 0.
|
| 359 |
"clusters": {
|
| 360 |
-
"qa1@4096": 0.
|
| 361 |
"qa1@8192": 0.0,
|
| 362 |
-
"qa2@4096": 0.
|
| 363 |
-
"qa2@8192": 0.
|
| 364 |
-
"qa3@4096": 0.
|
| 365 |
"qa3@8192": 0.0,
|
| 366 |
"qa4@4096": 0.0,
|
| 367 |
-
"qa4@8192": 0.
|
| 368 |
"qa5@4096": 0.0,
|
| 369 |
-
"qa5@8192": 0.
|
| 370 |
"qa1@16384": 0.0,
|
| 371 |
-
"qa2@16384": 0.
|
| 372 |
"qa3@16384": 0.0,
|
| 373 |
-
"qa4@16384": 0.
|
| 374 |
-
"qa5@16384": 0.
|
| 375 |
}
|
| 376 |
},
|
| 377 |
"org.g2.hellaswag_acc": {
|
| 378 |
-
"value": 0.
|
| 379 |
"clusters": {
|
| 380 |
-
"g2/hellaswag": 0.
|
| 381 |
}
|
| 382 |
},
|
| 383 |
"org.g3.induction_acc": {
|
|
@@ -387,101 +387,102 @@
|
|
| 387 |
}
|
| 388 |
},
|
| 389 |
"org.g2.winogrande_acc": {
|
| 390 |
-
"value": 0.
|
| 391 |
"clusters": {
|
| 392 |
-
"g2/winogrande": 0.
|
| 393 |
}
|
| 394 |
},
|
| 395 |
"org.g4.arithmetic_acc": {
|
| 396 |
-
"value": 0.
|
| 397 |
"clusters": {
|
| 398 |
-
"arith/t1": 0.
|
| 399 |
-
"arith/t2": 0.
|
| 400 |
"arith/t3": 0.0,
|
| 401 |
"arith/t2/noop": 0.25,
|
| 402 |
-
"arith/t2/extrap": 0.
|
| 403 |
}
|
| 404 |
},
|
| 405 |
"org.g5.helmet_rag_acc": {
|
| 406 |
-
"value": 0.
|
| 407 |
"clusters": {
|
| 408 |
"helmet_rag@nq": 0.0,
|
| 409 |
"helmet_rag@popqa": 0.0,
|
| 410 |
-
"helmet_rag@hotpotqa": 0.
|
| 411 |
-
"helmet_rag@triviaqa": 0.
|
| 412 |
}
|
| 413 |
},
|
| 414 |
"org.g4.proofwriter_acc": {
|
| 415 |
-
"value": 0.
|
| 416 |
"clusters": {
|
|
|
|
| 417 |
"proof/d0/pos": 1.0,
|
|
|
|
| 418 |
"proof/d1/pos": 1.0,
|
| 419 |
-
"proof/d2/neg": 0.0,
|
| 420 |
"proof/d2/pos": 1.0,
|
| 421 |
"proof/d3/neg": 0.0,
|
| 422 |
"proof/d3/pos": 1.0
|
| 423 |
}
|
| 424 |
},
|
| 425 |
"org.g5.natural_mcq_acc": {
|
| 426 |
-
"value": 0.
|
| 427 |
"clusters": {
|
| 428 |
-
"natural_mcq@Multi-Document QA": 0.
|
| 429 |
-
"natural_mcq@Single-Document QA": 0.
|
| 430 |
-
"natural_mcq@
|
| 431 |
-
"natural_mcq@
|
| 432 |
-
"natural_mcq@Long-dialogue History Understanding": 0.
|
| 433 |
}
|
| 434 |
},
|
| 435 |
-
"org.g7.joules_per_token": 0.
|
| 436 |
"org.g8.loss_spike_score": 1.0,
|
| 437 |
-
"org.g8.mup_lr_stability":
|
| 438 |
"org.g2.arc_challenge_acc": {
|
| 439 |
-
"value": 0.
|
| 440 |
"clusters": {
|
| 441 |
-
"g2/arc_challenge": 0.
|
| 442 |
}
|
| 443 |
},
|
| 444 |
"org.g4.boolean_logic_acc": {
|
| 445 |
-
"value": 0.
|
| 446 |
"clusters": {
|
| 447 |
-
"bool/d2": 0.
|
| 448 |
}
|
| 449 |
},
|
| 450 |
"org.g7.throughput_toks_s": {
|
| 451 |
-
"value":
|
| 452 |
"clusters": {
|
| 453 |
-
"b32":
|
| 454 |
}
|
| 455 |
},
|
| 456 |
"org.g1.bits_per_byte_code": {
|
| 457 |
-
"value": 1.
|
| 458 |
"clusters": {
|
| 459 |
-
"domain/code": 1.
|
| 460 |
}
|
| 461 |
},
|
| 462 |
"org.g1.bits_per_byte_math": {
|
| 463 |
-
"value": 1.
|
| 464 |
"clusters": {
|
| 465 |
-
"domain/math": 1.
|
| 466 |
}
|
| 467 |
},
|
| 468 |
"org.g4.knights_knaves_acc": {
|
| 469 |
-
"value": 0.
|
| 470 |
"clusters": {
|
| 471 |
-
"kk/n3": 0.
|
| 472 |
}
|
| 473 |
},
|
| 474 |
"org.g1.bits_per_byte_prose": {
|
| 475 |
-
"value": 1.
|
| 476 |
"clusters": {
|
| 477 |
-
"domain/prose": 1.
|
| 478 |
}
|
| 479 |
},
|
| 480 |
-
"org.g1.bits_per_byte_key_token": 0.
|
| 481 |
"org.g1.bits_per_byte_fresh_crawl": {
|
| 482 |
-
"value": 1.
|
| 483 |
"clusters": {
|
| 484 |
-
"fresh": 1.
|
| 485 |
}
|
| 486 |
},
|
| 487 |
"org.g7.state_bytes_per_token_32k": 8.0
|
|
@@ -491,11 +492,11 @@
|
|
| 491 |
"group": "g4",
|
| 492 |
"metric": "org.g4.arithmetic_acc",
|
| 493 |
"mirror": {
|
| 494 |
-
"value": 0.
|
| 495 |
"clusters": {
|
| 496 |
"arith#0": 0.0,
|
| 497 |
"arith#1": 0.0,
|
| 498 |
-
"arith#2":
|
| 499 |
"arith#3": 0.0
|
| 500 |
}
|
| 501 |
},
|
|
@@ -513,12 +514,12 @@
|
|
| 513 |
"group": "g4",
|
| 514 |
"metric": "org.g4.boolean_logic_acc",
|
| 515 |
"mirror": {
|
| 516 |
-
"value": 0.
|
| 517 |
"clusters": {
|
| 518 |
-
"boolean_expr#0":
|
| 519 |
-
"boolean_expr#1":
|
| 520 |
"boolean_expr#2": 1.0,
|
| 521 |
-
"boolean_expr#3":
|
| 522 |
}
|
| 523 |
},
|
| 524 |
"public": {
|
|
@@ -535,18 +536,18 @@
|
|
| 535 |
"group": "g4",
|
| 536 |
"metric": "org.g4.dyck_acc",
|
| 537 |
"mirror": {
|
| 538 |
-
"value": 0.
|
| 539 |
"clusters": {
|
| 540 |
-
"dyck#0": 0.
|
| 541 |
-
"dyck#1":
|
| 542 |
"dyck#2": 0.3333333333333333,
|
| 543 |
-
"dyck#3":
|
| 544 |
}
|
| 545 |
},
|
| 546 |
"public": {
|
| 547 |
-
"value": 0.
|
| 548 |
"clusters": {
|
| 549 |
-
"dyck#0": 0.
|
| 550 |
"dyck#1": 0.6666666666666666,
|
| 551 |
"dyck#2": 0.6666666666666666,
|
| 552 |
"dyck#3": 0.6666666666666666
|
|
@@ -557,20 +558,20 @@
|
|
| 557 |
"group": "g4",
|
| 558 |
"metric": "org.g4.modular_acc",
|
| 559 |
"mirror": {
|
| 560 |
-
"value": 0.
|
| 561 |
"clusters": {
|
| 562 |
"modular#0": 0.0,
|
| 563 |
"modular#1": 0.0,
|
| 564 |
"modular#2": 0.0,
|
| 565 |
-
"modular#3":
|
| 566 |
}
|
| 567 |
},
|
| 568 |
"public": {
|
| 569 |
-
"value": 0.
|
| 570 |
"clusters": {
|
| 571 |
-
"modular#0":
|
| 572 |
-
"modular#1":
|
| 573 |
-
"modular#2":
|
| 574 |
"modular#3": 1.0
|
| 575 |
}
|
| 576 |
}
|
|
@@ -579,12 +580,12 @@
|
|
| 579 |
"group": "g4",
|
| 580 |
"metric": "org.g4.knights_knaves_acc",
|
| 581 |
"mirror": {
|
| 582 |
-
"value": 0.
|
| 583 |
"clusters": {
|
| 584 |
-
"knights_knaves#0":
|
| 585 |
-
"knights_knaves#1":
|
| 586 |
-
"knights_knaves#2":
|
| 587 |
-
"knights_knaves#3":
|
| 588 |
}
|
| 589 |
},
|
| 590 |
"public": {
|
|
@@ -623,9 +624,9 @@
|
|
| 623 |
"group": "g2",
|
| 624 |
"metric": "org.g2.lambada_acc",
|
| 625 |
"mirror": {
|
| 626 |
-
"value":
|
| 627 |
"clusters": {
|
| 628 |
-
"lambada#0":
|
| 629 |
"lambada#1": 1.0,
|
| 630 |
"lambada#2": 1.0,
|
| 631 |
"lambada#3": 1.0
|
|
@@ -654,11 +655,11 @@
|
|
| 654 |
}
|
| 655 |
},
|
| 656 |
"public": {
|
| 657 |
-
"value":
|
| 658 |
"clusters": {
|
| 659 |
"hellaswag#0": 1.0,
|
| 660 |
-
"hellaswag#1":
|
| 661 |
-
"hellaswag#2":
|
| 662 |
"hellaswag#3": 1.0
|
| 663 |
}
|
| 664 |
}
|
|
@@ -667,18 +668,18 @@
|
|
| 667 |
"group": "g2",
|
| 668 |
"metric": "org.g2.piqa_acc",
|
| 669 |
"mirror": {
|
| 670 |
-
"value": 0.
|
| 671 |
"clusters": {
|
| 672 |
"piqa#0": 1.0,
|
| 673 |
"piqa#1": 0.0,
|
| 674 |
"piqa#2": 0.0,
|
| 675 |
-
"piqa#3":
|
| 676 |
}
|
| 677 |
},
|
| 678 |
"public": {
|
| 679 |
-
"value":
|
| 680 |
"clusters": {
|
| 681 |
-
"piqa#0":
|
| 682 |
"piqa#1": 1.0,
|
| 683 |
"piqa#2": 1.0,
|
| 684 |
"piqa#3": 1.0
|
|
@@ -689,11 +690,11 @@
|
|
| 689 |
"group": "g2",
|
| 690 |
"metric": "org.g2.arc_easy_acc",
|
| 691 |
"mirror": {
|
| 692 |
-
"value": 0.
|
| 693 |
"clusters": {
|
| 694 |
"arc_easy#0": 1.0,
|
| 695 |
"arc_easy#1": 1.0,
|
| 696 |
-
"arc_easy#2":
|
| 697 |
"arc_easy#3": 0.0
|
| 698 |
}
|
| 699 |
},
|
|
@@ -711,9 +712,9 @@
|
|
| 711 |
"group": "g2",
|
| 712 |
"metric": "org.g2.arc_challenge_acc",
|
| 713 |
"mirror": {
|
| 714 |
-
"value": 0.
|
| 715 |
"clusters": {
|
| 716 |
-
"arc_challenge#0":
|
| 717 |
"arc_challenge#1": 1.0,
|
| 718 |
"arc_challenge#2": 0.0,
|
| 719 |
"arc_challenge#3": 1.0
|
|
@@ -777,18 +778,18 @@
|
|
| 777 |
"group": "g2",
|
| 778 |
"metric": "org.g2.obqa_acc",
|
| 779 |
"mirror": {
|
| 780 |
-
"value": 0.
|
| 781 |
"clusters": {
|
| 782 |
"openbookqa#0": 1.0,
|
| 783 |
"openbookqa#1": 0.0,
|
| 784 |
"openbookqa#2": 0.0,
|
| 785 |
-
"openbookqa#3":
|
| 786 |
}
|
| 787 |
},
|
| 788 |
"public": {
|
| 789 |
-
"value": 0.
|
| 790 |
"clusters": {
|
| 791 |
-
"openbookqa#0":
|
| 792 |
"openbookqa#1": 1.0,
|
| 793 |
"openbookqa#2": 1.0,
|
| 794 |
"openbookqa#3": 0.0
|
|
@@ -799,19 +800,20 @@
|
|
| 799 |
"group": "g5",
|
| 800 |
"metric": "org.g5.natural_mcq_acc",
|
| 801 |
"mirror": {
|
| 802 |
-
"value": 0.
|
| 803 |
"clusters": {
|
| 804 |
-
"Multi-Document QA":
|
| 805 |
"Single-Document QA": 0.0,
|
| 806 |
-
"
|
|
|
|
| 807 |
}
|
| 808 |
},
|
| 809 |
"public": {
|
| 810 |
-
"value": 0.
|
| 811 |
"clusters": {
|
| 812 |
"Multi-Document QA": 0.0,
|
| 813 |
-
"
|
| 814 |
-
"
|
| 815 |
}
|
| 816 |
}
|
| 817 |
},
|
|
@@ -819,18 +821,18 @@
|
|
| 819 |
"group": "g5",
|
| 820 |
"metric": "org.g5.helmet_rag_acc",
|
| 821 |
"mirror": {
|
| 822 |
-
"value": 0.
|
| 823 |
"clusters": {
|
| 824 |
-
"
|
| 825 |
-
"hotpotqa": 0.0
|
| 826 |
-
"triviaqa": 1.0
|
| 827 |
}
|
| 828 |
},
|
| 829 |
"public": {
|
| 830 |
-
"value": 0.
|
| 831 |
"clusters": {
|
| 832 |
-
"
|
| 833 |
-
"
|
|
|
|
| 834 |
}
|
| 835 |
}
|
| 836 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"submission_id": "7b8658aedfdb158782567d09e26a9e819c578ff20c4db1d940e12de77cd9d6d2",
|
| 3 |
+
"arch_id": "arch_f17d92b32a8c79f7",
|
| 4 |
+
"owner_hotkey": "462c4a7dfe3091db3333dfb6cd5967e2b1d6f07bd1ceeb60300dcd63d13d3976",
|
| 5 |
+
"bpb": 3.7180674325750696,
|
| 6 |
+
"n_params": 106980502,
|
| 7 |
"tokens_seen": 2048,
|
| 8 |
+
"wall_clock_seconds": 20539.00746917725,
|
| 9 |
"battery": {
|
| 10 |
"tier": "public",
|
| 11 |
"groups": {
|
|
|
|
| 13 |
"module": "g1_intrinsic",
|
| 14 |
"status": "ok",
|
| 15 |
"metrics": {
|
| 16 |
+
"g1.bpb.val": 3.7180674450035034,
|
| 17 |
+
"g1.bpb.fresh": 4.490946593024322,
|
| 18 |
+
"g1.bpb.key_token": 5.835137702656671,
|
| 19 |
+
"g1.posloss.p0_128": 3.981469353984971,
|
| 20 |
+
"g1.bpb.domain.code": 3.048406180661858,
|
| 21 |
+
"g1.bpb.domain.math": 4.08552483348228,
|
| 22 |
+
"g1.bpb.domain.news": 5.367073807343638,
|
| 23 |
+
"g1.bpb.multidomain": 4.325325867950423,
|
| 24 |
+
"g1.bpb.domain.prose": 4.800298650313917,
|
| 25 |
+
"g1.posloss.p128_256": 3.6657491348531672,
|
| 26 |
+
"g1.posloss.p256_384": 3.6666124634651536,
|
| 27 |
+
"g1.posloss.p384_512": 3.684105031419292,
|
| 28 |
+
"g1.posloss.p512_end": 3.631590617330868,
|
| 29 |
+
"g1.bits_per_byte.val": 0.9333457081310936,
|
| 30 |
+
"g1.bits_per_byte.fresh": 1.2095837878739255,
|
| 31 |
"g1.assets.domains_present": 4.0,
|
| 32 |
+
"g1.bits_per_byte.key_token": 0.13152751503557092,
|
| 33 |
+
"g1.bits_per_byte.domain.code": 1.5197987035964795,
|
| 34 |
+
"g1.bits_per_byte.domain.math": 1.451242832264349,
|
| 35 |
+
"g1.bits_per_byte.domain.news": 1.4909604377215282,
|
| 36 |
+
"g1.bits_per_byte.multidomain": 1.433540428766053,
|
| 37 |
+
"g1.bits_per_byte.domain.prose": 1.2721597414818553
|
| 38 |
}
|
| 39 |
},
|
| 40 |
"g2": {
|
| 41 |
"module": "g2_downstream",
|
| 42 |
"status": "ok",
|
| 43 |
"metrics": {
|
| 44 |
+
"g2.core.mean_nll": 4.128923485933247,
|
| 45 |
+
"g2.piqa.acc_norm": 0.63,
|
| 46 |
+
"g2.boolq.acc_norm": 0.63,
|
| 47 |
+
"g2.lambada.acc_norm": 0.955,
|
| 48 |
+
"g2.arc_easy.acc_norm": 0.335,
|
| 49 |
+
"g2.core.mean_acc_norm": 0.504375,
|
| 50 |
+
"g2.hellaswag.acc_norm": 0.36,
|
| 51 |
+
"g2.openbookqa.acc_norm": 0.31,
|
| 52 |
+
"g2.winogrande.acc_norm": 0.52,
|
| 53 |
"g2.assets.tasks_present": 8.0,
|
| 54 |
+
"g2.arc_challenge.acc_norm": 0.295
|
| 55 |
}
|
| 56 |
},
|
| 57 |
"g3": {
|
| 58 |
"module": "g3_recall",
|
| 59 |
"status": "ok",
|
| 60 |
"metrics": {
|
| 61 |
+
"g3.copy.acc": 0.4444444444444445,
|
| 62 |
+
"g3.mqar.acc": 0.22916666666666663,
|
| 63 |
"g3.copy.g0.acc": 0.4166666666666667,
|
| 64 |
+
"g3.mqar.n4.acc": 0.375,
|
| 65 |
"g3.mqar.n8.acc": 0.25,
|
| 66 |
+
"g3.copy.g16.acc": 0.5,
|
| 67 |
+
"g3.copy.g64.acc": 0.4166666666666667,
|
| 68 |
"g3.mqar.n16.acc": 0.0625,
|
| 69 |
+
"g3.recall.mean_acc": 0.6684027777777778,
|
| 70 |
+
"g3.recall.mean_nll": 5.947218637065828,
|
| 71 |
"g3.passkey.base.acc": 1.0,
|
| 72 |
"g3.induction.base.acc": 1.0
|
| 73 |
}
|
|
|
|
| 76 |
"module": "g4_reasoning",
|
| 77 |
"status": "ok",
|
| 78 |
"metrics": {
|
| 79 |
+
"g4.kk.acc": 0.75,
|
| 80 |
+
"g4.s5.acc": 0.0,
|
| 81 |
+
"g4.mod.acc": 0.375,
|
| 82 |
+
"g4.bool.acc": 0.5,
|
| 83 |
+
"g4.dyck.acc": 0.638888888888889,
|
| 84 |
+
"g4.arith.acc": 0.3,
|
| 85 |
+
"g4.kk.n3.acc": 0.75,
|
| 86 |
+
"g4.proof.acc": 0.625,
|
| 87 |
+
"g4.s5.k5.acc": 0.0,
|
| 88 |
"g4.mod.id.acc": 0.25,
|
| 89 |
"g4.s5.k10.acc": 0.0,
|
| 90 |
+
"g4.dyck.k1.acc": 0.8333333333333334,
|
| 91 |
+
"g4.dyck.k2.acc": 0.75,
|
| 92 |
+
"g4.mod.ood.acc": 0.5,
|
| 93 |
+
"g4.arith.t1.acc": 0.75,
|
| 94 |
+
"g4.arith.t2.acc": 0.25,
|
| 95 |
"g4.arith.t3.acc": 0.0,
|
| 96 |
+
"g4.proof.d0.acc": 0.75,
|
| 97 |
+
"g4.proof.d1.acc": 0.5,
|
| 98 |
+
"g4.proof.d2.acc": 1.0,
|
| 99 |
"g4.proof.d3.acc": 0.25,
|
| 100 |
+
"g4.bool.base.acc": 0.5,
|
| 101 |
"g4.arith.noop.acc": 0.25,
|
| 102 |
+
"g4.mod.id_ood_gap": -0.25,
|
| 103 |
+
"g4.dyck.k2long.acc": 0.3333333333333333,
|
| 104 |
+
"g4.arith.extrap.acc": 0.25,
|
| 105 |
+
"g4.reasoning.mean_acc": 0.4555555555555556,
|
| 106 |
+
"g4.reasoning.mean_nll": 6.31392470209135
|
| 107 |
}
|
| 108 |
},
|
| 109 |
"g5": {
|
| 110 |
"module": "g5_longctx",
|
| 111 |
"status": "ok",
|
| 112 |
"metrics": {
|
| 113 |
+
"g5.lstar": 0.0,
|
| 114 |
+
"g5.retention": 3.428571428571429,
|
| 115 |
+
"g5.ruler.acc": 0.19525,
|
| 116 |
+
"g5.babilong.acc": 0.2,
|
| 117 |
"g5.helmet_rag.n": 20.0,
|
| 118 |
+
"g5.ruler.qa.acc": 0.25,
|
| 119 |
+
"g5.ruler.vt.acc": 0.12,
|
| 120 |
"g5.natural_mcq.n": 40.0,
|
| 121 |
"g5.ruler.qa.pack": 1.0,
|
| 122 |
+
"g5.helmet_rag.acc": 0.15,
|
| 123 |
+
"g5.mean.L4096.acc": 0.0875,
|
| 124 |
+
"g5.mean.L8192.acc": 0.3175,
|
| 125 |
"g5.natural.staged": 1.0,
|
| 126 |
+
"g5.ruler.mean_nll": 3.762060427080064,
|
| 127 |
+
"g5.mean.L16384.acc": 0.16999999999999998,
|
| 128 |
+
"g5.mean.L32768.acc": 0.175,
|
| 129 |
"g5.mean.L65536.acc": 0.3,
|
| 130 |
+
"g5.natural_mcq.acc": 0.325,
|
| 131 |
+
"g5.ruler.L4096.acc": 0.075,
|
| 132 |
+
"g5.ruler.L8192.acc": 0.335,
|
| 133 |
"g5.ruler.shot_rate": 0.8181818181818182,
|
| 134 |
+
"g5.babilong.qa1.acc": 0.0,
|
| 135 |
+
"g5.babilong.qa2.acc": 0.3333333333333333,
|
| 136 |
+
"g5.babilong.qa3.acc": 0.16666666666666666,
|
| 137 |
+
"g5.babilong.qa4.acc": 0.3333333333333333,
|
| 138 |
"g5.babilong.qa5.acc": 0.16666666666666666,
|
| 139 |
+
"g5.ruler.L16384.acc": 0.14,
|
| 140 |
+
"g5.ruler.L32768.acc": 0.175,
|
| 141 |
"g5.ruler.L65536.acc": 0.3,
|
| 142 |
+
"g5.ruler.mean_depth": 0.4692217355300894,
|
| 143 |
+
"g5.babilong.mean_nll": 10.280345492892796,
|
| 144 |
"g5.helmet_rag.rank_n": 20.0,
|
| 145 |
+
"g5.ruler.niah_mk.acc": 0.2,
|
| 146 |
"g5.ruler.niah_mq.acc": 0.09375,
|
| 147 |
"g5.ruler.niah_mv.acc": 0.3125,
|
| 148 |
+
"g5.babilong.L4096.acc": 0.1,
|
| 149 |
+
"g5.babilong.L8192.acc": 0.3,
|
| 150 |
+
"g5.ruler.qa.L4096.acc": 0.0,
|
| 151 |
+
"g5.ruler.qa.L8192.acc": 1.0,
|
| 152 |
+
"g5.ruler.vt.L4096.acc": 0.0,
|
| 153 |
+
"g5.ruler.vt.L8192.acc": 0.3,
|
| 154 |
+
"g5.babilong.L16384.acc": 0.2,
|
| 155 |
+
"g5.babilong.mean_depth": 0.5756925183491818,
|
| 156 |
"g5.babilong.mean_shots": 2.0,
|
| 157 |
+
"g5.helmet_rag.gold_nll": 4.511707195772065,
|
| 158 |
"g5.helmet_rag.rank_acc": 0.5,
|
| 159 |
+
"g5.ruler.L4096.len_err": 0.004150390625,
|
| 160 |
+
"g5.ruler.L8192.len_err": 0.002734375,
|
| 161 |
"g5.ruler.evidence_miss": 0.0,
|
| 162 |
"g5.ruler.qa.L16384.acc": 0.0,
|
| 163 |
"g5.ruler.qa.L32768.acc": 0.0,
|
| 164 |
+
"g5.ruler.vt.L16384.acc": 0.2,
|
| 165 |
+
"g5.ruler.vt.L32768.acc": 0.0,
|
| 166 |
"g5.ruler.vt.L65536.acc": 0.1,
|
| 167 |
"g5.babilong.filler_pack": 1.0,
|
| 168 |
+
"g5.helmet_rag.L8192.acc": 0.15,
|
| 169 |
+
"g5.natural_mcq.mean_nll": 3.679664521258111,
|
| 170 |
+
"g5.ruler.L16384.len_err": 0.00224609375,
|
| 171 |
"g5.ruler.L32768.len_err": 0.0,
|
| 172 |
"g5.ruler.L65536.len_err": 0.0,
|
| 173 |
+
"g5.natural_mcq.L8192.acc": 0.325,
|
| 174 |
"g5.babilong.L4096.len_err": 0.0,
|
| 175 |
"g5.babilong.L8192.len_err": 0.0,
|
| 176 |
"g5.babilong.evidence_miss": 0.0,
|
| 177 |
+
"g5.babilong.qa1.L4096.acc": 0.0,
|
| 178 |
"g5.babilong.qa1.L8192.acc": 0.0,
|
| 179 |
+
"g5.babilong.qa2.L4096.acc": 0.0,
|
| 180 |
+
"g5.babilong.qa2.L8192.acc": 0.5,
|
| 181 |
+
"g5.babilong.qa3.L4096.acc": 0.5,
|
| 182 |
"g5.babilong.qa3.L8192.acc": 0.0,
|
| 183 |
"g5.babilong.qa4.L4096.acc": 0.0,
|
| 184 |
+
"g5.babilong.qa4.L8192.acc": 0.5,
|
| 185 |
"g5.babilong.qa5.L4096.acc": 0.0,
|
| 186 |
+
"g5.babilong.qa5.L8192.acc": 0.5,
|
| 187 |
"g5.babilong.L16384.len_err": 0.0,
|
| 188 |
"g5.babilong.qa1.L16384.acc": 0.0,
|
| 189 |
+
"g5.babilong.qa2.L16384.acc": 0.5,
|
| 190 |
"g5.babilong.qa3.L16384.acc": 0.0,
|
| 191 |
+
"g5.babilong.qa4.L16384.acc": 0.5,
|
| 192 |
+
"g5.babilong.qa5.L16384.acc": 0.0,
|
| 193 |
+
"g5.ruler.niah_mk.L4096.acc": 0.0,
|
| 194 |
"g5.ruler.niah_mk.L8192.acc": 0.0,
|
| 195 |
+
"g5.ruler.niah_mq.L4096.acc": 0.125,
|
| 196 |
"g5.ruler.niah_mq.L8192.acc": 0.0,
|
| 197 |
+
"g5.ruler.niah_mv.L4096.acc": 0.25,
|
| 198 |
+
"g5.ruler.niah_mv.L8192.acc": 0.375,
|
| 199 |
+
"g5.ruler.niah_mk.L16384.acc": 0.0,
|
| 200 |
"g5.ruler.niah_mk.L32768.acc": 0.5,
|
| 201 |
"g5.ruler.niah_mk.L65536.acc": 0.5,
|
| 202 |
"g5.ruler.niah_mq.L16384.acc": 0.125,
|
| 203 |
+
"g5.ruler.niah_mq.L32768.acc": 0.125,
|
| 204 |
+
"g5.ruler.niah_mv.L16384.acc": 0.375,
|
| 205 |
+
"g5.ruler.niah_mv.L32768.acc": 0.25,
|
| 206 |
"g5.natural.pool_rows.helmet_rag": 96.0,
|
| 207 |
"g5.natural.pool_rows.natural_mcq": 64.0
|
| 208 |
}
|
|
|
|
| 219 |
"module": "g7_inference",
|
| 220 |
"status": "ok",
|
| 221 |
"metrics": {
|
| 222 |
+
"g7.vram.peak_gb": 3.81773056,
|
| 223 |
+
"g7.tpot.L1024.ms": 11.54466256593878,
|
| 224 |
+
"g7.tpot.L4096.ms": 11.588581441174028,
|
| 225 |
+
"g7.ttft.L1024.ms": 11.557281017303469,
|
| 226 |
+
"g7.ttft.L4096.ms": 11.51505101006478,
|
| 227 |
+
"g7.tpot.L16384.ms": 11.5575027793966,
|
| 228 |
+
"g7.tpot.L32768.ms": 11.551143341421266,
|
| 229 |
+
"g7.ttft.L16384.ms": 11.513719975482672,
|
| 230 |
+
"g7.ttft.L32768.ms": 11.49219903163612,
|
| 231 |
+
"g7.quant.w8a8.dbpb": 0.0037219625386475386,
|
| 232 |
+
"g7.quant.w4a16.dbpb": 0.22044160045714412,
|
| 233 |
+
"g7.energy.j_per_token": 0.0009267897161566004,
|
| 234 |
+
"g7.throughput.b1.toks": 90.11773760248344,
|
| 235 |
+
"g7.throughput.b32.toks": 151.57566520175138,
|
| 236 |
"g7.state.analytic_unavailable": 1.0,
|
| 237 |
"g7.state.bytes_per_token.measured": 8.0
|
| 238 |
}
|
|
|
|
| 241 |
"module": "g8_stability",
|
| 242 |
"status": "ok",
|
| 243 |
"metrics": {
|
| 244 |
+
"g8.mup.stub": 1.0,
|
| 245 |
"g8.spikes.count": 0.0,
|
| 246 |
+
"g8.mup.stability": 0.0,
|
| 247 |
"g8.spikes.per_1k_steps": 0.0,
|
|
|
|
| 248 |
"g8.divergence.probe_nan_frac": 0.0,
|
| 249 |
+
"g8.divergence.series_nan_frac": 0.0,
|
| 250 |
+
"g8.mup.stub_reason_width_knob_unsupported": 1.0
|
| 251 |
}
|
| 252 |
}
|
| 253 |
},
|
| 254 |
"metrics": {
|
| 255 |
+
"org.g5.lstar": 0.0,
|
| 256 |
"org.g2.obqa_acc": {
|
| 257 |
+
"value": 0.31,
|
| 258 |
"clusters": {
|
| 259 |
+
"g2/openbookqa": 0.31
|
| 260 |
}
|
| 261 |
},
|
| 262 |
"org.g2.piqa_acc": {
|
| 263 |
+
"value": 0.63,
|
| 264 |
"clusters": {
|
| 265 |
+
"g2/piqa": 0.63
|
| 266 |
}
|
| 267 |
},
|
| 268 |
"org.g3.mqar_acc": {
|
| 269 |
+
"value": 0.22916666666666663,
|
| 270 |
"clusters": {
|
| 271 |
+
"mqar/n4": 0.375,
|
| 272 |
"mqar/n8": 0.25,
|
| 273 |
"mqar/n16": 0.0625
|
| 274 |
}
|
| 275 |
},
|
| 276 |
"org.g4.dyck_acc": {
|
| 277 |
+
"value": 0.638888888888889,
|
| 278 |
"clusters": {
|
| 279 |
+
"dyck/k1/len10": 0.8333333333333334,
|
| 280 |
+
"dyck/k2/len10": 0.75,
|
| 281 |
+
"dyck/k2/len28": 0.3333333333333333
|
| 282 |
}
|
| 283 |
},
|
| 284 |
"org.g2.boolq_acc": {
|
| 285 |
+
"value": 0.63,
|
| 286 |
"clusters": {
|
| 287 |
+
"g2/boolq": 0.63
|
| 288 |
}
|
| 289 |
},
|
| 290 |
"org.g5.ruler_acc": {
|
| 291 |
+
"value": 0.19525,
|
| 292 |
"clusters": {
|
| 293 |
+
"qa@4096": 0.0,
|
| 294 |
+
"qa@8192": 1.0,
|
| 295 |
+
"vt@4096": 0.0,
|
| 296 |
+
"vt@8192": 0.30000000000000004,
|
| 297 |
"qa@16384": 0.0,
|
| 298 |
"qa@32768": 0.0,
|
| 299 |
+
"vt@16384": 0.2,
|
| 300 |
+
"vt@32768": 0.0,
|
| 301 |
"vt@65536": 0.1,
|
| 302 |
+
"niah_mk@4096": 0.0,
|
| 303 |
"niah_mk@8192": 0.0,
|
| 304 |
+
"niah_mq@4096": 0.125,
|
| 305 |
"niah_mq@8192": 0.0,
|
| 306 |
+
"niah_mv@4096": 0.25,
|
| 307 |
+
"niah_mv@8192": 0.375,
|
| 308 |
+
"niah_mk@16384": 0.0,
|
| 309 |
"niah_mk@32768": 0.5,
|
| 310 |
"niah_mk@65536": 0.5,
|
| 311 |
"niah_mq@16384": 0.125,
|
| 312 |
+
"niah_mq@32768": 0.125,
|
| 313 |
+
"niah_mv@16384": 0.375,
|
| 314 |
+
"niah_mv@32768": 0.25
|
| 315 |
}
|
| 316 |
},
|
| 317 |
"org.g2.lambada_acc": {
|
| 318 |
+
"value": 0.955,
|
| 319 |
"clusters": {
|
| 320 |
+
"g2/lambada": 0.955
|
| 321 |
}
|
| 322 |
},
|
| 323 |
"org.g3.copying_acc": {
|
| 324 |
+
"value": 0.4444444444444445,
|
| 325 |
"clusters": {
|
| 326 |
"copy/len16/gap0": 0.4166666666666667,
|
| 327 |
+
"copy/len16/gap16": 0.5,
|
| 328 |
+
"copy/len16/gap64": 0.4166666666666667
|
| 329 |
}
|
| 330 |
},
|
| 331 |
"org.g3.passkey_acc": {
|
|
|
|
| 335 |
}
|
| 336 |
},
|
| 337 |
"org.g4.modular_acc": {
|
| 338 |
+
"value": 0.375,
|
| 339 |
"clusters": {
|
| 340 |
"mod/p97/id": 0.25,
|
| 341 |
+
"mod/p97/ood": 0.5
|
| 342 |
}
|
| 343 |
},
|
| 344 |
+
"org.g7.tpot_ms_32k": 11.551143341421266,
|
| 345 |
"org.g7.ttft_ms_32k": {
|
| 346 |
+
"value": 11.49219903163612,
|
| 347 |
"clusters": {
|
| 348 |
+
"L32768": 11.49219903163612
|
| 349 |
}
|
| 350 |
},
|
| 351 |
"org.g2.arc_easy_acc": {
|
| 352 |
+
"value": 0.335,
|
| 353 |
"clusters": {
|
| 354 |
+
"g2/arc_easy": 0.335
|
| 355 |
}
|
| 356 |
},
|
| 357 |
"org.g5.babilong_acc": {
|
| 358 |
+
"value": 0.2,
|
| 359 |
"clusters": {
|
| 360 |
+
"qa1@4096": 0.0,
|
| 361 |
"qa1@8192": 0.0,
|
| 362 |
+
"qa2@4096": 0.0,
|
| 363 |
+
"qa2@8192": 0.5,
|
| 364 |
+
"qa3@4096": 0.5,
|
| 365 |
"qa3@8192": 0.0,
|
| 366 |
"qa4@4096": 0.0,
|
| 367 |
+
"qa4@8192": 0.5,
|
| 368 |
"qa5@4096": 0.0,
|
| 369 |
+
"qa5@8192": 0.5,
|
| 370 |
"qa1@16384": 0.0,
|
| 371 |
+
"qa2@16384": 0.5,
|
| 372 |
"qa3@16384": 0.0,
|
| 373 |
+
"qa4@16384": 0.5,
|
| 374 |
+
"qa5@16384": 0.0
|
| 375 |
}
|
| 376 |
},
|
| 377 |
"org.g2.hellaswag_acc": {
|
| 378 |
+
"value": 0.36,
|
| 379 |
"clusters": {
|
| 380 |
+
"g2/hellaswag": 0.36
|
| 381 |
}
|
| 382 |
},
|
| 383 |
"org.g3.induction_acc": {
|
|
|
|
| 387 |
}
|
| 388 |
},
|
| 389 |
"org.g2.winogrande_acc": {
|
| 390 |
+
"value": 0.52,
|
| 391 |
"clusters": {
|
| 392 |
+
"g2/winogrande": 0.52
|
| 393 |
}
|
| 394 |
},
|
| 395 |
"org.g4.arithmetic_acc": {
|
| 396 |
+
"value": 0.3,
|
| 397 |
"clusters": {
|
| 398 |
+
"arith/t1": 0.75,
|
| 399 |
+
"arith/t2": 0.25,
|
| 400 |
"arith/t3": 0.0,
|
| 401 |
"arith/t2/noop": 0.25,
|
| 402 |
+
"arith/t2/extrap": 0.25
|
| 403 |
}
|
| 404 |
},
|
| 405 |
"org.g5.helmet_rag_acc": {
|
| 406 |
+
"value": 0.15,
|
| 407 |
"clusters": {
|
| 408 |
"helmet_rag@nq": 0.0,
|
| 409 |
"helmet_rag@popqa": 0.0,
|
| 410 |
+
"helmet_rag@hotpotqa": 0.3333333333333333,
|
| 411 |
+
"helmet_rag@triviaqa": 0.4
|
| 412 |
}
|
| 413 |
},
|
| 414 |
"org.g4.proofwriter_acc": {
|
| 415 |
+
"value": 0.625,
|
| 416 |
"clusters": {
|
| 417 |
+
"proof/d0/neg": 0.0,
|
| 418 |
"proof/d0/pos": 1.0,
|
| 419 |
+
"proof/d1/neg": 0.0,
|
| 420 |
"proof/d1/pos": 1.0,
|
|
|
|
| 421 |
"proof/d2/pos": 1.0,
|
| 422 |
"proof/d3/neg": 0.0,
|
| 423 |
"proof/d3/pos": 1.0
|
| 424 |
}
|
| 425 |
},
|
| 426 |
"org.g5.natural_mcq_acc": {
|
| 427 |
+
"value": 0.325,
|
| 428 |
"clusters": {
|
| 429 |
+
"natural_mcq@Multi-Document QA": 0.3,
|
| 430 |
+
"natural_mcq@Single-Document QA": 0.4375,
|
| 431 |
+
"natural_mcq@Long In-context Learning": 0.5,
|
| 432 |
+
"natural_mcq@Code Repository Understanding": 0.14285714285714285,
|
| 433 |
+
"natural_mcq@Long-dialogue History Understanding": 0.2
|
| 434 |
}
|
| 435 |
},
|
| 436 |
+
"org.g7.joules_per_token": 0.0009267897161566004,
|
| 437 |
"org.g8.loss_spike_score": 1.0,
|
| 438 |
+
"org.g8.mup_lr_stability": 0.0,
|
| 439 |
"org.g2.arc_challenge_acc": {
|
| 440 |
+
"value": 0.295,
|
| 441 |
"clusters": {
|
| 442 |
+
"g2/arc_challenge": 0.295
|
| 443 |
}
|
| 444 |
},
|
| 445 |
"org.g4.boolean_logic_acc": {
|
| 446 |
+
"value": 0.5,
|
| 447 |
"clusters": {
|
| 448 |
+
"bool/d2": 0.5
|
| 449 |
}
|
| 450 |
},
|
| 451 |
"org.g7.throughput_toks_s": {
|
| 452 |
+
"value": 151.57566520175138,
|
| 453 |
"clusters": {
|
| 454 |
+
"b32": 151.57566520175138
|
| 455 |
}
|
| 456 |
},
|
| 457 |
"org.g1.bits_per_byte_code": {
|
| 458 |
+
"value": 1.5197987035964795,
|
| 459 |
"clusters": {
|
| 460 |
+
"domain/code": 1.5197987035964795
|
| 461 |
}
|
| 462 |
},
|
| 463 |
"org.g1.bits_per_byte_math": {
|
| 464 |
+
"value": 1.451242832264349,
|
| 465 |
"clusters": {
|
| 466 |
+
"domain/math": 1.451242832264349
|
| 467 |
}
|
| 468 |
},
|
| 469 |
"org.g4.knights_knaves_acc": {
|
| 470 |
+
"value": 0.75,
|
| 471 |
"clusters": {
|
| 472 |
+
"kk/n3": 0.75
|
| 473 |
}
|
| 474 |
},
|
| 475 |
"org.g1.bits_per_byte_prose": {
|
| 476 |
+
"value": 1.2721597414818553,
|
| 477 |
"clusters": {
|
| 478 |
+
"domain/prose": 1.2721597414818553
|
| 479 |
}
|
| 480 |
},
|
| 481 |
+
"org.g1.bits_per_byte_key_token": 0.13152751503557092,
|
| 482 |
"org.g1.bits_per_byte_fresh_crawl": {
|
| 483 |
+
"value": 1.2095837878739255,
|
| 484 |
"clusters": {
|
| 485 |
+
"fresh": 1.2095837878739255
|
| 486 |
}
|
| 487 |
},
|
| 488 |
"org.g7.state_bytes_per_token_32k": 8.0
|
|
|
|
| 492 |
"group": "g4",
|
| 493 |
"metric": "org.g4.arithmetic_acc",
|
| 494 |
"mirror": {
|
| 495 |
+
"value": 0.0,
|
| 496 |
"clusters": {
|
| 497 |
"arith#0": 0.0,
|
| 498 |
"arith#1": 0.0,
|
| 499 |
+
"arith#2": 0.0,
|
| 500 |
"arith#3": 0.0
|
| 501 |
}
|
| 502 |
},
|
|
|
|
| 514 |
"group": "g4",
|
| 515 |
"metric": "org.g4.boolean_logic_acc",
|
| 516 |
"mirror": {
|
| 517 |
+
"value": 0.75,
|
| 518 |
"clusters": {
|
| 519 |
+
"boolean_expr#0": 1.0,
|
| 520 |
+
"boolean_expr#1": 0.0,
|
| 521 |
"boolean_expr#2": 1.0,
|
| 522 |
+
"boolean_expr#3": 1.0
|
| 523 |
}
|
| 524 |
},
|
| 525 |
"public": {
|
|
|
|
| 536 |
"group": "g4",
|
| 537 |
"metric": "org.g4.dyck_acc",
|
| 538 |
"mirror": {
|
| 539 |
+
"value": 0.5,
|
| 540 |
"clusters": {
|
| 541 |
+
"dyck#0": 0.6666666666666666,
|
| 542 |
+
"dyck#1": 0.3333333333333333,
|
| 543 |
"dyck#2": 0.3333333333333333,
|
| 544 |
+
"dyck#3": 0.6666666666666666
|
| 545 |
}
|
| 546 |
},
|
| 547 |
"public": {
|
| 548 |
+
"value": 0.5833333333333333,
|
| 549 |
"clusters": {
|
| 550 |
+
"dyck#0": 0.3333333333333333,
|
| 551 |
"dyck#1": 0.6666666666666666,
|
| 552 |
"dyck#2": 0.6666666666666666,
|
| 553 |
"dyck#3": 0.6666666666666666
|
|
|
|
| 558 |
"group": "g4",
|
| 559 |
"metric": "org.g4.modular_acc",
|
| 560 |
"mirror": {
|
| 561 |
+
"value": 0.25,
|
| 562 |
"clusters": {
|
| 563 |
"modular#0": 0.0,
|
| 564 |
"modular#1": 0.0,
|
| 565 |
"modular#2": 0.0,
|
| 566 |
+
"modular#3": 1.0
|
| 567 |
}
|
| 568 |
},
|
| 569 |
"public": {
|
| 570 |
+
"value": 0.5,
|
| 571 |
"clusters": {
|
| 572 |
+
"modular#0": 1.0,
|
| 573 |
+
"modular#1": 0.0,
|
| 574 |
+
"modular#2": 0.0,
|
| 575 |
"modular#3": 1.0
|
| 576 |
}
|
| 577 |
}
|
|
|
|
| 580 |
"group": "g4",
|
| 581 |
"metric": "org.g4.knights_knaves_acc",
|
| 582 |
"mirror": {
|
| 583 |
+
"value": 0.75,
|
| 584 |
"clusters": {
|
| 585 |
+
"knights_knaves#0": 1.0,
|
| 586 |
+
"knights_knaves#1": 1.0,
|
| 587 |
+
"knights_knaves#2": 0.0,
|
| 588 |
+
"knights_knaves#3": 1.0
|
| 589 |
}
|
| 590 |
},
|
| 591 |
"public": {
|
|
|
|
| 624 |
"group": "g2",
|
| 625 |
"metric": "org.g2.lambada_acc",
|
| 626 |
"mirror": {
|
| 627 |
+
"value": 0.75,
|
| 628 |
"clusters": {
|
| 629 |
+
"lambada#0": 0.0,
|
| 630 |
"lambada#1": 1.0,
|
| 631 |
"lambada#2": 1.0,
|
| 632 |
"lambada#3": 1.0
|
|
|
|
| 655 |
}
|
| 656 |
},
|
| 657 |
"public": {
|
| 658 |
+
"value": 1.0,
|
| 659 |
"clusters": {
|
| 660 |
"hellaswag#0": 1.0,
|
| 661 |
+
"hellaswag#1": 1.0,
|
| 662 |
+
"hellaswag#2": 1.0,
|
| 663 |
"hellaswag#3": 1.0
|
| 664 |
}
|
| 665 |
}
|
|
|
|
| 668 |
"group": "g2",
|
| 669 |
"metric": "org.g2.piqa_acc",
|
| 670 |
"mirror": {
|
| 671 |
+
"value": 0.5,
|
| 672 |
"clusters": {
|
| 673 |
"piqa#0": 1.0,
|
| 674 |
"piqa#1": 0.0,
|
| 675 |
"piqa#2": 0.0,
|
| 676 |
+
"piqa#3": 1.0
|
| 677 |
}
|
| 678 |
},
|
| 679 |
"public": {
|
| 680 |
+
"value": 0.75,
|
| 681 |
"clusters": {
|
| 682 |
+
"piqa#0": 0.0,
|
| 683 |
"piqa#1": 1.0,
|
| 684 |
"piqa#2": 1.0,
|
| 685 |
"piqa#3": 1.0
|
|
|
|
| 690 |
"group": "g2",
|
| 691 |
"metric": "org.g2.arc_easy_acc",
|
| 692 |
"mirror": {
|
| 693 |
+
"value": 0.75,
|
| 694 |
"clusters": {
|
| 695 |
"arc_easy#0": 1.0,
|
| 696 |
"arc_easy#1": 1.0,
|
| 697 |
+
"arc_easy#2": 1.0,
|
| 698 |
"arc_easy#3": 0.0
|
| 699 |
}
|
| 700 |
},
|
|
|
|
| 712 |
"group": "g2",
|
| 713 |
"metric": "org.g2.arc_challenge_acc",
|
| 714 |
"mirror": {
|
| 715 |
+
"value": 0.75,
|
| 716 |
"clusters": {
|
| 717 |
+
"arc_challenge#0": 1.0,
|
| 718 |
"arc_challenge#1": 1.0,
|
| 719 |
"arc_challenge#2": 0.0,
|
| 720 |
"arc_challenge#3": 1.0
|
|
|
|
| 778 |
"group": "g2",
|
| 779 |
"metric": "org.g2.obqa_acc",
|
| 780 |
"mirror": {
|
| 781 |
+
"value": 0.5,
|
| 782 |
"clusters": {
|
| 783 |
"openbookqa#0": 1.0,
|
| 784 |
"openbookqa#1": 0.0,
|
| 785 |
"openbookqa#2": 0.0,
|
| 786 |
+
"openbookqa#3": 1.0
|
| 787 |
}
|
| 788 |
},
|
| 789 |
"public": {
|
| 790 |
+
"value": 0.75,
|
| 791 |
"clusters": {
|
| 792 |
+
"openbookqa#0": 1.0,
|
| 793 |
"openbookqa#1": 1.0,
|
| 794 |
"openbookqa#2": 1.0,
|
| 795 |
"openbookqa#3": 0.0
|
|
|
|
| 800 |
"group": "g5",
|
| 801 |
"metric": "org.g5.natural_mcq_acc",
|
| 802 |
"mirror": {
|
| 803 |
+
"value": 0.5,
|
| 804 |
"clusters": {
|
| 805 |
+
"Multi-Document QA": 1.0,
|
| 806 |
"Single-Document QA": 0.0,
|
| 807 |
+
"Long In-context Learning": 0.0,
|
| 808 |
+
"Long-dialogue History Understanding": 1.0
|
| 809 |
}
|
| 810 |
},
|
| 811 |
"public": {
|
| 812 |
+
"value": 0.25,
|
| 813 |
"clusters": {
|
| 814 |
"Multi-Document QA": 0.0,
|
| 815 |
+
"Single-Document QA": 0.0,
|
| 816 |
+
"Long In-context Learning": 1.0
|
| 817 |
}
|
| 818 |
}
|
| 819 |
},
|
|
|
|
| 821 |
"group": "g5",
|
| 822 |
"metric": "org.g5.helmet_rag_acc",
|
| 823 |
"mirror": {
|
| 824 |
+
"value": 0.0,
|
| 825 |
"clusters": {
|
| 826 |
+
"popqa": 0.0,
|
| 827 |
+
"hotpotqa": 0.0
|
|
|
|
| 828 |
}
|
| 829 |
},
|
| 830 |
"public": {
|
| 831 |
+
"value": 0.5,
|
| 832 |
"clusters": {
|
| 833 |
+
"nq": 0.0,
|
| 834 |
+
"popqa": 0.5,
|
| 835 |
+
"triviaqa": 1.0
|
| 836 |
}
|
| 837 |
}
|
| 838 |
}
|
README.md
CHANGED
|
@@ -27,26 +27,26 @@ Prism-protocol **public** eval pack (1×RTX 5090). Accuracy: **↑ higher better
|
|
| 27 |
|
| 28 |
| Metric | This model | GPT-2 | GPT-2 Large | vs GPT-2 | vs GPT-2 Large |
|
| 29 |
|---|---:|---:|---:|:---|:---|
|
| 30 |
-
| Val BPB (G1) | 3.
|
| 31 |
-
| HellaSwag | 0.
|
| 32 |
-
| ARC-Easy | 0.
|
| 33 |
-
| ARC-Challenge | 0.
|
| 34 |
-
| PIQA | 0.
|
| 35 |
-
| WinoGrande | 0.
|
| 36 |
-
| BoolQ | 0.
|
| 37 |
-
| LAMBADA | 0.
|
| 38 |
-
| OpenBookQA | 0.
|
| 39 |
|
| 40 |
### Compute notes
|
| 41 |
|
| 42 |
| | This model | GPT-2 | GPT-2 Large |
|
| 43 |
|---|---|---|---|
|
| 44 |
-
| Parameters |
|
| 45 |
-
| Size vs Large |
|
| 46 |
-
| Train tokens |
|
| 47 |
-
| Wall clock |
|
| 48 |
-
| Sustained train throughput |
|
| 49 |
-
| GPU (harness) | `GPU 0: NVIDIA GeForce RTX 5090 (UUID: GPU-
|
| 50 |
|
| 51 |
Throughput ≈ `6 × N × D / wall` TFLOPS (dense transformer train FLOPs rule of thumb).
|
| 52 |
|
|
@@ -54,10 +54,10 @@ Throughput ≈ `6 × N × D / wall` TFLOPS (dense transformer train FLOPs rule o
|
|
| 54 |
|
| 55 |
| field | value |
|
| 56 |
|---|---|
|
| 57 |
-
| arch_id | `
|
| 58 |
-
| bpb | `3.
|
| 59 |
-
| submission | `
|
| 60 |
-
| owner_hotkey | `
|
| 61 |
| hub repo | `BaseIntelligence/top-prism-architecture` |
|
| 62 |
|
| 63 |
## Load (trust_remote_code)
|
|
|
|
| 27 |
|
| 28 |
| Metric | This model | GPT-2 | GPT-2 Large | vs GPT-2 | vs GPT-2 Large |
|
| 29 |
|---|---:|---:|---:|:---|:---|
|
| 30 |
+
| Val BPB (G1) | 3.7181 | 4.7595 | 4.1639 | ↓ -1.0414 ✓ better | ↓ -0.4458 ✓ better |
|
| 31 |
+
| HellaSwag | 0.360 | 0.355 | 0.395 | ↑ +0.005 ✓ better | ↓ -0.035 worse |
|
| 32 |
+
| ARC-Easy | 0.335 | 0.245 | 0.280 | ↑ +0.090 ✓ better | ↑ +0.055 ✓ better |
|
| 33 |
+
| ARC-Challenge | 0.295 | 0.240 | 0.280 | ↑ +0.055 ✓ better | ↑ +0.015 ✓ better |
|
| 34 |
+
| PIQA | 0.630 | 0.585 | 0.690 | ↑ +0.045 ✓ better | ↓ -0.060 worse |
|
| 35 |
+
| WinoGrande | 0.520 | 0.515 | 0.545 | ↑ +0.005 ✓ better | ↓ -0.025 worse |
|
| 36 |
+
| BoolQ | 0.630 | 0.575 | 0.640 | ↑ +0.055 ✓ better | ↓ -0.010 worse |
|
| 37 |
+
| LAMBADA | 0.955 | 0.970 | 0.985 | ↓ -0.015 worse | ↓ -0.030 worse |
|
| 38 |
+
| OpenBookQA | 0.310 | 0.320 | 0.335 | ↓ -0.010 worse | ↓ -0.025 worse |
|
| 39 |
|
| 40 |
### Compute notes
|
| 41 |
|
| 42 |
| | This model | GPT-2 | GPT-2 Large |
|
| 43 |
|---|---|---|---|
|
| 44 |
+
| Parameters | 107.0M | 124M | 774M |
|
| 45 |
+
| Size vs Large | 7.23× vs GPT-2 Large (774M) | 6.22× | 1× |
|
| 46 |
+
| Train tokens | — | _(eval-only)_ | _(eval-only)_ |
|
| 47 |
+
| Wall clock | 20539s | _(eval-only)_ | _(eval-only)_ |
|
| 48 |
+
| Sustained train throughput | — | n/a | n/a |
|
| 49 |
+
| GPU (harness) | `GPU 0: NVIDIA GeForce RTX 5090 (UUID: GPU-e31dbb89-6a01-a2fb-2684-3b6f0efb3f28)` | 1×RTX 5090 (eval) | 1×RTX 5090 (eval) |
|
| 50 |
|
| 51 |
Throughput ≈ `6 × N × D / wall` TFLOPS (dense transformer train FLOPs rule of thumb).
|
| 52 |
|
|
|
|
| 54 |
|
| 55 |
| field | value |
|
| 56 |
|---|---|
|
| 57 |
+
| arch_id | `arch_f17d92b32a8c79f7` |
|
| 58 |
+
| bpb | `3.718067` |
|
| 59 |
+
| submission | `7b8658aedfdb158782567d09e26a9e819c578ff20c4db1d940e12de77cd9d6d2` |
|
| 60 |
+
| owner_hotkey | `462c4a7dfe30…` |
|
| 61 |
| hub repo | `BaseIntelligence/top-prism-architecture` |
|
| 62 |
|
| 63 |
## Load (trust_remote_code)
|
architecture.py
CHANGED
|
@@ -1,702 +1,621 @@
|
|
| 1 |
-
# prism-automodel-copy patch_sha256=
|
| 2 |
-
# --- nemo_automodel/
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
model = build_model(ctx)
|
| 11 |
-
metrics = train(model, ctx)
|
| 12 |
-
|
| 13 |
-
and then scores the in-memory model. Nothing here imports the surrounding
|
| 14 |
-
framework: the pod provides torch + numpy (base image) and pyarrow +
|
| 15 |
-
transformers (harness bootstrap), and that is the entire dependency set.
|
| 16 |
-
|
| 17 |
-
RoPEDecoderLM (RoPE rotary position embeddings / RMSNorm / QK-norm /
|
| 18 |
-
SwiGLU feed forward / multi-head attention / weight tying / tied
|
| 19 |
-
embeddings / zero-init residual projections, causal SDPA) at vocab 8192,
|
| 20 |
-
d_model 1024, 15 layers, 8 heads, SwiGLU hidden 2752, context 1024; packed
|
| 21 |
-
uint16 stream built on-pod from the pinned shard with our 8k tokenizer;
|
| 22 |
-
196,608 tokens per optimizer step; Muon (Newton-Schulz orthogonalised
|
| 23 |
-
momentum) on hidden matrices + AdamW on embeddings and norms; warmup then
|
| 24 |
-
stable then cosine decay, keyed to whichever budget runs out first — wall
|
| 25 |
-
time or the step ceiling — so the tail completes in both directions.
|
| 26 |
-
|
| 27 |
-
Data hygiene: the frozen val cut (filtered rows 2048..2303 of the pinned
|
| 28 |
-
shard) is removed from the training texts, so the scored texts are never
|
| 29 |
-
trained on.
|
| 30 |
"""
|
| 31 |
|
| 32 |
-
import json
|
| 33 |
import math
|
| 34 |
import os
|
|
|
|
| 35 |
import time
|
| 36 |
|
| 37 |
-
|
|
|
|
| 38 |
import pyarrow.parquet as pq
|
| 39 |
import torch
|
| 40 |
import torch.nn as nn
|
| 41 |
import torch.nn.functional as F
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
# The harness supplies this module to the training process; keep a no-op
|
| 44 |
-
# stand-in for local dress rehearsals and use the real hooks whenever present.
|
| 45 |
try:
|
| 46 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
except ImportError:
|
| 48 |
-
class
|
| 49 |
@staticmethod
|
| 50 |
-
def report(**
|
| 51 |
return None
|
| 52 |
|
| 53 |
@staticmethod
|
| 54 |
def finish_evaluation():
|
| 55 |
return None
|
| 56 |
|
| 57 |
-
|
| 58 |
|
| 59 |
-
_HERE = os.path.dirname(os.path.abspath(__file__))
|
| 60 |
|
| 61 |
-
#
|
| 62 |
-
VOCAB = 8192
|
| 63 |
-
D_MODEL = 1024
|
| 64 |
-
N_LAYER = 15
|
| 65 |
-
N_HEAD = 8
|
| 66 |
-
FFN_HIDDEN = 2752
|
| 67 |
BLOCK = 1024
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
MAX_STEPS = 19000 # = STEP_CEILING: пусть связывает ВРЕМЯ, а не шаги.
|
| 76 |
-
#: r4/r5 стояли на 14000 и заканчивали за 4.12ч из доступных 5.0 (finish_reason
|
| 77 |
-
#: train_returned), отдавая 3175с и ~590M токенов. Прежний комментарий исходил из
|
| 78 |
-
#: 72k tok/s; под фактически даёт 185.7k, и потолок шагов срабатывал раньше стены.
|
| 79 |
-
#: _lr_mult берёт max(frac_time, frac_step), поэтому при высоком потолке затухание
|
| 80 |
-
#: ведёт время и доводится до конца в обе стороны.
|
| 81 |
-
MUON_REF_DIM = 768 # d_model, на котором подобран MUON_LR
|
| 82 |
-
MUON_WIDTH_FIX = False # см. Muon.step: делает шаг инвариантным к ширине
|
| 83 |
-
MUON_LR = 0.033
|
| 84 |
-
MUON_MOMENTUM = 0.95
|
| 85 |
-
NS_STEPS = 5
|
| 86 |
-
ADAM_LR = 0.003
|
| 87 |
-
ADAM_BETAS = (0.9, 0.95)
|
| 88 |
-
ADAM_WD = 0.0
|
| 89 |
-
WARMUP_STEPS = 250
|
| 90 |
-
DECAY_FRAC = 0.35 # final share of the wall budget, cosine to min
|
| 91 |
-
MIN_LR_FRAC = 0.0
|
| 92 |
-
DOCSTART_FRAC = 0.5
|
| 93 |
-
DATA_SEED = 1303
|
| 94 |
-
REPORT_EVERY = 25
|
| 95 |
-
STEP_CEILING = 19000 # hard stop below the recipe's 20000
|
| 96 |
-
VAL_LO, VAL_HI = 2048, 2304 # frozen val cut, removed from training texts
|
| 97 |
-
MIN_CHARS = 100 # harness text filter
|
| 98 |
-
TOKENS_CACHE = os.environ.get("PRISM_TOKENS_CACHE", "/tmp/prism_toks8k.npy")
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
def _log(msg):
|
| 102 |
-
print(f"[prism] {msg}", flush=True)
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
# ------------------------------- model -----------------------------------
|
| 106 |
-
def _rope_cache(head_dim, max_t, base, device, dtype):
|
| 107 |
-
inv = 1.0 / (base ** (torch.arange(0, head_dim, 2, device=device).float() / head_dim))
|
| 108 |
-
freqs = torch.outer(torch.arange(max_t, device=device).float(), inv)
|
| 109 |
-
return freqs.cos().to(dtype), freqs.sin().to(dtype)
|
| 110 |
|
| 111 |
|
| 112 |
-
def
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
return
|
| 120 |
|
| 121 |
|
| 122 |
class RMSNorm(nn.Module):
|
| 123 |
-
def __init__(self,
|
| 124 |
super().__init__()
|
|
|
|
| 125 |
self.eps = eps
|
| 126 |
-
self.weight = nn.Parameter(torch.ones(d))
|
| 127 |
|
| 128 |
def forward(self, x):
|
| 129 |
-
|
|
|
|
|
|
|
| 130 |
|
| 131 |
|
| 132 |
-
def
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
|
| 136 |
-
class
|
| 137 |
-
def __init__(self, d,
|
| 138 |
super().__init__()
|
| 139 |
-
self.
|
| 140 |
-
self.hd = d //
|
| 141 |
-
self.
|
| 142 |
-
self.
|
| 143 |
-
self.
|
| 144 |
-
self.
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
|
| 157 |
class SwiGLU(nn.Module):
|
| 158 |
-
def __init__(self, d, hidden):
|
| 159 |
super().__init__()
|
| 160 |
-
self.
|
| 161 |
-
self.
|
| 162 |
-
self.
|
| 163 |
|
| 164 |
def forward(self, x):
|
| 165 |
-
return self.
|
| 166 |
|
| 167 |
|
| 168 |
-
class
|
| 169 |
-
def __init__(self, d,
|
| 170 |
super().__init__()
|
| 171 |
self.n1 = RMSNorm(d)
|
| 172 |
-
self.
|
| 173 |
self.n2 = RMSNorm(d)
|
| 174 |
-
self.mlp = SwiGLU(d,
|
|
|
|
| 175 |
|
| 176 |
-
def forward(self, x, cos, sin):
|
| 177 |
-
|
| 178 |
-
|
|
|
|
| 179 |
|
| 180 |
|
| 181 |
-
class
|
| 182 |
-
def __init__(self, vocab
|
| 183 |
-
n_head=N_HEAD, ffn=FFN_HIDDEN, block=BLOCK, rope_base=ROPE_BASE):
|
| 184 |
super().__init__()
|
| 185 |
self.block = block
|
| 186 |
-
self.
|
| 187 |
-
|
| 188 |
-
self.
|
| 189 |
-
self.
|
| 190 |
-
self.
|
| 191 |
-
self.
|
| 192 |
-
self.head = nn.Linear(
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
self._mup_mult = math.sqrt(float(D_MODEL) / float(d_model))
|
| 199 |
-
self._mup_out = float(D_MODEL) / float(d_model)
|
| 200 |
self.apply(self._init)
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
|
|
|
|
|
|
| 204 |
|
| 205 |
def _init(self, m):
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
cands = []
|
| 240 |
-
if ctx:
|
| 241 |
-
for key in ("tokenizer_dir", "submission_tokenizer_dir"):
|
| 242 |
-
if ctx.get(key):
|
| 243 |
-
cands.append(str(ctx[key]))
|
| 244 |
-
envd = os.environ.get("PRISM_TOKENIZER_DIR")
|
| 245 |
-
if envd:
|
| 246 |
-
cands.append(envd)
|
| 247 |
-
cands += [
|
| 248 |
-
os.path.join(_HERE, "tok8k"), # vendored beside this file
|
| 249 |
-
os.path.join(_HERE, "..", "..", "..", "..", "tokenizer"), # applied-tree root
|
| 250 |
-
os.path.join(os.getcwd(), "submission", "tokenizer"),
|
| 251 |
-
"/tmp/prism_eval/submission/tokenizer",
|
| 252 |
-
]
|
| 253 |
-
for c in cands:
|
| 254 |
-
if c and os.path.isdir(c) and os.path.isfile(os.path.join(c, "tokenizer.json")):
|
| 255 |
-
return c
|
| 256 |
-
raise FileNotFoundError("8k tokenizer directory not found (looked in %s)" % cands)
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
def _load_tokenizer(ctx=None):
|
| 260 |
-
"""Load the shipped 8k tokenizer from local files only.
|
| 261 |
-
|
| 262 |
-
The harness resolves the submission tokenizer with
|
| 263 |
-
`AutoTokenizer.from_pretrained(dir, local_files_only=True)`, so the shipped
|
| 264 |
-
tokenizer_config.json declares `PreTrainedTokenizerFast` (a class the pod's
|
| 265 |
-
transformers knows). The direct-from-file path below is a belt-and-braces
|
| 266 |
-
fallback for the same tokenizer.json.
|
| 267 |
-
"""
|
| 268 |
-
tok = ctx.get("tokenizer") if ctx else None
|
| 269 |
if tok is not None:
|
| 270 |
return tok
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
|
| 311 |
|
| 312 |
-
def
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
t0 = time.time()
|
| 317 |
-
table = pq.read_table(parquet_path, columns=["text"])
|
| 318 |
-
texts = [t for t in table.column("text").to_pylist()
|
| 319 |
-
if isinstance(t, str) and len(t) >= MIN_CHARS]
|
| 320 |
-
n_all = len(texts)
|
| 321 |
-
texts = texts[:VAL_LO] + texts[VAL_HI:] # drop the frozen val cut
|
| 322 |
-
eos = tok.eos_token_id
|
| 323 |
-
if eos is None:
|
| 324 |
-
eos = VOCAB - 1
|
| 325 |
-
assert len(tok) <= 65535, "uint16 stream caps vocab at 65535"
|
| 326 |
-
_log(f"{n_all} texts -> {len(texts)} train texts (val cut removed); tokenizing")
|
| 327 |
-
parts = []
|
| 328 |
-
batch = 2048
|
| 329 |
-
for i in range(0, len(texts), batch):
|
| 330 |
-
enc = tok(texts[i:i + batch], add_special_tokens=False)["input_ids"]
|
| 331 |
-
for ids in enc:
|
| 332 |
-
parts.append(np.asarray(ids + [eos], dtype=np.uint16))
|
| 333 |
-
if (i // batch) % 50 == 0:
|
| 334 |
-
_log(f" tokenized {min(i + batch, len(texts))}/{len(texts)} ({time.time()-t0:.0f}s)")
|
| 335 |
-
stream = np.concatenate(parts)
|
| 336 |
-
_log(f"packed {len(stream)/1e6:.1f}M tokens in {time.time()-t0:.0f}s")
|
| 337 |
-
if TOKENS_CACHE:
|
| 338 |
try:
|
| 339 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 340 |
except OSError:
|
| 341 |
pass
|
| 342 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 343 |
|
| 344 |
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
"""Nesterov momentum + Newton-Schulz orthogonalisation for 2D weights."""
|
| 348 |
|
| 349 |
-
def __init__(self, params, lr=MUON_LR, momentum=MUON_MOMENTUM, ns_steps=NS_STEPS):
|
| 350 |
-
super().__init__(params, dict(lr=lr, momentum=momentum, ns_steps=ns_steps))
|
| 351 |
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 365 |
|
| 366 |
@torch.no_grad()
|
| 367 |
-
def step(self
|
| 368 |
-
for
|
| 369 |
-
lr, mom, ns =
|
| 370 |
-
for p in
|
| 371 |
if p.grad is None:
|
| 372 |
continue
|
| 373 |
st = self.state[p]
|
| 374 |
-
if "
|
| 375 |
-
st["
|
| 376 |
-
buf = st["
|
| 377 |
buf.mul_(mom).add_(p.grad)
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
# ------------------------------- entry -----------------------------------
|
| 412 |
-
#: Parameter ceiling for a width-scaled probe build. The harness G8 sweep
|
| 413 |
-
#: trains the wide variant with AdamW (four times the parameter bytes: weights,
|
| 414 |
-
#: grads, two moments) on one card, so a literal 4x width — sixteen times the
|
| 415 |
-
#: parameters — cannot be held. An OOM there is reported as `build_failed`,
|
| 416 |
-
#: which scores exactly the same zero as not supporting the knob at all.
|
| 417 |
-
G8_PROBE_PARAM_BUDGET = 480_000_000
|
| 418 |
-
#: Minimum parameter growth the harness demands of the wide build (it checks
|
| 419 |
-
#: `> 1.5x`); keep a margin so rounding never lands on the boundary.
|
| 420 |
-
G8_PROBE_MIN_GROWTH = 1.6
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
def _param_count(d_model, ffn, n_layer=None, vocab=None):
|
| 424 |
-
"""Parameters of RoPEDecoderLM at a given width, without building it."""
|
| 425 |
-
n_layer = N_LAYER if n_layer is None else n_layer
|
| 426 |
-
vocab = VOCAB if vocab is None else vocab
|
| 427 |
-
per_layer = 4 * d_model * d_model + 3 * d_model * ffn + 2 * d_model
|
| 428 |
-
return per_layer * n_layer + vocab * d_model + d_model
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
def _width_variant(mult):
|
| 432 |
-
"""muP width knob (`prism_width_multiplier`, documented for miners).
|
| 433 |
-
|
| 434 |
-
Head dimension stays fixed and d_model / SwiGLU hidden scale together, so
|
| 435 |
-
the wide build is the same architecture at a larger width — that is what
|
| 436 |
-
makes the harness LR-transfer comparison meaningful. The requested factor
|
| 437 |
-
is reduced only as far as the probe's own memory budget forces, and never
|
| 438 |
-
below the growth the harness asks for.
|
| 439 |
-
"""
|
| 440 |
-
if not mult or float(mult) <= 1.0:
|
| 441 |
-
return D_MODEL, FFN_HIDDEN, N_HEAD
|
| 442 |
-
head_dim = D_MODEL // N_HEAD
|
| 443 |
-
base = _param_count(D_MODEL, FFN_HIDDEN)
|
| 444 |
-
fallback = None
|
| 445 |
-
f = float(mult)
|
| 446 |
-
while f > 1.0:
|
| 447 |
-
d = max(head_dim, int(round(D_MODEL * f / head_dim)) * head_dim)
|
| 448 |
-
ffn = max(64, int(round(FFN_HIDDEN * f / 64)) * 64)
|
| 449 |
-
n = _param_count(d, ffn)
|
| 450 |
-
if n > G8_PROBE_MIN_GROWTH * base:
|
| 451 |
-
if n <= G8_PROBE_PARAM_BUDGET:
|
| 452 |
-
return d, ffn, d // head_dim
|
| 453 |
-
fallback = (d, ffn, d // head_dim)
|
| 454 |
-
f -= 0.05
|
| 455 |
-
return fallback or (D_MODEL * 2, FFN_HIDDEN * 2, N_HEAD * 2)
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
def build_model(ctx=None):
|
| 459 |
-
ctx = ctx or {}
|
| 460 |
-
torch.manual_seed(int(ctx.get("seed", MODEL_SEED) or MODEL_SEED))
|
| 461 |
-
vocab = int(ctx.get("vocab_size") or VOCAB)
|
| 462 |
-
# Fail loudly and immediately if the harness did not resolve the shipped
|
| 463 |
-
# vocabulary: the frozen-val score is computed with the harness tokenizer,
|
| 464 |
-
# so a mismatch here cannot be recovered later in the run — better to stop
|
| 465 |
-
# at build than to spend the whole wall budget on an unscoreable model.
|
| 466 |
-
if vocab != VOCAB:
|
| 467 |
-
raise RuntimeError(
|
| 468 |
-
f"tokenizer mismatch: harness resolved vocab {vocab}, this entry ships "
|
| 469 |
-
f"{VOCAB}; expected the submitted files under submission/tokenizer/"
|
| 470 |
-
)
|
| 471 |
-
mult = ctx.get("prism_width_multiplier")
|
| 472 |
-
d_model, ffn, n_head = _width_variant(mult)
|
| 473 |
-
# Значения по умолчанию у RoPEDecoderLM связаны в момент определения класса,
|
| 474 |
-
# поэтому все размеры передаём явно — иначе стендовые переопределения
|
| 475 |
-
# N_LAYER / BLOCK молча игнорируются и меряется не тот конфиг.
|
| 476 |
-
model = RoPEDecoderLM(vocab=vocab, d_model=d_model, n_layer=N_LAYER,
|
| 477 |
-
n_head=n_head, ffn=ffn, block=BLOCK, rope_base=ROPE_BASE)
|
| 478 |
-
n = sum(p.numel() for p in model.parameters())
|
| 479 |
-
if d_model != D_MODEL:
|
| 480 |
-
_log(f"width x{float(mult):g} requested -> d_model {d_model}, ffn {ffn}, "
|
| 481 |
-
f"heads {n_head}: {n/1e6:.1f}M params (vocab {vocab})")
|
| 482 |
-
else:
|
| 483 |
-
_log(f"model built: {n/1e6:.1f}M params (vocab {vocab})")
|
| 484 |
-
return model
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
def train(model, ctx=None):
|
| 488 |
-
ctx = ctx or {}
|
| 489 |
-
device = ctx.get("device") or ("cuda" if torch.cuda.is_available() else "cpu")
|
| 490 |
-
torch.manual_seed(int(ctx.get("seed", MODEL_SEED) or MODEL_SEED))
|
| 491 |
-
guard = ctx.get("guard", lambda: None)
|
| 492 |
-
t_start = time.time()
|
| 493 |
-
|
| 494 |
-
hours = float(os.environ.get("PRISM_HOURS", 0.0)) or float(ctx.get("train_hours_cap", 6.0))
|
| 495 |
-
# Reserve, inside the pod lifetime, for everything that runs after train()
|
| 496 |
-
# returns: the harness checkpoint write, the rebuilt-model battery and the
|
| 497 |
-
# frozen-val score, plus the intermediate probes the harness telemetry hook
|
| 498 |
-
# runs while training. One hour, not thirty minutes: the post-train phase is
|
| 499 |
-
# a full second pass over the model, not just the 256-text val loop.
|
| 500 |
-
safety_min = 60.0 if hours >= 3.0 else 8.0
|
| 501 |
-
budget_s = hours * 3600.0 - safety_min * 60.0
|
| 502 |
-
step_cap = int(os.environ.get("PRISM_MAX_STEPS", MAX_STEPS))
|
| 503 |
-
_log(f"wall budget {budget_s/3600.0:.2f}h (cap {hours}h - {safety_min:.0f}m safety), "
|
| 504 |
-
f"step cap {step_cap}")
|
| 505 |
-
|
| 506 |
-
# Pod lifetime kill -> hand the in-memory model to scoring instead of dying
|
| 507 |
-
# scoreless. finish_evaluation raises by design, so it ends the run.
|
| 508 |
-
try:
|
| 509 |
-
import signal
|
| 510 |
-
|
| 511 |
-
def _salvage(_sig, _frm):
|
| 512 |
-
_log("SIGTERM received -> handing over for scoring")
|
| 513 |
-
_TLM.finish_evaluation()
|
| 514 |
-
|
| 515 |
-
signal.signal(signal.SIGTERM, _salvage)
|
| 516 |
-
except Exception as exc: # noqa: BLE001
|
| 517 |
-
_log(f"signal handler unavailable: {exc}")
|
| 518 |
-
|
| 519 |
-
tok = _load_tokenizer(ctx)
|
| 520 |
-
stream = _build_stream(_locate_parquet(ctx), tok)
|
| 521 |
-
eos_id = tok.eos_token_id if tok.eos_token_id is not None else VOCAB - 1
|
| 522 |
-
n_windows = max(1, (len(stream) - 1) // SEQ)
|
| 523 |
-
_log(f"{n_windows} windows of {SEQ} tokens")
|
| 524 |
-
|
| 525 |
-
model = model.to(device)
|
| 526 |
try:
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
micro_bs = MICRO_BS
|
| 574 |
-
while True: # OOM ladder
|
| 575 |
try:
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
accum = max(1, TOK_PER_STEP // (micro_bs * SEQ))
|
| 587 |
-
_log(f"micro_bs {micro_bs} x accum {accum} = {micro_bs*SEQ*accum} tok/step")
|
| 588 |
-
|
| 589 |
-
hard_cap = min(step_cap, STEP_CEILING) # the cap the loop actually breaks on
|
| 590 |
step = 0
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 595 |
guard()
|
| 596 |
-
elapsed = time.time() -
|
| 597 |
-
if elapsed >
|
| 598 |
break
|
| 599 |
-
mult =
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 617 |
|
|
|
|
|
|
|
|
|
|
| 618 |
if step == 1 or step % REPORT_EVERY == 0:
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
"""Standalone dress-rehearsal path (the harness uses build_model/train)."""
|
| 651 |
-
ctx = {
|
| 652 |
-
"device": "cuda" if torch.cuda.is_available() else "cpu",
|
| 653 |
-
"seed": MODEL_SEED,
|
| 654 |
-
"train_hours_cap": float(os.environ.get("PRISM_HOURS", 6.0)),
|
| 655 |
-
}
|
| 656 |
-
model = build_model(ctx)
|
| 657 |
-
print(json.dumps(train(model, ctx)), flush=True)
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
if __name__ == "__main__":
|
| 661 |
-
main()
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
# ------------------------- замер на замороженном val -------------------------
|
| 665 |
-
def eval_frozen_val(model, ctx=None, val_lo=VAL_LO, val_hi=VAL_HI):
|
| 666 |
-
"""CE / bpb / bits_per_byte на замороженном срезе, как в prismlib.scoring.
|
| 667 |
-
|
| 668 |
-
Повторяет операторскую арифметику дословно: документ подаётся целиком,
|
| 669 |
-
цель выравнивается по последним logits.shape[1] позициям (модель вправе
|
| 670 |
-
сама усечь контекст), среднее берётся ПО ДОКУМЕНТАМ, а не по токенам, и
|
| 671 |
-
байты пропорционально урезаются на долю реально оценённых позиций.
|
| 672 |
-
"""
|
| 673 |
-
ctx = ctx or {}
|
| 674 |
-
device = ctx.get("device") or ("cuda" if torch.cuda.is_available() else "cpu")
|
| 675 |
-
tok = _load_tokenizer(ctx)
|
| 676 |
-
table = pq.read_table(_locate_parquet(ctx), columns=["text"])
|
| 677 |
-
texts = [t for t in table.column("text").to_pylist()
|
| 678 |
-
if isinstance(t, str) and len(t) >= MIN_CHARS][val_lo:val_hi]
|
| 679 |
-
model.eval()
|
| 680 |
-
losses, n_tokens, bits, scored_bytes = [], 0, 0.0, 0.0
|
| 681 |
with torch.no_grad():
|
| 682 |
-
for
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
if logits.shape[1] < 1:
|
| 689 |
-
continue
|
| 690 |
-
tgt = ids[:, 1:][:, -logits.shape[1]:]
|
| 691 |
-
loss = F.cross_entropy(
|
| 692 |
-
logits.reshape(-1, logits.shape[-1]).float(), tgt.reshape(-1), reduction="mean")
|
| 693 |
-
losses.append(float(loss))
|
| 694 |
-
n_scored = tgt.numel()
|
| 695 |
-
n_tokens += n_scored
|
| 696 |
-
bits += float(loss) * n_scored / math.log(2.0)
|
| 697 |
-
scored_bytes += len(txt.encode("utf-8", errors="replace")) * (
|
| 698 |
-
n_scored / float(max(1, ids.shape[1] - 1)))
|
| 699 |
-
if not losses:
|
| 700 |
-
raise RuntimeError("нет оценённых токенов")
|
| 701 |
-
ce = sum(losses) / len(losses)
|
| 702 |
-
return ce, ce / math.log(2.0), n_tokens, bits / max(1.0, scored_bytes)
|
|
|
|
| 1 |
+
# prism-automodel-copy patch_sha256=af56edd2beccf4460add89c0491907180b95cd76f9f512814db3505150e80055
|
| 2 |
+
# --- nemo_automodel/recipes/llm/prism_entry.py (trainer) ---
|
| 3 |
+
"""PRISM AutoModel 2.0 entry: self-contained build_model + train.
|
| 4 |
+
|
| 5 |
+
Modern decoder LM (RMSNorm, RoPE, SwiGLU, GQA, QK-norm, value-residual, U-net
|
| 6 |
+
skips, tied-free head, logit soft-cap) trained from random init with Muon +
|
| 7 |
+
AdamW (per-group LRs), a WSD schedule, and FlexAttention document masking.
|
| 8 |
+
The harness resolves this module and calls build_model(ctx) then train(model, ctx).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
"""
|
| 10 |
|
|
|
|
| 11 |
import math
|
| 12 |
import os
|
| 13 |
+
import sys
|
| 14 |
import time
|
| 15 |
|
| 16 |
+
os.environ.setdefault("TOKENIZERS_PARALLELISM", "true")
|
| 17 |
+
|
| 18 |
import pyarrow.parquet as pq
|
| 19 |
import torch
|
| 20 |
import torch.nn as nn
|
| 21 |
import torch.nn.functional as F
|
| 22 |
+
from transformers import GPT2TokenizerFast
|
| 23 |
+
|
| 24 |
+
try:
|
| 25 |
+
from torch.nn.attention.flex_attention import flex_attention as _flex
|
| 26 |
+
_flex = torch.compile(_flex)
|
| 27 |
+
except Exception:
|
| 28 |
+
_flex = None
|
| 29 |
|
|
|
|
|
|
|
| 30 |
try:
|
| 31 |
+
from torch.nn.attention.flex_attention import create_block_mask as _create_block_mask
|
| 32 |
+
except Exception:
|
| 33 |
+
_create_block_mask = None
|
| 34 |
+
|
| 35 |
+
try:
|
| 36 |
+
import prism_telemetry
|
| 37 |
except ImportError:
|
| 38 |
+
class _TelemetryFallback:
|
| 39 |
@staticmethod
|
| 40 |
+
def report(**_kwargs):
|
| 41 |
return None
|
| 42 |
|
| 43 |
@staticmethod
|
| 44 |
def finish_evaluation():
|
| 45 |
return None
|
| 46 |
|
| 47 |
+
prism_telemetry = _TelemetryFallback()
|
| 48 |
|
|
|
|
| 49 |
|
| 50 |
+
VOCAB = 8192 # default; real value comes from the shipped tokenizer via ctx["vocab_size"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
BLOCK = 1024
|
| 52 |
+
D_MODEL = 768
|
| 53 |
+
N_LAYER = 15
|
| 54 |
+
N_HEAD = 12
|
| 55 |
+
N_KV_HEAD = 4
|
| 56 |
+
FFN_MULT = 4
|
| 57 |
+
DROPOUT = 0.0
|
| 58 |
+
LOGIT_SOFTCAP = 15.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
|
| 61 |
+
def _ctx_get(ctx, key, default):
|
| 62 |
+
if hasattr(ctx, "get"):
|
| 63 |
+
try:
|
| 64 |
+
v = ctx.get(key, default)
|
| 65 |
+
return default if v is None else v
|
| 66 |
+
except Exception:
|
| 67 |
+
return default
|
| 68 |
+
return getattr(ctx, key, default)
|
| 69 |
|
| 70 |
|
| 71 |
class RMSNorm(nn.Module):
|
| 72 |
+
def __init__(self, dim: int, eps: float = 1e-6):
|
| 73 |
super().__init__()
|
| 74 |
+
self.weight = nn.Parameter(torch.ones(dim))
|
| 75 |
self.eps = eps
|
|
|
|
| 76 |
|
| 77 |
def forward(self, x):
|
| 78 |
+
x32 = x.float()
|
| 79 |
+
x32 = x32 * torch.rsqrt(x32.pow(2).mean(-1, keepdim=True) + self.eps)
|
| 80 |
+
return (x32 * self.weight.float()).type_as(x)
|
| 81 |
|
| 82 |
|
| 83 |
+
def _rope(head_dim: int, seq: int, base: float = 10000.0):
|
| 84 |
+
inv = 1.0 / (base ** (torch.arange(0, head_dim, 2, dtype=torch.float32) / head_dim))
|
| 85 |
+
t = torch.arange(seq, dtype=torch.float32)
|
| 86 |
+
f = torch.outer(t, inv)
|
| 87 |
+
return torch.cos(f), torch.sin(f)
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def _apply_rope(x, cos, sin):
|
| 91 |
+
# x: (b, h, t, hd). Interleaved even/odd rotation.
|
| 92 |
+
xe, xo = x[..., 0::2], x[..., 1::2]
|
| 93 |
+
cos = cos[None, None, :, :].to(x.dtype)
|
| 94 |
+
sin = sin[None, None, :, :].to(x.dtype)
|
| 95 |
+
re = xe * cos - xo * sin
|
| 96 |
+
ro = xe * sin + xo * cos
|
| 97 |
+
return torch.stack([re, ro], dim=-1).flatten(-2)
|
| 98 |
|
| 99 |
|
| 100 |
+
class Attention(nn.Module):
|
| 101 |
+
def __init__(self, d: int, n_head: int, n_kv: int):
|
| 102 |
super().__init__()
|
| 103 |
+
self.n_head, self.n_kv = n_head, n_kv
|
| 104 |
+
self.hd = d // n_head
|
| 105 |
+
self.groups = n_head // n_kv
|
| 106 |
+
self.wq = nn.Linear(d, n_head * self.hd, bias=False)
|
| 107 |
+
self.wk = nn.Linear(d, n_kv * self.hd, bias=False)
|
| 108 |
+
self.wv = nn.Linear(d, n_kv * self.hd, bias=False)
|
| 109 |
+
self.wo = nn.Linear(n_head * self.hd, d, bias=False)
|
| 110 |
+
# QK-norm: normalize queries/keys per head for stable attention logits.
|
| 111 |
+
self.q_norm = RMSNorm(self.hd)
|
| 112 |
+
self.k_norm = RMSNorm(self.hd)
|
| 113 |
+
# Value-residual: mix layer-0 values into this layer (sigmoid(lam) in (0,1),
|
| 114 |
+
# init 0.5). Speeds convergence by giving every block direct access to
|
| 115 |
+
# first-layer value features (ResFormer / value-residual learning).
|
| 116 |
+
self.lam = nn.Parameter(torch.zeros(1))
|
| 117 |
+
|
| 118 |
+
def forward(self, x, cos, sin, v0=None, block_mask=None):
|
| 119 |
+
b, t, _ = x.shape
|
| 120 |
+
q = self.q_norm(self.wq(x).view(b, t, self.n_head, self.hd)).transpose(1, 2)
|
| 121 |
+
k = self.k_norm(self.wk(x).view(b, t, self.n_kv, self.hd)).transpose(1, 2)
|
| 122 |
+
v = self.wv(x).view(b, t, self.n_kv, self.hd)
|
| 123 |
+
if v0 is None:
|
| 124 |
+
v0_out = v
|
| 125 |
+
else:
|
| 126 |
+
lam = torch.sigmoid(self.lam)
|
| 127 |
+
v = lam * v + (1.0 - lam) * v0
|
| 128 |
+
v0_out = v0
|
| 129 |
+
v = v.transpose(1, 2)
|
| 130 |
+
q = _apply_rope(q, cos, sin)
|
| 131 |
+
k = _apply_rope(k, cos, sin)
|
| 132 |
+
k = k.to(q.dtype)
|
| 133 |
+
v = v.to(q.dtype)
|
| 134 |
+
if block_mask is not None and _flex is not None:
|
| 135 |
+
# Fast document-masked attention (GQA handled natively).
|
| 136 |
+
o = _flex(q, k, v, block_mask=block_mask, enable_gqa=True)
|
| 137 |
+
else:
|
| 138 |
+
if self.groups > 1:
|
| 139 |
+
k = k.repeat_interleave(self.groups, dim=1)
|
| 140 |
+
v = v.repeat_interleave(self.groups, dim=1)
|
| 141 |
+
o = F.scaled_dot_product_attention(q, k, v, is_causal=True)
|
| 142 |
+
o = o.transpose(1, 2).contiguous().view(b, t, self.n_head * self.hd)
|
| 143 |
+
return self.wo(o), v0_out
|
| 144 |
|
| 145 |
|
| 146 |
class SwiGLU(nn.Module):
|
| 147 |
+
def __init__(self, d: int, hidden: int):
|
| 148 |
super().__init__()
|
| 149 |
+
self.w_gate = nn.Linear(d, hidden, bias=False)
|
| 150 |
+
self.w_up = nn.Linear(d, hidden, bias=False)
|
| 151 |
+
self.w_down = nn.Linear(hidden, d, bias=False)
|
| 152 |
|
| 153 |
def forward(self, x):
|
| 154 |
+
return self.w_down(F.silu(self.w_gate(x)) * self.w_up(x))
|
| 155 |
|
| 156 |
|
| 157 |
+
class Block(nn.Module):
|
| 158 |
+
def __init__(self, d, n_head, n_kv, ffn, dropout=0.0):
|
| 159 |
super().__init__()
|
| 160 |
self.n1 = RMSNorm(d)
|
| 161 |
+
self.attn = Attention(d, n_head, n_kv)
|
| 162 |
self.n2 = RMSNorm(d)
|
| 163 |
+
self.mlp = SwiGLU(d, ffn)
|
| 164 |
+
self.drop = nn.Dropout(dropout)
|
| 165 |
|
| 166 |
+
def forward(self, x, cos, sin, v0=None, block_mask=None):
|
| 167 |
+
a, v0_out = self.attn(self.n1(x), cos, sin, v0, block_mask)
|
| 168 |
+
x = x + self.drop(a)
|
| 169 |
+
return x + self.drop(self.mlp(self.n2(x))), v0_out
|
| 170 |
|
| 171 |
|
| 172 |
+
class DecoderLM(nn.Module):
|
| 173 |
+
def __init__(self, vocab, d, n_layer, n_head, n_kv, block, ffn_mult):
|
|
|
|
| 174 |
super().__init__()
|
| 175 |
self.block = block
|
| 176 |
+
self.tok_emb = nn.Embedding(vocab, d)
|
| 177 |
+
ffn = ((int(d * ffn_mult * 2 / 3) + 63) // 64) * 64
|
| 178 |
+
self.blocks = nn.ModuleList(Block(d, n_head, n_kv, ffn, DROPOUT) for _ in range(n_layer))
|
| 179 |
+
self.emb_drop = nn.Dropout(DROPOUT)
|
| 180 |
+
self.skip_weights = nn.Parameter(torch.zeros(n_layer // 2))
|
| 181 |
+
self.ln_f = RMSNorm(d)
|
| 182 |
+
self.head = nn.Linear(d, vocab, bias=False)
|
| 183 |
+
# untied head (zero-init), Adam high-LR
|
| 184 |
+
|
| 185 |
+
cos, sin = _rope(d // n_head, block)
|
| 186 |
+
self.register_buffer("rope_cos", cos, persistent=False)
|
| 187 |
+
self.register_buffer("rope_sin", sin, persistent=False)
|
|
|
|
|
|
|
| 188 |
self.apply(self._init)
|
| 189 |
+
# Scaled residual init for depth stability.
|
| 190 |
+
for name, p in self.named_parameters():
|
| 191 |
+
if name.endswith("wo.weight") or name.endswith("w_down.weight"):
|
| 192 |
+
nn.init.normal_(p, mean=0.0, std=0.02 / math.sqrt(2 * n_layer))
|
| 193 |
+
nn.init.zeros_(self.head.weight)
|
| 194 |
|
| 195 |
def _init(self, m):
|
| 196 |
+
if isinstance(m, nn.Linear):
|
| 197 |
+
nn.init.normal_(m.weight, mean=0.0, std=0.02)
|
| 198 |
+
elif isinstance(m, nn.Embedding):
|
| 199 |
+
nn.init.normal_(m.weight, mean=0.0, std=0.02)
|
| 200 |
+
|
| 201 |
+
def forward(self, ids, block_mask=None):
|
| 202 |
+
t = min(ids.shape[1], self.block)
|
| 203 |
+
ids = ids[:, -t:]
|
| 204 |
+
if self.rope_cos.device != ids.device:
|
| 205 |
+
self.rope_cos = self.rope_cos.to(ids.device)
|
| 206 |
+
self.rope_sin = self.rope_sin.to(ids.device)
|
| 207 |
+
cos, sin = self.rope_cos[:t], self.rope_sin[:t]
|
| 208 |
+
x = self.emb_drop(self.tok_emb(ids))
|
| 209 |
+
v0 = None
|
| 210 |
+
n = len(self.blocks)
|
| 211 |
+
n_enc = n // 2
|
| 212 |
+
skips = []
|
| 213 |
+
for i, blk in enumerate(self.blocks):
|
| 214 |
+
if i >= n - n_enc:
|
| 215 |
+
x = x + self.skip_weights[i - (n - n_enc)] * skips.pop()
|
| 216 |
+
x, v0 = blk(x, cos, sin, v0, block_mask)
|
| 217 |
+
if i < n_enc:
|
| 218 |
+
skips.append(x)
|
| 219 |
+
x = self.ln_f(x)
|
| 220 |
+
logits = self.head(x)
|
| 221 |
+
return LOGIT_SOFTCAP * torch.tanh(logits / LOGIT_SOFTCAP)
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def _resolve_tokenizer(ctx):
|
| 225 |
+
"""Prefer the harness-resolved+validated tokenizer (ctx['tokenizer']); else
|
| 226 |
+
load the shipped in-domain tokenizer from the local source tree. Never hits
|
| 227 |
+
the network (the miner child runs under unshare --net)."""
|
| 228 |
+
tok = _ctx_get(ctx, "tokenizer", None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
if tok is not None:
|
| 230 |
return tok
|
| 231 |
+
import os as _os
|
| 232 |
+
here = _os.path.dirname(_os.path.abspath(__file__))
|
| 233 |
+
cands = [
|
| 234 |
+
_ctx_get(ctx, "tokenizer_dir", None),
|
| 235 |
+
_os.path.join(here, "tokenizer"),
|
| 236 |
+
_os.path.join(here, "tok8k"),
|
| 237 |
+
_os.path.join(_os.getcwd(), "tokenizer"),
|
| 238 |
+
_os.path.join(_os.getcwd(), "submission", "tokenizer"),
|
| 239 |
+
]
|
| 240 |
+
for d in cands:
|
| 241 |
+
if d and _os.path.isfile(_os.path.join(d, "tokenizer.json")):
|
| 242 |
+
try:
|
| 243 |
+
from transformers import AutoTokenizer
|
| 244 |
+
return AutoTokenizer.from_pretrained(d, local_files_only=True)
|
| 245 |
+
except Exception:
|
| 246 |
+
from transformers import PreTrainedTokenizerFast
|
| 247 |
+
return PreTrainedTokenizerFast(
|
| 248 |
+
tokenizer_file=_os.path.join(d, "tokenizer.json"),
|
| 249 |
+
eos_token="<|eos|>", pad_token="<|eos|>")
|
| 250 |
+
# Last-resort fallback: the pinned GPT-2 default (keeps local smoke tests
|
| 251 |
+
# runnable even without shipped files; never reached in-pod).
|
| 252 |
+
from transformers import GPT2TokenizerFast
|
| 253 |
+
return GPT2TokenizerFast.from_pretrained("gpt2")
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
def build_model(ctx):
|
| 257 |
+
"""Recipe contract entrypoint: return an nn.Module given the context."""
|
| 258 |
+
torch.manual_seed(int(_ctx_get(ctx, "seed", 0)))
|
| 259 |
+
d = int(_ctx_get(ctx, "d_model", D_MODEL))
|
| 260 |
+
n_layer = int(_ctx_get(ctx, "n_layer", N_LAYER))
|
| 261 |
+
n_head = int(_ctx_get(ctx, "n_head", N_HEAD))
|
| 262 |
+
n_kv = int(_ctx_get(ctx, "n_kv_head", N_KV_HEAD))
|
| 263 |
+
block = int(_ctx_get(ctx, "block", BLOCK))
|
| 264 |
+
# Embedding/head are sized from the resolved (shipped) tokenizer, not a
|
| 265 |
+
# hardcoded constant — the harness passes vocab_size for the tokenizer it
|
| 266 |
+
# resolved from submission/tokenizer/. Fail loud on mismatch would be ideal,
|
| 267 |
+
# but the harness guarantees this equals len(shipped tokenizer).
|
| 268 |
+
vocab = int(_ctx_get(ctx, "vocab_size", VOCAB))
|
| 269 |
+
return DecoderLM(vocab, d, n_layer, n_head, n_kv, block, FFN_MULT)
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
HARD_MAX_STEPS = 20000
|
| 273 |
+
HARD_MAX_SECONDS = 21600
|
| 274 |
+
MUON_LR = 0.036 # peak LR for the transformer weight matrices (Muon)
|
| 275 |
+
# Embedding LR scales inversely with per-token gradient density. At 50k vocab
|
| 276 |
+
# (sparse: ~4 hits/token/step) 0.3 was optimal; at 4096 vocab embeddings update
|
| 277 |
+
# ~12x denser, so hold the effective per-token update constant -> ~0.03.
|
| 278 |
+
EMB_LR = 0.05 # input embedding LR (tuned for 8k in-domain vocab)
|
| 279 |
+
HEAD_LR = 3.6e-3 # peak LR for the untied output head (AdamW ~ 0.1/sqrt(d))
|
| 280 |
+
SCALAR_LR = 0.015 # peak LR for 1-D params: norms, skip/value-residual scalars
|
| 281 |
+
MIN_LR_RATIO = 0.01
|
| 282 |
+
WARMUP_STEPS = 300
|
| 283 |
+
WEIGHT_DECAY = 0.1
|
| 284 |
+
GRAD_CLIP = 1.0
|
| 285 |
+
REPORT_EVERY = 20
|
| 286 |
+
EOT_ID = 50256 # gpt2 <|endoftext|>
|
| 287 |
+
# Rows of unique data to read (memory-safe as uint16); ~420M tokens, reused a few epochs.
|
| 288 |
+
MAX_DATA_ROWS = 700000
|
| 289 |
+
# Large effective batch via gradient accumulation (the run is step-capped, so
|
| 290 |
+
# tokens/step is the lever); target a few epochs over the shard, not more.
|
| 291 |
+
EFFECTIVE_TOKENS_PER_STEP = 262144
|
| 292 |
+
MICRO_TOKENS = 16384
|
| 293 |
+
TARGET_EPOCHS = 2.0
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
def _ctx_get(ctx, key, default):
|
| 297 |
+
if hasattr(ctx, "get"):
|
| 298 |
+
try:
|
| 299 |
+
v = ctx.get(key, default)
|
| 300 |
+
return default if v is None else v
|
| 301 |
+
except Exception:
|
| 302 |
+
return default
|
| 303 |
+
return getattr(ctx, key, default)
|
| 304 |
|
| 305 |
|
| 306 |
+
def _budget(ctx):
|
| 307 |
+
max_steps, max_seconds = HARD_MAX_STEPS, HARD_MAX_SECONDS
|
| 308 |
+
b = getattr(ctx, "budget", None)
|
| 309 |
+
if callable(b):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
try:
|
| 311 |
+
bb = b()
|
| 312 |
+
max_steps = int(getattr(bb, "max_steps", max_steps))
|
| 313 |
+
max_seconds = float(getattr(bb, "max_seconds", max_seconds))
|
| 314 |
+
except Exception:
|
| 315 |
+
pass
|
| 316 |
+
max_steps = int(_ctx_get(ctx, "max_train_steps", max_steps))
|
| 317 |
+
max_seconds = float(_ctx_get(ctx, "max_seconds", max_seconds))
|
| 318 |
+
return min(max_steps, HARD_MAX_STEPS), min(max_seconds, HARD_MAX_SECONDS)
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
def _packed_tokens(ctx, tok, block, want_tokens):
|
| 322 |
+
# Concatenate tokenized docs (EOT-separated) into one uint16 stream, then reshape
|
| 323 |
+
# into (n, block) windows. Tokens are kept as numpy uint16 (gpt2 vocab < 65536) so
|
| 324 |
+
# ~hundreds of millions of tokens fit in memory instead of a huge Python int list.
|
| 325 |
+
import numpy as np
|
| 326 |
+
|
| 327 |
+
path = _ctx_get(ctx, "dataset_path", None)
|
| 328 |
+
tr = int(_ctx_get(ctx, "train_rows", 2048))
|
| 329 |
+
vr = int(_ctx_get(ctx, "val_rows", 256))
|
| 330 |
+
# Cache the packed token stream so a re-run in the same pod skips re-tokenizing.
|
| 331 |
+
cache = f"/tmp/prism_pack_{MAX_DATA_ROWS}_{tr}_{vr}.npy"
|
| 332 |
+
if os.path.exists(cache):
|
| 333 |
+
stream = np.load(cache)
|
| 334 |
+
else:
|
| 335 |
+
# Only materialize the rows we use. The harness scores texts[tr:tr+vr]; the
|
| 336 |
+
# pinned shard has no <100-char rows, so raw row order matches its filtered
|
| 337 |
+
# order and slicing raw keeps train disjoint from the scored val cut.
|
| 338 |
+
col = pq.read_table(path, columns=["text"]).column("text")
|
| 339 |
+
head = col.slice(0, tr).to_pylist()
|
| 340 |
+
body = col.slice(tr + vr, MAX_DATA_ROWS).to_pylist()
|
| 341 |
+
texts = [t for t in head + body if isinstance(t, str) and len(t) >= 100]
|
| 342 |
+
eot = np.array([EOT_ID], dtype=np.uint16)
|
| 343 |
+
parts = []
|
| 344 |
+
total = 0
|
| 345 |
+
for start in range(0, len(texts), 1024):
|
| 346 |
+
for enc in tok(texts[start : start + 1024], add_special_tokens=False)["input_ids"]:
|
| 347 |
+
parts.append(np.asarray(enc, dtype=np.uint16))
|
| 348 |
+
parts.append(eot)
|
| 349 |
+
total += len(enc) + 1
|
| 350 |
+
if total >= want_tokens:
|
| 351 |
+
break
|
| 352 |
+
stream = np.concatenate(parts) if parts else np.zeros(block + 1, dtype=np.uint16)
|
| 353 |
+
try:
|
| 354 |
+
np.save(cache, stream)
|
| 355 |
except OSError:
|
| 356 |
pass
|
| 357 |
+
n = max(1, (len(stream) - 1) // block)
|
| 358 |
+
stream = stream[: n * block + 1]
|
| 359 |
+
x = torch.from_numpy(stream[:-1].astype(np.int32)).view(n, block)
|
| 360 |
+
y = torch.from_numpy(stream[1:].astype(np.int32)).view(n, block)
|
| 361 |
+
return x, y
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
def _batch_size(device, block):
|
| 365 |
+
if not str(device).startswith("cuda"):
|
| 366 |
+
return 4
|
| 367 |
+
# ~32k tokens/step; back off if VRAM is tight (handled by the OOM guard).
|
| 368 |
+
return max(1, min(48, 32768 // max(block, 1)))
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
def _doc_block_mask(xb):
|
| 372 |
+
# Block-sparse mask: attend only within the same document (EOT-split) + causal.
|
| 373 |
+
if _create_block_mask is None:
|
| 374 |
+
return None
|
| 375 |
+
eot = (xb == EOT_ID)
|
| 376 |
+
doc_id = torch.cumsum(eot.int(), dim=1) - eot.int()
|
| 377 |
+
def mm(b, h, q_idx, kv_idx):
|
| 378 |
+
return (q_idx >= kv_idx) & (doc_id[b, q_idx] == doc_id[b, kv_idx])
|
| 379 |
+
return _create_block_mask(mm, xb.shape[0], None, xb.shape[1], xb.shape[1], device=xb.device)
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
def _sched(elapsed, budget, warmup_frac=0.03, decay_frac=0.20):
|
| 383 |
+
# Warmup -> stable (hold peak LR) -> cosine decay over the last decay_frac.
|
| 384 |
+
# WSD keeps LR high through most of the run (faster convergence when val is
|
| 385 |
+
# still descending at the cap) and only anneals near the end.
|
| 386 |
+
warm = warmup_frac * budget
|
| 387 |
+
if elapsed < warm:
|
| 388 |
+
return elapsed / max(warm, 1e-9)
|
| 389 |
+
decay_start = (1.0 - decay_frac) * budget
|
| 390 |
+
if elapsed < decay_start:
|
| 391 |
+
return 1.0
|
| 392 |
+
progress = min(1.0, (elapsed - decay_start) / max(1e-9, budget - decay_start))
|
| 393 |
+
cosine = 0.5 * (1.0 + math.cos(math.pi * progress))
|
| 394 |
+
return MIN_LR_RATIO + (1.0 - MIN_LR_RATIO) * cosine
|
| 395 |
|
| 396 |
|
| 397 |
+
def _is_no_decay(name, p):
|
| 398 |
+
return p.dim() < 2 or "norm" in name.lower() or "emb" in name.lower()
|
|
|
|
| 399 |
|
|
|
|
|
|
|
| 400 |
|
| 401 |
+
def _newtonschulz5(G, steps=5):
|
| 402 |
+
# Orthogonalize the gradient matrix via a quintic Newton-Schulz iteration
|
| 403 |
+
# (Muon; Bernstein/Jordan). Runs in bf16; coefficients tuned for LM training.
|
| 404 |
+
a, b, c = 3.4445, -4.7750, 2.0315
|
| 405 |
+
X = G.bfloat16()
|
| 406 |
+
transposed = X.shape[0] > X.shape[1]
|
| 407 |
+
if transposed:
|
| 408 |
+
X = X.T
|
| 409 |
+
X = X / (X.norm() + 1e-7)
|
| 410 |
+
for _ in range(steps):
|
| 411 |
+
A = X @ X.T
|
| 412 |
+
B = b * A + c * (A @ A)
|
| 413 |
+
X = a * X + B @ X
|
| 414 |
+
return X.T if transposed else X
|
| 415 |
+
|
| 416 |
+
|
| 417 |
+
class Muon(torch.optim.Optimizer):
|
| 418 |
+
"""Muon: momentum + Newton-Schulz orthogonalization for 2D weight matrices.
|
| 419 |
+
Trains transformer matrices markedly faster than AdamW at the same compute."""
|
| 420 |
+
|
| 421 |
+
def __init__(self, params, lr=0.02, momentum=0.95, nesterov=True, ns_steps=5):
|
| 422 |
+
super().__init__(params, dict(lr=lr, momentum=momentum, nesterov=nesterov, ns_steps=ns_steps))
|
| 423 |
|
| 424 |
@torch.no_grad()
|
| 425 |
+
def step(self):
|
| 426 |
+
for grp in self.param_groups:
|
| 427 |
+
lr, mom, nest, ns = grp["lr"], grp["momentum"], grp["nesterov"], grp["ns_steps"]
|
| 428 |
+
for p in grp["params"]:
|
| 429 |
if p.grad is None:
|
| 430 |
continue
|
| 431 |
st = self.state[p]
|
| 432 |
+
if "buf" not in st:
|
| 433 |
+
st["buf"] = torch.zeros_like(p.grad)
|
| 434 |
+
buf = st["buf"]
|
| 435 |
buf.mul_(mom).add_(p.grad)
|
| 436 |
+
g = p.grad.add(buf, alpha=mom) if nest else buf
|
| 437 |
+
g = _newtonschulz5(g, steps=ns)
|
| 438 |
+
# Scale so the RMS update size is ~lr regardless of matrix shape.
|
| 439 |
+
scale = (max(1.0, p.size(0) / p.size(1)) ** 0.5)
|
| 440 |
+
p.add_(g.to(p.dtype), alpha=-lr * scale)
|
| 441 |
+
|
| 442 |
+
|
| 443 |
+
def train(model, ctx):
|
| 444 |
+
"""Recipe contract entrypoint: trains in place, returns a metrics dict."""
|
| 445 |
+
device = _ctx_get(ctx, "device", "cpu")
|
| 446 |
+
torch.manual_seed(int(_ctx_get(ctx, "seed", 0)))
|
| 447 |
+
guard = _ctx_get(ctx, "guard", lambda: None)
|
| 448 |
+
if str(device).startswith("cuda"):
|
| 449 |
+
torch.backends.cuda.matmul.allow_tf32 = True
|
| 450 |
+
torch.backends.cudnn.allow_tf32 = True
|
| 451 |
+
|
| 452 |
+
max_steps, max_seconds = _budget(ctx)
|
| 453 |
+
warmup = min(WARMUP_STEPS, max(1, max_steps // 20))
|
| 454 |
+
|
| 455 |
+
tok = _resolve_tokenizer(ctx)
|
| 456 |
+
# The frozen-val bpb is scored with THIS tokenizer; the doc separator in the
|
| 457 |
+
# packed training stream + the doc-mask must use its real eos id.
|
| 458 |
+
global EOT_ID
|
| 459 |
+
_eos = getattr(tok, "eos_token_id", None)
|
| 460 |
+
EOT_ID = int(_eos) if _eos is not None else (len(tok) - 1)
|
| 461 |
+
block = getattr(model, "block", 512)
|
| 462 |
+
micro = max(1, int(_ctx_get(ctx, "batch_size", MICRO_TOKENS // max(block, 1))))
|
| 463 |
+
accum = max(1, EFFECTIVE_TOKENS_PER_STEP // (micro * block))
|
| 464 |
+
|
| 465 |
+
x, y = _packed_tokens(ctx, tok, block, want_tokens=1_200_000_000)
|
| 466 |
+
# Exact replica of the harness val cut (texts[train_rows:train_rows+val_rows])
|
| 467 |
+
# for a live bpb estimate; these rows are excluded from training data.
|
| 468 |
+
val_ids = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 469 |
try:
|
| 470 |
+
_vp = _ctx_get(ctx, "dataset_path", None)
|
| 471 |
+
_tr = int(_ctx_get(ctx, "train_rows", 2048)); _vr = int(_ctx_get(ctx, "val_rows", 256))
|
| 472 |
+
_vcol = pq.read_table(_vp, columns=["text"]).column("text").slice(_tr, _vr).to_pylist()
|
| 473 |
+
_vtexts = [t for t in _vcol if isinstance(t, str) and len(t) >= 100]
|
| 474 |
+
for _t in _vtexts:
|
| 475 |
+
_ids = tok(_t, add_special_tokens=False)["input_ids"]
|
| 476 |
+
if len(_ids) >= 2:
|
| 477 |
+
val_ids.append(torch.tensor(_ids, dtype=torch.long))
|
| 478 |
+
except Exception:
|
| 479 |
+
val_ids = []
|
| 480 |
+
n_windows = x.shape[0]
|
| 481 |
+
# Train for the whole compute budget (time governs the schedule); reshuffled
|
| 482 |
+
# windows give ~as many epochs as fit, and the LR decays to its floor by the cap.
|
| 483 |
+
time_budget = max_seconds * 0.94
|
| 484 |
+
|
| 485 |
+
# Muon for the 2D transformer weight matrices; AdamW for embeddings + norms.
|
| 486 |
+
muon_params, adam_emb, adam_head, adam_scalar = [], [], [], []
|
| 487 |
+
for n, p in model.named_parameters():
|
| 488 |
+
if not p.requires_grad:
|
| 489 |
+
continue
|
| 490 |
+
if "tok_emb" in n:
|
| 491 |
+
adam_emb.append(p)
|
| 492 |
+
elif "head" in n:
|
| 493 |
+
adam_head.append(p)
|
| 494 |
+
elif p.ndim >= 2:
|
| 495 |
+
muon_params.append(p)
|
| 496 |
+
else:
|
| 497 |
+
adam_scalar.append(p)
|
| 498 |
+
opt_muon = Muon(muon_params, lr=MUON_LR, momentum=0.95)
|
| 499 |
+
opt_adam = torch.optim.AdamW(
|
| 500 |
+
[{"params": adam_emb, "lr": EMB_LR},
|
| 501 |
+
{"params": adam_head, "lr": HEAD_LR},
|
| 502 |
+
{"params": adam_scalar, "lr": SCALAR_LR}],
|
| 503 |
+
betas=(0.9, 0.95), eps=1e-8, weight_decay=0.0,
|
| 504 |
+
fused=str(device).startswith("cuda"),
|
| 505 |
+
)
|
| 506 |
+
optimizers = [opt_muon, opt_adam]
|
| 507 |
+
use_bf16 = str(device).startswith("cuda") and torch.cuda.is_bf16_supported()
|
| 508 |
+
model.to(device)
|
| 509 |
+
model.train()
|
| 510 |
+
EMA_DECAY = 0.999
|
| 511 |
+
ema_params = {n: p.detach().clone().float() for n, p in model.named_parameters() if p.requires_grad}
|
| 512 |
+
# Compile the TRAINING forward for throughput (fixed shape). The harness scores
|
| 513 |
+
# val on the original `model` (variable lengths), so it never recompiles.
|
| 514 |
+
fwd = model
|
| 515 |
+
if str(device).startswith("cuda"):
|
|
|
|
|
|
|
| 516 |
try:
|
| 517 |
+
fwd = torch.compile(model)
|
| 518 |
+
except Exception:
|
| 519 |
+
fwd = model
|
| 520 |
+
|
| 521 |
+
g = torch.Generator().manual_seed(int(_ctx_get(ctx, "seed", 0)))
|
| 522 |
+
order = torch.randperm(n_windows, generator=g)
|
| 523 |
+
t0 = time.time()
|
| 524 |
+
last = 0.0
|
| 525 |
+
ema = 0.0
|
| 526 |
+
cursor = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
| 527 |
step = 0
|
| 528 |
+
|
| 529 |
+
def _next_micro(n):
|
| 530 |
+
nonlocal cursor, order
|
| 531 |
+
if cursor + n > n_windows:
|
| 532 |
+
order = torch.randperm(n_windows, generator=g)
|
| 533 |
+
cursor = 0
|
| 534 |
+
idx = order[cursor : cursor + n]
|
| 535 |
+
cursor += n
|
| 536 |
+
return (x[idx].to(device, non_blocking=True).long(),
|
| 537 |
+
y[idx].to(device, non_blocking=True).long())
|
| 538 |
+
|
| 539 |
+
while step < max_steps:
|
| 540 |
guard()
|
| 541 |
+
elapsed = time.time() - t0
|
| 542 |
+
if elapsed >= time_budget:
|
| 543 |
break
|
| 544 |
+
mult = _sched(elapsed, time_budget)
|
| 545 |
+
lr = MUON_LR * mult
|
| 546 |
+
opt_muon.param_groups[0]["lr"] = MUON_LR * mult
|
| 547 |
+
opt_adam.param_groups[0]["lr"] = EMB_LR * mult
|
| 548 |
+
opt_adam.param_groups[1]["lr"] = HEAD_LR * mult
|
| 549 |
+
opt_adam.param_groups[2]["lr"] = SCALAR_LR * mult
|
| 550 |
+
for o in optimizers:
|
| 551 |
+
o.zero_grad(set_to_none=True)
|
| 552 |
+
try:
|
| 553 |
+
for a in range(accum):
|
| 554 |
+
xb, yb = _next_micro(micro)
|
| 555 |
+
bm = _doc_block_mask(xb)
|
| 556 |
+
if use_bf16:
|
| 557 |
+
with torch.autocast(device_type="cuda", dtype=torch.bfloat16):
|
| 558 |
+
logits = fwd(xb, block_mask=bm)
|
| 559 |
+
loss = F.cross_entropy(logits.reshape(-1, logits.shape[-1]), yb.reshape(-1))
|
| 560 |
+
else:
|
| 561 |
+
logits = fwd(xb, block_mask=bm)
|
| 562 |
+
loss = F.cross_entropy(logits.reshape(-1, logits.shape[-1]), yb.reshape(-1))
|
| 563 |
+
(loss / accum).backward()
|
| 564 |
+
grad_norm = float(torch.nn.utils.clip_grad_norm_(model.parameters(), GRAD_CLIP))
|
| 565 |
+
for o in optimizers:
|
| 566 |
+
o.step()
|
| 567 |
+
with torch.no_grad():
|
| 568 |
+
for _n, _p in model.named_parameters():
|
| 569 |
+
if _n in ema_params:
|
| 570 |
+
ema_params[_n].mul_(EMA_DECAY).add_(_p.detach().float(), alpha=1.0 - EMA_DECAY)
|
| 571 |
+
except RuntimeError as exc:
|
| 572 |
+
if "out of memory" in str(exc).lower() and micro > 1:
|
| 573 |
+
micro = max(1, micro // 2)
|
| 574 |
+
accum = max(1, EFFECTIVE_TOKENS_PER_STEP // (micro * block))
|
| 575 |
+
if str(device).startswith("cuda"):
|
| 576 |
+
torch.cuda.empty_cache()
|
| 577 |
+
continue
|
| 578 |
+
raise
|
| 579 |
|
| 580 |
+
last = float(loss.item())
|
| 581 |
+
ema = last if step == 0 else (0.98 * ema + 0.02 * last)
|
| 582 |
+
step += 1
|
| 583 |
if step == 1 or step % REPORT_EVERY == 0:
|
| 584 |
+
prism_telemetry.report(
|
| 585 |
+
loss=last, step=step, grad_norm=grad_norm,
|
| 586 |
+
layer_stats={"model": {"grad_norm": grad_norm}},
|
| 587 |
+
)
|
| 588 |
+
if step == 1 or step % 100 == 0:
|
| 589 |
+
print(f"[train] step {step}/{max_steps} loss {last:.3f} ema {ema:.3f} lr {lr:.2e} "
|
| 590 |
+
f"gnorm {grad_norm:.2f} t {time.time()-t0:.0f}s", file=sys.stderr, flush=True)
|
| 591 |
+
if val_ids and (step == 1 or step % 1000 == 0):
|
| 592 |
+
try:
|
| 593 |
+
model.eval()
|
| 594 |
+
vloss = []
|
| 595 |
+
with torch.no_grad():
|
| 596 |
+
for _ids in val_ids:
|
| 597 |
+
_i = _ids.to(device).unsqueeze(0)
|
| 598 |
+
if use_bf16:
|
| 599 |
+
with torch.autocast(device_type="cuda", dtype=torch.bfloat16):
|
| 600 |
+
_lg = model(_i[:, :-1])
|
| 601 |
+
_tg = _i[:, 1:][:, -_lg.shape[1]:]
|
| 602 |
+
_l = F.cross_entropy(_lg.reshape(-1, _lg.shape[-1]).float(), _tg.reshape(-1))
|
| 603 |
+
else:
|
| 604 |
+
_lg = model(_i[:, :-1])
|
| 605 |
+
_tg = _i[:, 1:][:, -_lg.shape[1]:]
|
| 606 |
+
_l = F.cross_entropy(_lg.reshape(-1, _lg.shape[-1]), _tg.reshape(-1))
|
| 607 |
+
vloss.append(float(_l))
|
| 608 |
+
model.train()
|
| 609 |
+
_ce = sum(vloss) / max(1, len(vloss))
|
| 610 |
+
print(f"[val] step {step} val_ce {_ce:.4f} bpb {_ce/0.6931471805599453:.4f} "
|
| 611 |
+
f"(top 4.2881) t {time.time()-t0:.0f}s", file=sys.stderr, flush=True)
|
| 612 |
+
except Exception:
|
| 613 |
+
model.train()
|
| 614 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 615 |
with torch.no_grad():
|
| 616 |
+
for _n, _p in model.named_parameters():
|
| 617 |
+
if _n in ema_params:
|
| 618 |
+
_p.copy_(ema_params[_n].to(_p.dtype))
|
| 619 |
+
prism_telemetry.report(loss=last, step=step, grad_norm=0.0)
|
| 620 |
+
prism_telemetry.finish_evaluation()
|
| 621 |
+
return {"train_loss": last, "train_steps": step, "train_seconds": time.time() - t0}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
checkpoint.pt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:219b23c0d467a2cbfc7117f6f7904f3fbd57158dcdc383b87245c48c7a2078c0
|
| 3 |
+
size 427978889
|
config.json
CHANGED
|
@@ -8,9 +8,9 @@
|
|
| 8 |
"AutoModel": "modeling_prism.PrismCustomModel",
|
| 9 |
"AutoModelForCausalLM": "modeling_prism.PrismCustomModel"
|
| 10 |
},
|
| 11 |
-
"prism_arch_id": "
|
| 12 |
-
"prism_submission_id": "
|
| 13 |
-
"prism_bpb": 3.
|
| 14 |
"torch_dtype": "float32",
|
| 15 |
"checkpoint_file": "checkpoint.pt"
|
| 16 |
}
|
|
|
|
| 8 |
"AutoModel": "modeling_prism.PrismCustomModel",
|
| 9 |
"AutoModelForCausalLM": "modeling_prism.PrismCustomModel"
|
| 10 |
},
|
| 11 |
+
"prism_arch_id": "arch_f17d92b32a8c79f7",
|
| 12 |
+
"prism_submission_id": "7b8658aedfdb158782567d09e26a9e819c578ff20c4db1d940e12de77cd9d6d2",
|
| 13 |
+
"prism_bpb": 3.7180674325750696,
|
| 14 |
"torch_dtype": "float32",
|
| 15 |
"checkpoint_file": "checkpoint.pt"
|
| 16 |
}
|
sources/.prism/automodel.patch
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
sources/.prism/diffstat.json
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
{"files":[{"path":"nemo_automodel/
|
|
|
|
| 1 |
+
{"files":[{"path":"nemo_automodel/recipes/llm/prism_entry.py","added":619,"deleted":0,"class":"trainer"},{"path":"tokenizer/tokenizer.json","added":1,"deleted":0,"class":"other"},{"path":"tokenizer/tokenizer_config.json","added":9,"deleted":0,"class":"other"}],"total_added":629,"total_deleted":0}
|
sources/nemo_automodel/recipes/llm/prism_entry.py
CHANGED
|
@@ -45,7 +45,7 @@ except ImportError:
|
|
| 45 |
prism_telemetry = _TelemetryFallback()
|
| 46 |
|
| 47 |
|
| 48 |
-
VOCAB =
|
| 49 |
BLOCK = 1024
|
| 50 |
D_MODEL = 768
|
| 51 |
N_LAYER = 15
|
|
@@ -88,8 +88,8 @@ def _rope(head_dim: int, seq: int, base: float = 10000.0):
|
|
| 88 |
def _apply_rope(x, cos, sin):
|
| 89 |
# x: (b, h, t, hd). Interleaved even/odd rotation.
|
| 90 |
xe, xo = x[..., 0::2], x[..., 1::2]
|
| 91 |
-
cos = cos[None, None, :, :]
|
| 92 |
-
sin = sin[None, None, :, :]
|
| 93 |
re = xe * cos - xo * sin
|
| 94 |
ro = xe * sin + xo * cos
|
| 95 |
return torch.stack([re, ro], dim=-1).flatten(-2)
|
|
@@ -127,6 +127,8 @@ class Attention(nn.Module):
|
|
| 127 |
v = v.transpose(1, 2)
|
| 128 |
q = _apply_rope(q, cos, sin)
|
| 129 |
k = _apply_rope(k, cos, sin)
|
|
|
|
|
|
|
| 130 |
if block_mask is not None and _flex is not None:
|
| 131 |
# Fast document-masked attention (GQA handled natively).
|
| 132 |
o = _flex(q, k, v, block_mask=block_mask, enable_gqa=True)
|
|
@@ -217,6 +219,38 @@ class DecoderLM(nn.Module):
|
|
| 217 |
return LOGIT_SOFTCAP * torch.tanh(logits / LOGIT_SOFTCAP)
|
| 218 |
|
| 219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
def build_model(ctx):
|
| 221 |
"""Recipe contract entrypoint: return an nn.Module given the context."""
|
| 222 |
torch.manual_seed(int(_ctx_get(ctx, "seed", 0)))
|
|
@@ -225,13 +259,21 @@ def build_model(ctx):
|
|
| 225 |
n_head = int(_ctx_get(ctx, "n_head", N_HEAD))
|
| 226 |
n_kv = int(_ctx_get(ctx, "n_kv_head", N_KV_HEAD))
|
| 227 |
block = int(_ctx_get(ctx, "block", BLOCK))
|
| 228 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
|
| 230 |
|
| 231 |
HARD_MAX_STEPS = 20000
|
| 232 |
HARD_MAX_SECONDS = 21600
|
| 233 |
MUON_LR = 0.036 # peak LR for the transformer weight matrices (Muon)
|
| 234 |
-
|
|
|
|
|
|
|
|
|
|
| 235 |
HEAD_LR = 3.6e-3 # peak LR for the untied output head (AdamW ~ 0.1/sqrt(d))
|
| 236 |
SCALAR_LR = 0.015 # peak LR for 1-D params: norms, skip/value-residual scalars
|
| 237 |
MIN_LR_RATIO = 0.01
|
|
@@ -408,7 +450,12 @@ def train(model, ctx):
|
|
| 408 |
max_steps, max_seconds = _budget(ctx)
|
| 409 |
warmup = min(WARMUP_STEPS, max(1, max_steps // 20))
|
| 410 |
|
| 411 |
-
tok =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
block = getattr(model, "block", 512)
|
| 413 |
micro = max(1, int(_ctx_get(ctx, "batch_size", MICRO_TOKENS // max(block, 1))))
|
| 414 |
accum = max(1, EFFECTIVE_TOKENS_PER_STEP // (micro * block))
|
|
|
|
| 45 |
prism_telemetry = _TelemetryFallback()
|
| 46 |
|
| 47 |
|
| 48 |
+
VOCAB = 8192 # default; real value comes from the shipped tokenizer via ctx["vocab_size"]
|
| 49 |
BLOCK = 1024
|
| 50 |
D_MODEL = 768
|
| 51 |
N_LAYER = 15
|
|
|
|
| 88 |
def _apply_rope(x, cos, sin):
|
| 89 |
# x: (b, h, t, hd). Interleaved even/odd rotation.
|
| 90 |
xe, xo = x[..., 0::2], x[..., 1::2]
|
| 91 |
+
cos = cos[None, None, :, :].to(x.dtype)
|
| 92 |
+
sin = sin[None, None, :, :].to(x.dtype)
|
| 93 |
re = xe * cos - xo * sin
|
| 94 |
ro = xe * sin + xo * cos
|
| 95 |
return torch.stack([re, ro], dim=-1).flatten(-2)
|
|
|
|
| 127 |
v = v.transpose(1, 2)
|
| 128 |
q = _apply_rope(q, cos, sin)
|
| 129 |
k = _apply_rope(k, cos, sin)
|
| 130 |
+
k = k.to(q.dtype)
|
| 131 |
+
v = v.to(q.dtype)
|
| 132 |
if block_mask is not None and _flex is not None:
|
| 133 |
# Fast document-masked attention (GQA handled natively).
|
| 134 |
o = _flex(q, k, v, block_mask=block_mask, enable_gqa=True)
|
|
|
|
| 219 |
return LOGIT_SOFTCAP * torch.tanh(logits / LOGIT_SOFTCAP)
|
| 220 |
|
| 221 |
|
| 222 |
+
def _resolve_tokenizer(ctx):
|
| 223 |
+
"""Prefer the harness-resolved+validated tokenizer (ctx['tokenizer']); else
|
| 224 |
+
load the shipped in-domain tokenizer from the local source tree. Never hits
|
| 225 |
+
the network (the miner child runs under unshare --net)."""
|
| 226 |
+
tok = _ctx_get(ctx, "tokenizer", None)
|
| 227 |
+
if tok is not None:
|
| 228 |
+
return tok
|
| 229 |
+
import os as _os
|
| 230 |
+
here = _os.path.dirname(_os.path.abspath(__file__))
|
| 231 |
+
cands = [
|
| 232 |
+
_ctx_get(ctx, "tokenizer_dir", None),
|
| 233 |
+
_os.path.join(here, "tokenizer"),
|
| 234 |
+
_os.path.join(here, "tok8k"),
|
| 235 |
+
_os.path.join(_os.getcwd(), "tokenizer"),
|
| 236 |
+
_os.path.join(_os.getcwd(), "submission", "tokenizer"),
|
| 237 |
+
]
|
| 238 |
+
for d in cands:
|
| 239 |
+
if d and _os.path.isfile(_os.path.join(d, "tokenizer.json")):
|
| 240 |
+
try:
|
| 241 |
+
from transformers import AutoTokenizer
|
| 242 |
+
return AutoTokenizer.from_pretrained(d, local_files_only=True)
|
| 243 |
+
except Exception:
|
| 244 |
+
from transformers import PreTrainedTokenizerFast
|
| 245 |
+
return PreTrainedTokenizerFast(
|
| 246 |
+
tokenizer_file=_os.path.join(d, "tokenizer.json"),
|
| 247 |
+
eos_token="<|eos|>", pad_token="<|eos|>")
|
| 248 |
+
# Last-resort fallback: the pinned GPT-2 default (keeps local smoke tests
|
| 249 |
+
# runnable even without shipped files; never reached in-pod).
|
| 250 |
+
from transformers import GPT2TokenizerFast
|
| 251 |
+
return GPT2TokenizerFast.from_pretrained("gpt2")
|
| 252 |
+
|
| 253 |
+
|
| 254 |
def build_model(ctx):
|
| 255 |
"""Recipe contract entrypoint: return an nn.Module given the context."""
|
| 256 |
torch.manual_seed(int(_ctx_get(ctx, "seed", 0)))
|
|
|
|
| 259 |
n_head = int(_ctx_get(ctx, "n_head", N_HEAD))
|
| 260 |
n_kv = int(_ctx_get(ctx, "n_kv_head", N_KV_HEAD))
|
| 261 |
block = int(_ctx_get(ctx, "block", BLOCK))
|
| 262 |
+
# Embedding/head are sized from the resolved (shipped) tokenizer, not a
|
| 263 |
+
# hardcoded constant — the harness passes vocab_size for the tokenizer it
|
| 264 |
+
# resolved from submission/tokenizer/. Fail loud on mismatch would be ideal,
|
| 265 |
+
# but the harness guarantees this equals len(shipped tokenizer).
|
| 266 |
+
vocab = int(_ctx_get(ctx, "vocab_size", VOCAB))
|
| 267 |
+
return DecoderLM(vocab, d, n_layer, n_head, n_kv, block, FFN_MULT)
|
| 268 |
|
| 269 |
|
| 270 |
HARD_MAX_STEPS = 20000
|
| 271 |
HARD_MAX_SECONDS = 21600
|
| 272 |
MUON_LR = 0.036 # peak LR for the transformer weight matrices (Muon)
|
| 273 |
+
# Embedding LR scales inversely with per-token gradient density. At 50k vocab
|
| 274 |
+
# (sparse: ~4 hits/token/step) 0.3 was optimal; at 4096 vocab embeddings update
|
| 275 |
+
# ~12x denser, so hold the effective per-token update constant -> ~0.03.
|
| 276 |
+
EMB_LR = 0.05 # input embedding LR (tuned for 8k in-domain vocab)
|
| 277 |
HEAD_LR = 3.6e-3 # peak LR for the untied output head (AdamW ~ 0.1/sqrt(d))
|
| 278 |
SCALAR_LR = 0.015 # peak LR for 1-D params: norms, skip/value-residual scalars
|
| 279 |
MIN_LR_RATIO = 0.01
|
|
|
|
| 450 |
max_steps, max_seconds = _budget(ctx)
|
| 451 |
warmup = min(WARMUP_STEPS, max(1, max_steps // 20))
|
| 452 |
|
| 453 |
+
tok = _resolve_tokenizer(ctx)
|
| 454 |
+
# The frozen-val bpb is scored with THIS tokenizer; the doc separator in the
|
| 455 |
+
# packed training stream + the doc-mask must use its real eos id.
|
| 456 |
+
global EOT_ID
|
| 457 |
+
_eos = getattr(tok, "eos_token_id", None)
|
| 458 |
+
EOT_ID = int(_eos) if _eos is not None else (len(tok) - 1)
|
| 459 |
block = getattr(model, "block", 512)
|
| 460 |
micro = max(1, int(_ctx_get(ctx, "batch_size", MICRO_TOKENS // max(block, 1))))
|
| 461 |
accum = max(1, EFFECTIVE_TOKENS_PER_STEP // (micro * block))
|
sources/prism.toml
CHANGED
|
@@ -1,38 +1 @@
|
|
| 1 |
-
|
| 2 |
-
#
|
| 3 |
-
# The patch adds one self-contained, Prism-shaped train entry plus the
|
| 4 |
-
# submission's 8k tokenizer. The harness loads the entry below, calls
|
| 5 |
-
# build_model(ctx) then train(model, ctx); under the two-phase flow it saves
|
| 6 |
-
# the trained weights, rebuilds the model from this same build_model and
|
| 7 |
-
# scores it.
|
| 8 |
-
#
|
| 9 |
-
# The entry depends only on what the pod provides: torch and numpy from the
|
| 10 |
-
# base image, pyarrow and transformers from the harness bootstrap. It does not
|
| 11 |
-
# import the surrounding framework, so the run does not depend on any
|
| 12 |
-
# AutoModel extra being installed on the pod.
|
| 13 |
-
|
| 14 |
-
[automodel]
|
| 15 |
-
base = "automodel@v0.5.0"
|
| 16 |
-
git_commit = "d02f49cb314554715aabb97e8dba6599c9f6e9e0"
|
| 17 |
-
|
| 18 |
-
[train]
|
| 19 |
-
entry = "nemo_automodel/components/models/prism/prism_entry.py"
|
| 20 |
-
|
| 21 |
-
[budget]
|
| 22 |
-
# Budget lives in the entry (constants), not here: up to 11,000 optimizer steps (the 5.0h wall binds first)
|
| 23 |
-
# at 196,608 tokens/step. Projected 108k tok/s on the pinned 1x RTX 5090 at d_model 1024
|
| 24 |
-
# (1.82 s/step projected), plus ~3-5 min on-pod tokenization and ~2 min
|
| 25 |
-
# compile. The entry keeps one hour of the 6.0h training cap in reserve so the
|
| 26 |
-
# post-train phase - checkpoint write, rebuilt-model battery, frozen-val score
|
| 27 |
-
# - finishes inside the 7.0h pod lifetime; the measured post-train phase is
|
| 28 |
-
# ~6 min, so that reserve is deliberately generous.
|
| 29 |
-
#
|
| 30 |
-
# The decay is keyed to whichever budget runs out first, wall time or the step
|
| 31 |
-
# ceiling: a pod faster than planned reaches max_steps with time to spare, a
|
| 32 |
-
# slower one runs out the wall first, and the cosine tail completes in both
|
| 33 |
-
# directions instead of being cut off mid-schedule.
|
| 34 |
-
max_steps = 19000
|
| 35 |
-
tokens_per_step = 196608
|
| 36 |
-
seq_len = 1024
|
| 37 |
-
local_batch_size = 32
|
| 38 |
-
grad_accum = 6
|
|
|
|
| 1 |
+
entry = "nemo_automodel/recipes/llm/prism_entry.py"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sources/tokenizer/tokenizer.json
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
sources/tokenizer/tokenizer_config.json
CHANGED
|
@@ -2,8 +2,8 @@
|
|
| 2 |
"tokenizer_class": "PreTrainedTokenizerFast",
|
| 3 |
"eos_token": "<|eos|>",
|
| 4 |
"pad_token": "<|eos|>",
|
| 5 |
-
"unk_token": null,
|
| 6 |
"bos_token": null,
|
|
|
|
| 7 |
"clean_up_tokenization_spaces": false,
|
| 8 |
-
"model_max_length":
|
| 9 |
}
|
|
|
|
| 2 |
"tokenizer_class": "PreTrainedTokenizerFast",
|
| 3 |
"eos_token": "<|eos|>",
|
| 4 |
"pad_token": "<|eos|>",
|
|
|
|
| 5 |
"bos_token": null,
|
| 6 |
+
"unk_token": null,
|
| 7 |
"clean_up_tokenization_spaces": false,
|
| 8 |
+
"model_max_length": 1000000000
|
| 9 |
}
|
training.py
CHANGED
|
@@ -0,0 +1,620 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# --- nemo_automodel/recipes/llm/prism_entry.py (trainer) ---
|
| 2 |
+
"""PRISM AutoModel 2.0 entry: self-contained build_model + train.
|
| 3 |
+
|
| 4 |
+
Modern decoder LM (RMSNorm, RoPE, SwiGLU, GQA, QK-norm, value-residual, U-net
|
| 5 |
+
skips, tied-free head, logit soft-cap) trained from random init with Muon +
|
| 6 |
+
AdamW (per-group LRs), a WSD schedule, and FlexAttention document masking.
|
| 7 |
+
The harness resolves this module and calls build_model(ctx) then train(model, ctx).
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import math
|
| 11 |
+
import os
|
| 12 |
+
import sys
|
| 13 |
+
import time
|
| 14 |
+
|
| 15 |
+
os.environ.setdefault("TOKENIZERS_PARALLELISM", "true")
|
| 16 |
+
|
| 17 |
+
import pyarrow.parquet as pq
|
| 18 |
+
import torch
|
| 19 |
+
import torch.nn as nn
|
| 20 |
+
import torch.nn.functional as F
|
| 21 |
+
from transformers import GPT2TokenizerFast
|
| 22 |
+
|
| 23 |
+
try:
|
| 24 |
+
from torch.nn.attention.flex_attention import flex_attention as _flex
|
| 25 |
+
_flex = torch.compile(_flex)
|
| 26 |
+
except Exception:
|
| 27 |
+
_flex = None
|
| 28 |
+
|
| 29 |
+
try:
|
| 30 |
+
from torch.nn.attention.flex_attention import create_block_mask as _create_block_mask
|
| 31 |
+
except Exception:
|
| 32 |
+
_create_block_mask = None
|
| 33 |
+
|
| 34 |
+
try:
|
| 35 |
+
import prism_telemetry
|
| 36 |
+
except ImportError:
|
| 37 |
+
class _TelemetryFallback:
|
| 38 |
+
@staticmethod
|
| 39 |
+
def report(**_kwargs):
|
| 40 |
+
return None
|
| 41 |
+
|
| 42 |
+
@staticmethod
|
| 43 |
+
def finish_evaluation():
|
| 44 |
+
return None
|
| 45 |
+
|
| 46 |
+
prism_telemetry = _TelemetryFallback()
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
VOCAB = 8192 # default; real value comes from the shipped tokenizer via ctx["vocab_size"]
|
| 50 |
+
BLOCK = 1024
|
| 51 |
+
D_MODEL = 768
|
| 52 |
+
N_LAYER = 15
|
| 53 |
+
N_HEAD = 12
|
| 54 |
+
N_KV_HEAD = 4
|
| 55 |
+
FFN_MULT = 4
|
| 56 |
+
DROPOUT = 0.0
|
| 57 |
+
LOGIT_SOFTCAP = 15.0
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def _ctx_get(ctx, key, default):
|
| 61 |
+
if hasattr(ctx, "get"):
|
| 62 |
+
try:
|
| 63 |
+
v = ctx.get(key, default)
|
| 64 |
+
return default if v is None else v
|
| 65 |
+
except Exception:
|
| 66 |
+
return default
|
| 67 |
+
return getattr(ctx, key, default)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
class RMSNorm(nn.Module):
|
| 71 |
+
def __init__(self, dim: int, eps: float = 1e-6):
|
| 72 |
+
super().__init__()
|
| 73 |
+
self.weight = nn.Parameter(torch.ones(dim))
|
| 74 |
+
self.eps = eps
|
| 75 |
+
|
| 76 |
+
def forward(self, x):
|
| 77 |
+
x32 = x.float()
|
| 78 |
+
x32 = x32 * torch.rsqrt(x32.pow(2).mean(-1, keepdim=True) + self.eps)
|
| 79 |
+
return (x32 * self.weight.float()).type_as(x)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def _rope(head_dim: int, seq: int, base: float = 10000.0):
|
| 83 |
+
inv = 1.0 / (base ** (torch.arange(0, head_dim, 2, dtype=torch.float32) / head_dim))
|
| 84 |
+
t = torch.arange(seq, dtype=torch.float32)
|
| 85 |
+
f = torch.outer(t, inv)
|
| 86 |
+
return torch.cos(f), torch.sin(f)
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def _apply_rope(x, cos, sin):
|
| 90 |
+
# x: (b, h, t, hd). Interleaved even/odd rotation.
|
| 91 |
+
xe, xo = x[..., 0::2], x[..., 1::2]
|
| 92 |
+
cos = cos[None, None, :, :].to(x.dtype)
|
| 93 |
+
sin = sin[None, None, :, :].to(x.dtype)
|
| 94 |
+
re = xe * cos - xo * sin
|
| 95 |
+
ro = xe * sin + xo * cos
|
| 96 |
+
return torch.stack([re, ro], dim=-1).flatten(-2)
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
class Attention(nn.Module):
|
| 100 |
+
def __init__(self, d: int, n_head: int, n_kv: int):
|
| 101 |
+
super().__init__()
|
| 102 |
+
self.n_head, self.n_kv = n_head, n_kv
|
| 103 |
+
self.hd = d // n_head
|
| 104 |
+
self.groups = n_head // n_kv
|
| 105 |
+
self.wq = nn.Linear(d, n_head * self.hd, bias=False)
|
| 106 |
+
self.wk = nn.Linear(d, n_kv * self.hd, bias=False)
|
| 107 |
+
self.wv = nn.Linear(d, n_kv * self.hd, bias=False)
|
| 108 |
+
self.wo = nn.Linear(n_head * self.hd, d, bias=False)
|
| 109 |
+
# QK-norm: normalize queries/keys per head for stable attention logits.
|
| 110 |
+
self.q_norm = RMSNorm(self.hd)
|
| 111 |
+
self.k_norm = RMSNorm(self.hd)
|
| 112 |
+
# Value-residual: mix layer-0 values into this layer (sigmoid(lam) in (0,1),
|
| 113 |
+
# init 0.5). Speeds convergence by giving every block direct access to
|
| 114 |
+
# first-layer value features (ResFormer / value-residual learning).
|
| 115 |
+
self.lam = nn.Parameter(torch.zeros(1))
|
| 116 |
+
|
| 117 |
+
def forward(self, x, cos, sin, v0=None, block_mask=None):
|
| 118 |
+
b, t, _ = x.shape
|
| 119 |
+
q = self.q_norm(self.wq(x).view(b, t, self.n_head, self.hd)).transpose(1, 2)
|
| 120 |
+
k = self.k_norm(self.wk(x).view(b, t, self.n_kv, self.hd)).transpose(1, 2)
|
| 121 |
+
v = self.wv(x).view(b, t, self.n_kv, self.hd)
|
| 122 |
+
if v0 is None:
|
| 123 |
+
v0_out = v
|
| 124 |
+
else:
|
| 125 |
+
lam = torch.sigmoid(self.lam)
|
| 126 |
+
v = lam * v + (1.0 - lam) * v0
|
| 127 |
+
v0_out = v0
|
| 128 |
+
v = v.transpose(1, 2)
|
| 129 |
+
q = _apply_rope(q, cos, sin)
|
| 130 |
+
k = _apply_rope(k, cos, sin)
|
| 131 |
+
k = k.to(q.dtype)
|
| 132 |
+
v = v.to(q.dtype)
|
| 133 |
+
if block_mask is not None and _flex is not None:
|
| 134 |
+
# Fast document-masked attention (GQA handled natively).
|
| 135 |
+
o = _flex(q, k, v, block_mask=block_mask, enable_gqa=True)
|
| 136 |
+
else:
|
| 137 |
+
if self.groups > 1:
|
| 138 |
+
k = k.repeat_interleave(self.groups, dim=1)
|
| 139 |
+
v = v.repeat_interleave(self.groups, dim=1)
|
| 140 |
+
o = F.scaled_dot_product_attention(q, k, v, is_causal=True)
|
| 141 |
+
o = o.transpose(1, 2).contiguous().view(b, t, self.n_head * self.hd)
|
| 142 |
+
return self.wo(o), v0_out
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
class SwiGLU(nn.Module):
|
| 146 |
+
def __init__(self, d: int, hidden: int):
|
| 147 |
+
super().__init__()
|
| 148 |
+
self.w_gate = nn.Linear(d, hidden, bias=False)
|
| 149 |
+
self.w_up = nn.Linear(d, hidden, bias=False)
|
| 150 |
+
self.w_down = nn.Linear(hidden, d, bias=False)
|
| 151 |
+
|
| 152 |
+
def forward(self, x):
|
| 153 |
+
return self.w_down(F.silu(self.w_gate(x)) * self.w_up(x))
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
class Block(nn.Module):
|
| 157 |
+
def __init__(self, d, n_head, n_kv, ffn, dropout=0.0):
|
| 158 |
+
super().__init__()
|
| 159 |
+
self.n1 = RMSNorm(d)
|
| 160 |
+
self.attn = Attention(d, n_head, n_kv)
|
| 161 |
+
self.n2 = RMSNorm(d)
|
| 162 |
+
self.mlp = SwiGLU(d, ffn)
|
| 163 |
+
self.drop = nn.Dropout(dropout)
|
| 164 |
+
|
| 165 |
+
def forward(self, x, cos, sin, v0=None, block_mask=None):
|
| 166 |
+
a, v0_out = self.attn(self.n1(x), cos, sin, v0, block_mask)
|
| 167 |
+
x = x + self.drop(a)
|
| 168 |
+
return x + self.drop(self.mlp(self.n2(x))), v0_out
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
class DecoderLM(nn.Module):
|
| 172 |
+
def __init__(self, vocab, d, n_layer, n_head, n_kv, block, ffn_mult):
|
| 173 |
+
super().__init__()
|
| 174 |
+
self.block = block
|
| 175 |
+
self.tok_emb = nn.Embedding(vocab, d)
|
| 176 |
+
ffn = ((int(d * ffn_mult * 2 / 3) + 63) // 64) * 64
|
| 177 |
+
self.blocks = nn.ModuleList(Block(d, n_head, n_kv, ffn, DROPOUT) for _ in range(n_layer))
|
| 178 |
+
self.emb_drop = nn.Dropout(DROPOUT)
|
| 179 |
+
self.skip_weights = nn.Parameter(torch.zeros(n_layer // 2))
|
| 180 |
+
self.ln_f = RMSNorm(d)
|
| 181 |
+
self.head = nn.Linear(d, vocab, bias=False)
|
| 182 |
+
# untied head (zero-init), Adam high-LR
|
| 183 |
+
|
| 184 |
+
cos, sin = _rope(d // n_head, block)
|
| 185 |
+
self.register_buffer("rope_cos", cos, persistent=False)
|
| 186 |
+
self.register_buffer("rope_sin", sin, persistent=False)
|
| 187 |
+
self.apply(self._init)
|
| 188 |
+
# Scaled residual init for depth stability.
|
| 189 |
+
for name, p in self.named_parameters():
|
| 190 |
+
if name.endswith("wo.weight") or name.endswith("w_down.weight"):
|
| 191 |
+
nn.init.normal_(p, mean=0.0, std=0.02 / math.sqrt(2 * n_layer))
|
| 192 |
+
nn.init.zeros_(self.head.weight)
|
| 193 |
+
|
| 194 |
+
def _init(self, m):
|
| 195 |
+
if isinstance(m, nn.Linear):
|
| 196 |
+
nn.init.normal_(m.weight, mean=0.0, std=0.02)
|
| 197 |
+
elif isinstance(m, nn.Embedding):
|
| 198 |
+
nn.init.normal_(m.weight, mean=0.0, std=0.02)
|
| 199 |
+
|
| 200 |
+
def forward(self, ids, block_mask=None):
|
| 201 |
+
t = min(ids.shape[1], self.block)
|
| 202 |
+
ids = ids[:, -t:]
|
| 203 |
+
if self.rope_cos.device != ids.device:
|
| 204 |
+
self.rope_cos = self.rope_cos.to(ids.device)
|
| 205 |
+
self.rope_sin = self.rope_sin.to(ids.device)
|
| 206 |
+
cos, sin = self.rope_cos[:t], self.rope_sin[:t]
|
| 207 |
+
x = self.emb_drop(self.tok_emb(ids))
|
| 208 |
+
v0 = None
|
| 209 |
+
n = len(self.blocks)
|
| 210 |
+
n_enc = n // 2
|
| 211 |
+
skips = []
|
| 212 |
+
for i, blk in enumerate(self.blocks):
|
| 213 |
+
if i >= n - n_enc:
|
| 214 |
+
x = x + self.skip_weights[i - (n - n_enc)] * skips.pop()
|
| 215 |
+
x, v0 = blk(x, cos, sin, v0, block_mask)
|
| 216 |
+
if i < n_enc:
|
| 217 |
+
skips.append(x)
|
| 218 |
+
x = self.ln_f(x)
|
| 219 |
+
logits = self.head(x)
|
| 220 |
+
return LOGIT_SOFTCAP * torch.tanh(logits / LOGIT_SOFTCAP)
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def _resolve_tokenizer(ctx):
|
| 224 |
+
"""Prefer the harness-resolved+validated tokenizer (ctx['tokenizer']); else
|
| 225 |
+
load the shipped in-domain tokenizer from the local source tree. Never hits
|
| 226 |
+
the network (the miner child runs under unshare --net)."""
|
| 227 |
+
tok = _ctx_get(ctx, "tokenizer", None)
|
| 228 |
+
if tok is not None:
|
| 229 |
+
return tok
|
| 230 |
+
import os as _os
|
| 231 |
+
here = _os.path.dirname(_os.path.abspath(__file__))
|
| 232 |
+
cands = [
|
| 233 |
+
_ctx_get(ctx, "tokenizer_dir", None),
|
| 234 |
+
_os.path.join(here, "tokenizer"),
|
| 235 |
+
_os.path.join(here, "tok8k"),
|
| 236 |
+
_os.path.join(_os.getcwd(), "tokenizer"),
|
| 237 |
+
_os.path.join(_os.getcwd(), "submission", "tokenizer"),
|
| 238 |
+
]
|
| 239 |
+
for d in cands:
|
| 240 |
+
if d and _os.path.isfile(_os.path.join(d, "tokenizer.json")):
|
| 241 |
+
try:
|
| 242 |
+
from transformers import AutoTokenizer
|
| 243 |
+
return AutoTokenizer.from_pretrained(d, local_files_only=True)
|
| 244 |
+
except Exception:
|
| 245 |
+
from transformers import PreTrainedTokenizerFast
|
| 246 |
+
return PreTrainedTokenizerFast(
|
| 247 |
+
tokenizer_file=_os.path.join(d, "tokenizer.json"),
|
| 248 |
+
eos_token="<|eos|>", pad_token="<|eos|>")
|
| 249 |
+
# Last-resort fallback: the pinned GPT-2 default (keeps local smoke tests
|
| 250 |
+
# runnable even without shipped files; never reached in-pod).
|
| 251 |
+
from transformers import GPT2TokenizerFast
|
| 252 |
+
return GPT2TokenizerFast.from_pretrained("gpt2")
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
def build_model(ctx):
|
| 256 |
+
"""Recipe contract entrypoint: return an nn.Module given the context."""
|
| 257 |
+
torch.manual_seed(int(_ctx_get(ctx, "seed", 0)))
|
| 258 |
+
d = int(_ctx_get(ctx, "d_model", D_MODEL))
|
| 259 |
+
n_layer = int(_ctx_get(ctx, "n_layer", N_LAYER))
|
| 260 |
+
n_head = int(_ctx_get(ctx, "n_head", N_HEAD))
|
| 261 |
+
n_kv = int(_ctx_get(ctx, "n_kv_head", N_KV_HEAD))
|
| 262 |
+
block = int(_ctx_get(ctx, "block", BLOCK))
|
| 263 |
+
# Embedding/head are sized from the resolved (shipped) tokenizer, not a
|
| 264 |
+
# hardcoded constant — the harness passes vocab_size for the tokenizer it
|
| 265 |
+
# resolved from submission/tokenizer/. Fail loud on mismatch would be ideal,
|
| 266 |
+
# but the harness guarantees this equals len(shipped tokenizer).
|
| 267 |
+
vocab = int(_ctx_get(ctx, "vocab_size", VOCAB))
|
| 268 |
+
return DecoderLM(vocab, d, n_layer, n_head, n_kv, block, FFN_MULT)
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
HARD_MAX_STEPS = 20000
|
| 272 |
+
HARD_MAX_SECONDS = 21600
|
| 273 |
+
MUON_LR = 0.036 # peak LR for the transformer weight matrices (Muon)
|
| 274 |
+
# Embedding LR scales inversely with per-token gradient density. At 50k vocab
|
| 275 |
+
# (sparse: ~4 hits/token/step) 0.3 was optimal; at 4096 vocab embeddings update
|
| 276 |
+
# ~12x denser, so hold the effective per-token update constant -> ~0.03.
|
| 277 |
+
EMB_LR = 0.05 # input embedding LR (tuned for 8k in-domain vocab)
|
| 278 |
+
HEAD_LR = 3.6e-3 # peak LR for the untied output head (AdamW ~ 0.1/sqrt(d))
|
| 279 |
+
SCALAR_LR = 0.015 # peak LR for 1-D params: norms, skip/value-residual scalars
|
| 280 |
+
MIN_LR_RATIO = 0.01
|
| 281 |
+
WARMUP_STEPS = 300
|
| 282 |
+
WEIGHT_DECAY = 0.1
|
| 283 |
+
GRAD_CLIP = 1.0
|
| 284 |
+
REPORT_EVERY = 20
|
| 285 |
+
EOT_ID = 50256 # gpt2 <|endoftext|>
|
| 286 |
+
# Rows of unique data to read (memory-safe as uint16); ~420M tokens, reused a few epochs.
|
| 287 |
+
MAX_DATA_ROWS = 700000
|
| 288 |
+
# Large effective batch via gradient accumulation (the run is step-capped, so
|
| 289 |
+
# tokens/step is the lever); target a few epochs over the shard, not more.
|
| 290 |
+
EFFECTIVE_TOKENS_PER_STEP = 262144
|
| 291 |
+
MICRO_TOKENS = 16384
|
| 292 |
+
TARGET_EPOCHS = 2.0
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
def _ctx_get(ctx, key, default):
|
| 296 |
+
if hasattr(ctx, "get"):
|
| 297 |
+
try:
|
| 298 |
+
v = ctx.get(key, default)
|
| 299 |
+
return default if v is None else v
|
| 300 |
+
except Exception:
|
| 301 |
+
return default
|
| 302 |
+
return getattr(ctx, key, default)
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
def _budget(ctx):
|
| 306 |
+
max_steps, max_seconds = HARD_MAX_STEPS, HARD_MAX_SECONDS
|
| 307 |
+
b = getattr(ctx, "budget", None)
|
| 308 |
+
if callable(b):
|
| 309 |
+
try:
|
| 310 |
+
bb = b()
|
| 311 |
+
max_steps = int(getattr(bb, "max_steps", max_steps))
|
| 312 |
+
max_seconds = float(getattr(bb, "max_seconds", max_seconds))
|
| 313 |
+
except Exception:
|
| 314 |
+
pass
|
| 315 |
+
max_steps = int(_ctx_get(ctx, "max_train_steps", max_steps))
|
| 316 |
+
max_seconds = float(_ctx_get(ctx, "max_seconds", max_seconds))
|
| 317 |
+
return min(max_steps, HARD_MAX_STEPS), min(max_seconds, HARD_MAX_SECONDS)
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
def _packed_tokens(ctx, tok, block, want_tokens):
|
| 321 |
+
# Concatenate tokenized docs (EOT-separated) into one uint16 stream, then reshape
|
| 322 |
+
# into (n, block) windows. Tokens are kept as numpy uint16 (gpt2 vocab < 65536) so
|
| 323 |
+
# ~hundreds of millions of tokens fit in memory instead of a huge Python int list.
|
| 324 |
+
import numpy as np
|
| 325 |
+
|
| 326 |
+
path = _ctx_get(ctx, "dataset_path", None)
|
| 327 |
+
tr = int(_ctx_get(ctx, "train_rows", 2048))
|
| 328 |
+
vr = int(_ctx_get(ctx, "val_rows", 256))
|
| 329 |
+
# Cache the packed token stream so a re-run in the same pod skips re-tokenizing.
|
| 330 |
+
cache = f"/tmp/prism_pack_{MAX_DATA_ROWS}_{tr}_{vr}.npy"
|
| 331 |
+
if os.path.exists(cache):
|
| 332 |
+
stream = np.load(cache)
|
| 333 |
+
else:
|
| 334 |
+
# Only materialize the rows we use. The harness scores texts[tr:tr+vr]; the
|
| 335 |
+
# pinned shard has no <100-char rows, so raw row order matches its filtered
|
| 336 |
+
# order and slicing raw keeps train disjoint from the scored val cut.
|
| 337 |
+
col = pq.read_table(path, columns=["text"]).column("text")
|
| 338 |
+
head = col.slice(0, tr).to_pylist()
|
| 339 |
+
body = col.slice(tr + vr, MAX_DATA_ROWS).to_pylist()
|
| 340 |
+
texts = [t for t in head + body if isinstance(t, str) and len(t) >= 100]
|
| 341 |
+
eot = np.array([EOT_ID], dtype=np.uint16)
|
| 342 |
+
parts = []
|
| 343 |
+
total = 0
|
| 344 |
+
for start in range(0, len(texts), 1024):
|
| 345 |
+
for enc in tok(texts[start : start + 1024], add_special_tokens=False)["input_ids"]:
|
| 346 |
+
parts.append(np.asarray(enc, dtype=np.uint16))
|
| 347 |
+
parts.append(eot)
|
| 348 |
+
total += len(enc) + 1
|
| 349 |
+
if total >= want_tokens:
|
| 350 |
+
break
|
| 351 |
+
stream = np.concatenate(parts) if parts else np.zeros(block + 1, dtype=np.uint16)
|
| 352 |
+
try:
|
| 353 |
+
np.save(cache, stream)
|
| 354 |
+
except OSError:
|
| 355 |
+
pass
|
| 356 |
+
n = max(1, (len(stream) - 1) // block)
|
| 357 |
+
stream = stream[: n * block + 1]
|
| 358 |
+
x = torch.from_numpy(stream[:-1].astype(np.int32)).view(n, block)
|
| 359 |
+
y = torch.from_numpy(stream[1:].astype(np.int32)).view(n, block)
|
| 360 |
+
return x, y
|
| 361 |
+
|
| 362 |
+
|
| 363 |
+
def _batch_size(device, block):
|
| 364 |
+
if not str(device).startswith("cuda"):
|
| 365 |
+
return 4
|
| 366 |
+
# ~32k tokens/step; back off if VRAM is tight (handled by the OOM guard).
|
| 367 |
+
return max(1, min(48, 32768 // max(block, 1)))
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
def _doc_block_mask(xb):
|
| 371 |
+
# Block-sparse mask: attend only within the same document (EOT-split) + causal.
|
| 372 |
+
if _create_block_mask is None:
|
| 373 |
+
return None
|
| 374 |
+
eot = (xb == EOT_ID)
|
| 375 |
+
doc_id = torch.cumsum(eot.int(), dim=1) - eot.int()
|
| 376 |
+
def mm(b, h, q_idx, kv_idx):
|
| 377 |
+
return (q_idx >= kv_idx) & (doc_id[b, q_idx] == doc_id[b, kv_idx])
|
| 378 |
+
return _create_block_mask(mm, xb.shape[0], None, xb.shape[1], xb.shape[1], device=xb.device)
|
| 379 |
+
|
| 380 |
+
|
| 381 |
+
def _sched(elapsed, budget, warmup_frac=0.03, decay_frac=0.20):
|
| 382 |
+
# Warmup -> stable (hold peak LR) -> cosine decay over the last decay_frac.
|
| 383 |
+
# WSD keeps LR high through most of the run (faster convergence when val is
|
| 384 |
+
# still descending at the cap) and only anneals near the end.
|
| 385 |
+
warm = warmup_frac * budget
|
| 386 |
+
if elapsed < warm:
|
| 387 |
+
return elapsed / max(warm, 1e-9)
|
| 388 |
+
decay_start = (1.0 - decay_frac) * budget
|
| 389 |
+
if elapsed < decay_start:
|
| 390 |
+
return 1.0
|
| 391 |
+
progress = min(1.0, (elapsed - decay_start) / max(1e-9, budget - decay_start))
|
| 392 |
+
cosine = 0.5 * (1.0 + math.cos(math.pi * progress))
|
| 393 |
+
return MIN_LR_RATIO + (1.0 - MIN_LR_RATIO) * cosine
|
| 394 |
+
|
| 395 |
+
|
| 396 |
+
def _is_no_decay(name, p):
|
| 397 |
+
return p.dim() < 2 or "norm" in name.lower() or "emb" in name.lower()
|
| 398 |
+
|
| 399 |
+
|
| 400 |
+
def _newtonschulz5(G, steps=5):
|
| 401 |
+
# Orthogonalize the gradient matrix via a quintic Newton-Schulz iteration
|
| 402 |
+
# (Muon; Bernstein/Jordan). Runs in bf16; coefficients tuned for LM training.
|
| 403 |
+
a, b, c = 3.4445, -4.7750, 2.0315
|
| 404 |
+
X = G.bfloat16()
|
| 405 |
+
transposed = X.shape[0] > X.shape[1]
|
| 406 |
+
if transposed:
|
| 407 |
+
X = X.T
|
| 408 |
+
X = X / (X.norm() + 1e-7)
|
| 409 |
+
for _ in range(steps):
|
| 410 |
+
A = X @ X.T
|
| 411 |
+
B = b * A + c * (A @ A)
|
| 412 |
+
X = a * X + B @ X
|
| 413 |
+
return X.T if transposed else X
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
class Muon(torch.optim.Optimizer):
|
| 417 |
+
"""Muon: momentum + Newton-Schulz orthogonalization for 2D weight matrices.
|
| 418 |
+
Trains transformer matrices markedly faster than AdamW at the same compute."""
|
| 419 |
+
|
| 420 |
+
def __init__(self, params, lr=0.02, momentum=0.95, nesterov=True, ns_steps=5):
|
| 421 |
+
super().__init__(params, dict(lr=lr, momentum=momentum, nesterov=nesterov, ns_steps=ns_steps))
|
| 422 |
+
|
| 423 |
+
@torch.no_grad()
|
| 424 |
+
def step(self):
|
| 425 |
+
for grp in self.param_groups:
|
| 426 |
+
lr, mom, nest, ns = grp["lr"], grp["momentum"], grp["nesterov"], grp["ns_steps"]
|
| 427 |
+
for p in grp["params"]:
|
| 428 |
+
if p.grad is None:
|
| 429 |
+
continue
|
| 430 |
+
st = self.state[p]
|
| 431 |
+
if "buf" not in st:
|
| 432 |
+
st["buf"] = torch.zeros_like(p.grad)
|
| 433 |
+
buf = st["buf"]
|
| 434 |
+
buf.mul_(mom).add_(p.grad)
|
| 435 |
+
g = p.grad.add(buf, alpha=mom) if nest else buf
|
| 436 |
+
g = _newtonschulz5(g, steps=ns)
|
| 437 |
+
# Scale so the RMS update size is ~lr regardless of matrix shape.
|
| 438 |
+
scale = (max(1.0, p.size(0) / p.size(1)) ** 0.5)
|
| 439 |
+
p.add_(g.to(p.dtype), alpha=-lr * scale)
|
| 440 |
+
|
| 441 |
+
|
| 442 |
+
def train(model, ctx):
|
| 443 |
+
"""Recipe contract entrypoint: trains in place, returns a metrics dict."""
|
| 444 |
+
device = _ctx_get(ctx, "device", "cpu")
|
| 445 |
+
torch.manual_seed(int(_ctx_get(ctx, "seed", 0)))
|
| 446 |
+
guard = _ctx_get(ctx, "guard", lambda: None)
|
| 447 |
+
if str(device).startswith("cuda"):
|
| 448 |
+
torch.backends.cuda.matmul.allow_tf32 = True
|
| 449 |
+
torch.backends.cudnn.allow_tf32 = True
|
| 450 |
+
|
| 451 |
+
max_steps, max_seconds = _budget(ctx)
|
| 452 |
+
warmup = min(WARMUP_STEPS, max(1, max_steps // 20))
|
| 453 |
+
|
| 454 |
+
tok = _resolve_tokenizer(ctx)
|
| 455 |
+
# The frozen-val bpb is scored with THIS tokenizer; the doc separator in the
|
| 456 |
+
# packed training stream + the doc-mask must use its real eos id.
|
| 457 |
+
global EOT_ID
|
| 458 |
+
_eos = getattr(tok, "eos_token_id", None)
|
| 459 |
+
EOT_ID = int(_eos) if _eos is not None else (len(tok) - 1)
|
| 460 |
+
block = getattr(model, "block", 512)
|
| 461 |
+
micro = max(1, int(_ctx_get(ctx, "batch_size", MICRO_TOKENS // max(block, 1))))
|
| 462 |
+
accum = max(1, EFFECTIVE_TOKENS_PER_STEP // (micro * block))
|
| 463 |
+
|
| 464 |
+
x, y = _packed_tokens(ctx, tok, block, want_tokens=1_200_000_000)
|
| 465 |
+
# Exact replica of the harness val cut (texts[train_rows:train_rows+val_rows])
|
| 466 |
+
# for a live bpb estimate; these rows are excluded from training data.
|
| 467 |
+
val_ids = []
|
| 468 |
+
try:
|
| 469 |
+
_vp = _ctx_get(ctx, "dataset_path", None)
|
| 470 |
+
_tr = int(_ctx_get(ctx, "train_rows", 2048)); _vr = int(_ctx_get(ctx, "val_rows", 256))
|
| 471 |
+
_vcol = pq.read_table(_vp, columns=["text"]).column("text").slice(_tr, _vr).to_pylist()
|
| 472 |
+
_vtexts = [t for t in _vcol if isinstance(t, str) and len(t) >= 100]
|
| 473 |
+
for _t in _vtexts:
|
| 474 |
+
_ids = tok(_t, add_special_tokens=False)["input_ids"]
|
| 475 |
+
if len(_ids) >= 2:
|
| 476 |
+
val_ids.append(torch.tensor(_ids, dtype=torch.long))
|
| 477 |
+
except Exception:
|
| 478 |
+
val_ids = []
|
| 479 |
+
n_windows = x.shape[0]
|
| 480 |
+
# Train for the whole compute budget (time governs the schedule); reshuffled
|
| 481 |
+
# windows give ~as many epochs as fit, and the LR decays to its floor by the cap.
|
| 482 |
+
time_budget = max_seconds * 0.94
|
| 483 |
+
|
| 484 |
+
# Muon for the 2D transformer weight matrices; AdamW for embeddings + norms.
|
| 485 |
+
muon_params, adam_emb, adam_head, adam_scalar = [], [], [], []
|
| 486 |
+
for n, p in model.named_parameters():
|
| 487 |
+
if not p.requires_grad:
|
| 488 |
+
continue
|
| 489 |
+
if "tok_emb" in n:
|
| 490 |
+
adam_emb.append(p)
|
| 491 |
+
elif "head" in n:
|
| 492 |
+
adam_head.append(p)
|
| 493 |
+
elif p.ndim >= 2:
|
| 494 |
+
muon_params.append(p)
|
| 495 |
+
else:
|
| 496 |
+
adam_scalar.append(p)
|
| 497 |
+
opt_muon = Muon(muon_params, lr=MUON_LR, momentum=0.95)
|
| 498 |
+
opt_adam = torch.optim.AdamW(
|
| 499 |
+
[{"params": adam_emb, "lr": EMB_LR},
|
| 500 |
+
{"params": adam_head, "lr": HEAD_LR},
|
| 501 |
+
{"params": adam_scalar, "lr": SCALAR_LR}],
|
| 502 |
+
betas=(0.9, 0.95), eps=1e-8, weight_decay=0.0,
|
| 503 |
+
fused=str(device).startswith("cuda"),
|
| 504 |
+
)
|
| 505 |
+
optimizers = [opt_muon, opt_adam]
|
| 506 |
+
use_bf16 = str(device).startswith("cuda") and torch.cuda.is_bf16_supported()
|
| 507 |
+
model.to(device)
|
| 508 |
+
model.train()
|
| 509 |
+
EMA_DECAY = 0.999
|
| 510 |
+
ema_params = {n: p.detach().clone().float() for n, p in model.named_parameters() if p.requires_grad}
|
| 511 |
+
# Compile the TRAINING forward for throughput (fixed shape). The harness scores
|
| 512 |
+
# val on the original `model` (variable lengths), so it never recompiles.
|
| 513 |
+
fwd = model
|
| 514 |
+
if str(device).startswith("cuda"):
|
| 515 |
+
try:
|
| 516 |
+
fwd = torch.compile(model)
|
| 517 |
+
except Exception:
|
| 518 |
+
fwd = model
|
| 519 |
+
|
| 520 |
+
g = torch.Generator().manual_seed(int(_ctx_get(ctx, "seed", 0)))
|
| 521 |
+
order = torch.randperm(n_windows, generator=g)
|
| 522 |
+
t0 = time.time()
|
| 523 |
+
last = 0.0
|
| 524 |
+
ema = 0.0
|
| 525 |
+
cursor = 0
|
| 526 |
+
step = 0
|
| 527 |
+
|
| 528 |
+
def _next_micro(n):
|
| 529 |
+
nonlocal cursor, order
|
| 530 |
+
if cursor + n > n_windows:
|
| 531 |
+
order = torch.randperm(n_windows, generator=g)
|
| 532 |
+
cursor = 0
|
| 533 |
+
idx = order[cursor : cursor + n]
|
| 534 |
+
cursor += n
|
| 535 |
+
return (x[idx].to(device, non_blocking=True).long(),
|
| 536 |
+
y[idx].to(device, non_blocking=True).long())
|
| 537 |
+
|
| 538 |
+
while step < max_steps:
|
| 539 |
+
guard()
|
| 540 |
+
elapsed = time.time() - t0
|
| 541 |
+
if elapsed >= time_budget:
|
| 542 |
+
break
|
| 543 |
+
mult = _sched(elapsed, time_budget)
|
| 544 |
+
lr = MUON_LR * mult
|
| 545 |
+
opt_muon.param_groups[0]["lr"] = MUON_LR * mult
|
| 546 |
+
opt_adam.param_groups[0]["lr"] = EMB_LR * mult
|
| 547 |
+
opt_adam.param_groups[1]["lr"] = HEAD_LR * mult
|
| 548 |
+
opt_adam.param_groups[2]["lr"] = SCALAR_LR * mult
|
| 549 |
+
for o in optimizers:
|
| 550 |
+
o.zero_grad(set_to_none=True)
|
| 551 |
+
try:
|
| 552 |
+
for a in range(accum):
|
| 553 |
+
xb, yb = _next_micro(micro)
|
| 554 |
+
bm = _doc_block_mask(xb)
|
| 555 |
+
if use_bf16:
|
| 556 |
+
with torch.autocast(device_type="cuda", dtype=torch.bfloat16):
|
| 557 |
+
logits = fwd(xb, block_mask=bm)
|
| 558 |
+
loss = F.cross_entropy(logits.reshape(-1, logits.shape[-1]), yb.reshape(-1))
|
| 559 |
+
else:
|
| 560 |
+
logits = fwd(xb, block_mask=bm)
|
| 561 |
+
loss = F.cross_entropy(logits.reshape(-1, logits.shape[-1]), yb.reshape(-1))
|
| 562 |
+
(loss / accum).backward()
|
| 563 |
+
grad_norm = float(torch.nn.utils.clip_grad_norm_(model.parameters(), GRAD_CLIP))
|
| 564 |
+
for o in optimizers:
|
| 565 |
+
o.step()
|
| 566 |
+
with torch.no_grad():
|
| 567 |
+
for _n, _p in model.named_parameters():
|
| 568 |
+
if _n in ema_params:
|
| 569 |
+
ema_params[_n].mul_(EMA_DECAY).add_(_p.detach().float(), alpha=1.0 - EMA_DECAY)
|
| 570 |
+
except RuntimeError as exc:
|
| 571 |
+
if "out of memory" in str(exc).lower() and micro > 1:
|
| 572 |
+
micro = max(1, micro // 2)
|
| 573 |
+
accum = max(1, EFFECTIVE_TOKENS_PER_STEP // (micro * block))
|
| 574 |
+
if str(device).startswith("cuda"):
|
| 575 |
+
torch.cuda.empty_cache()
|
| 576 |
+
continue
|
| 577 |
+
raise
|
| 578 |
+
|
| 579 |
+
last = float(loss.item())
|
| 580 |
+
ema = last if step == 0 else (0.98 * ema + 0.02 * last)
|
| 581 |
+
step += 1
|
| 582 |
+
if step == 1 or step % REPORT_EVERY == 0:
|
| 583 |
+
prism_telemetry.report(
|
| 584 |
+
loss=last, step=step, grad_norm=grad_norm,
|
| 585 |
+
layer_stats={"model": {"grad_norm": grad_norm}},
|
| 586 |
+
)
|
| 587 |
+
if step == 1 or step % 100 == 0:
|
| 588 |
+
print(f"[train] step {step}/{max_steps} loss {last:.3f} ema {ema:.3f} lr {lr:.2e} "
|
| 589 |
+
f"gnorm {grad_norm:.2f} t {time.time()-t0:.0f}s", file=sys.stderr, flush=True)
|
| 590 |
+
if val_ids and (step == 1 or step % 1000 == 0):
|
| 591 |
+
try:
|
| 592 |
+
model.eval()
|
| 593 |
+
vloss = []
|
| 594 |
+
with torch.no_grad():
|
| 595 |
+
for _ids in val_ids:
|
| 596 |
+
_i = _ids.to(device).unsqueeze(0)
|
| 597 |
+
if use_bf16:
|
| 598 |
+
with torch.autocast(device_type="cuda", dtype=torch.bfloat16):
|
| 599 |
+
_lg = model(_i[:, :-1])
|
| 600 |
+
_tg = _i[:, 1:][:, -_lg.shape[1]:]
|
| 601 |
+
_l = F.cross_entropy(_lg.reshape(-1, _lg.shape[-1]).float(), _tg.reshape(-1))
|
| 602 |
+
else:
|
| 603 |
+
_lg = model(_i[:, :-1])
|
| 604 |
+
_tg = _i[:, 1:][:, -_lg.shape[1]:]
|
| 605 |
+
_l = F.cross_entropy(_lg.reshape(-1, _lg.shape[-1]), _tg.reshape(-1))
|
| 606 |
+
vloss.append(float(_l))
|
| 607 |
+
model.train()
|
| 608 |
+
_ce = sum(vloss) / max(1, len(vloss))
|
| 609 |
+
print(f"[val] step {step} val_ce {_ce:.4f} bpb {_ce/0.6931471805599453:.4f} "
|
| 610 |
+
f"(top 4.2881) t {time.time()-t0:.0f}s", file=sys.stderr, flush=True)
|
| 611 |
+
except Exception:
|
| 612 |
+
model.train()
|
| 613 |
+
|
| 614 |
+
with torch.no_grad():
|
| 615 |
+
for _n, _p in model.named_parameters():
|
| 616 |
+
if _n in ema_params:
|
| 617 |
+
_p.copy_(ema_params[_n].to(_p.dtype))
|
| 618 |
+
prism_telemetry.report(loss=last, step=step, grad_norm=0.0)
|
| 619 |
+
prism_telemetry.finish_evaluation()
|
| 620 |
+
return {"train_loss": last, "train_steps": step, "train_seconds": time.time() - t0}
|