Datasets:
Rebuild from main c483b866: T4 Triton auto-disable, bf16 source auto-detect
Browse files- kit_manifest.json +19 -10
- lanes/README.md +40 -0
- lanes/balanced-h-08b.json +3 -2
- lanes/clean-suite-08b.json +14 -4
- lanes/robustness-08b-shard1of3.json +103 -0
- lanes/robustness-08b-shard2of3.json +103 -0
- lanes/robustness-08b-shard3of3.json +103 -0
- lanes/smoke-08b.json +6 -2
- scripts/ag_fetch.py +160 -0
- scripts/build_kit.py +15 -1
- scripts/combine_lane_manifests.py +127 -0
- scripts/eval_generation.py +231 -0
- scripts/eval_quantized.py +24 -0
- scripts/make_qad_dataset.py +219 -0
- scripts/make_sweep_spec.py +117 -0
- scripts/merge_language_hessians.py +23 -1
- scripts/pull_results.py +119 -0
- scripts/qad_finetune.py +27 -3
- scripts/run_lane.py +106 -3
kit_manifest.json
CHANGED
|
@@ -1,24 +1,30 @@
|
|
| 1 |
{
|
| 2 |
-
"built_from_commit": "
|
| 3 |
"files": {
|
| 4 |
"scripts/rht_int4_convert.py": "c27bec9abcca8ab673f6b1e1a1252d5fb5562c1cdc57be4d7023ccc6844a79ce",
|
| 5 |
"scripts/rewrite_lalamo_hybrid_spec.py": "154564c88391f81b5c24f64125d99abc15d81bd082a8264e36d43a00d4c47a04",
|
| 6 |
"scripts/normalize_lalamo_config.py": "248a5a07d0829c9e383eeba1a5204e88abdc065f78737d1191d376a1f37476c4",
|
| 7 |
"scripts/make_lalamo_eval_copy.py": "5563e8542ef51e57cc6ed5cff48fcc81d58fb6487d75350df8273cfad948a500",
|
| 8 |
"scripts/yaqa_calibration.py": "4fdf85cfbd3266d9b080cbc3d7663dd3adc27e951a53e211d51874654b2ddd7d",
|
| 9 |
-
"scripts/merge_language_hessians.py": "
|
| 10 |
"scripts/merge_calibration_groups.py": "58a347ff40c47f629c073c23aea54e215c1e75c052737e5b4a48ff81946d8060",
|
| 11 |
-
"scripts/eval_quantized.py": "
|
| 12 |
-
"scripts/qad_finetune.py": "
|
| 13 |
"scripts/compute_bpc.py": "2b55fd1df406d54b40daeeca2ecaf2efb35981655f5bf5e0cc10c057ce796256",
|
| 14 |
-
"scripts/run_lane.py": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
"scripts/corpus_guard.py": "5f226a81988acaebd80b8b81dfb4207ed8b661e52067b0260deec6ee48e9af6a",
|
| 16 |
"scripts/dedup_lines.py": "d7caa00dc29f0ba48bc1bdac675e2ed5d81f0514d5d9df17a8f5b2017e6ea8d4",
|
| 17 |
"scripts/dedup_calibration.py": "62ecc3c3921d307048c9e3547026634b616110115baf561f74dfb74c91e89b7d",
|
| 18 |
"scripts/check_experiment.py": "a2e7e40909f68031dfccd7013ed055dfbc0ebb21f2a619622b71e6772c685ca5",
|
| 19 |
"scripts/tiny_sharding_probe.py": "29eb58f2689242b919616f6aab6ff753e0de031b16371137975b4d645e836fae",
|
| 20 |
"scripts/audit_public_corpus.py": "84f1ec805a74004e71f63a70a8ed19967cb3fad9966f254798e655ab95e53ab0",
|
| 21 |
-
"scripts/build_kit.py": "
|
| 22 |
"scripts/bootstrap_kaggle.py": "1633e3edbb80976c337444e3e4544e2b5210b2d8d1821e3a2717c1099c00843e",
|
| 23 |
"data/calibration_en_wikitext2_dedup.txt": "18a79f4f938cc25747a90a12b120c7131e7f4ac55b58dfc691795ea61d4b5e9a",
|
| 24 |
"data/calibration_ja_wikipedia_dedup.txt": "b45e3f3f00f2137be280a75c1fa9c9883a7e69d289257c4388fc701f33fee0d1",
|
|
@@ -27,10 +33,13 @@
|
|
| 27 |
"data/calibration_mixed_ja65_en35_dedup.txt": "36e17429433759bbad53cf62dbca2d880abe716d60b3bb32fc7b7ca96bb093e1",
|
| 28 |
"data/eval_en_wikitext2_dedup.txt": "342e8f6a77fb9db7e1a14aa7cabe13c1f13eeaa4f045f8fb3689c0b26c742c0e",
|
| 29 |
"data/eval_ja_wikipedia_dedup.txt": "707c9a6c951dd0b831c746a5d6e6972e4dbc71498e75c4aa8f12140eeed89213",
|
| 30 |
-
"lanes/README.md": "
|
| 31 |
-
"lanes/smoke-08b.json": "
|
| 32 |
-
"lanes/clean-suite-08b.json": "
|
| 33 |
-
"lanes/balanced-h-08b.json": "
|
|
|
|
|
|
|
|
|
|
| 34 |
"tests/test_experiment_guards.py": "d71ddf9586c1d7ece52e217288b9d4b09079be54d32ceaf391be113c1832b6ef",
|
| 35 |
"tests/test_compute_bpc.py": "bba5b6d0afc9b0699ebb6f7f0ed9fc5ebfcb98472867e9ccff4262fe9999949f",
|
| 36 |
"tests/test_run_lane.py": "fe5b613a31f217fbb71e5ff33aaa4975f65ca22f36024e224d0eff6fd05a80c0",
|
|
|
|
| 1 |
{
|
| 2 |
+
"built_from_commit": "c483b866a0d0528b4a0adebb44027e77de0d2c89",
|
| 3 |
"files": {
|
| 4 |
"scripts/rht_int4_convert.py": "c27bec9abcca8ab673f6b1e1a1252d5fb5562c1cdc57be4d7023ccc6844a79ce",
|
| 5 |
"scripts/rewrite_lalamo_hybrid_spec.py": "154564c88391f81b5c24f64125d99abc15d81bd082a8264e36d43a00d4c47a04",
|
| 6 |
"scripts/normalize_lalamo_config.py": "248a5a07d0829c9e383eeba1a5204e88abdc065f78737d1191d376a1f37476c4",
|
| 7 |
"scripts/make_lalamo_eval_copy.py": "5563e8542ef51e57cc6ed5cff48fcc81d58fb6487d75350df8273cfad948a500",
|
| 8 |
"scripts/yaqa_calibration.py": "4fdf85cfbd3266d9b080cbc3d7663dd3adc27e951a53e211d51874654b2ddd7d",
|
| 9 |
+
"scripts/merge_language_hessians.py": "a6385caaa0d7190024b4e47ded59d1ab662e771ce81e18de94b30c8846829b4e",
|
| 10 |
"scripts/merge_calibration_groups.py": "58a347ff40c47f629c073c23aea54e215c1e75c052737e5b4a48ff81946d8060",
|
| 11 |
+
"scripts/eval_quantized.py": "60200dfb9ad65857642e18fed10ac092853cf2c2addabe81b398e425d91bfe6e",
|
| 12 |
+
"scripts/qad_finetune.py": "4f639ac8e266cf09051c713fba9d87703b8f43c660c14e089f3b0e64d97a5ad7",
|
| 13 |
"scripts/compute_bpc.py": "2b55fd1df406d54b40daeeca2ecaf2efb35981655f5bf5e0cc10c057ce796256",
|
| 14 |
+
"scripts/run_lane.py": "73dff4a4099211edba03a3de5f30416a9b456eb62a79c9faaf89fbc41721a481",
|
| 15 |
+
"scripts/make_sweep_spec.py": "dc31ec026c89e7db316a185575a4423bca988c2ac6cf08ef6df8f955328cda69",
|
| 16 |
+
"scripts/combine_lane_manifests.py": "164ba691d60b3e2987b805426c606d135dcf3cf0c855b38cf7f5d6d57628a481",
|
| 17 |
+
"scripts/make_qad_dataset.py": "18e91221c5ac1b07362dd6978956168ed1148a3c6e8f73e0a2efc3f1f4047634",
|
| 18 |
+
"scripts/ag_fetch.py": "ba8c9e5d8a4fceb41695a5483a967b0d3bda75a3759b311cb7441bc22f31dd2e",
|
| 19 |
+
"scripts/eval_generation.py": "bc240aef06c6ede583c3334fd0483ca9153ca07a52e22ef53c85c0b4fb90f7d2",
|
| 20 |
+
"scripts/pull_results.py": "e5873cfda71dcebcf86e1ecfaacefc9bf01a142521d06c065654eaea7d07de5c",
|
| 21 |
"scripts/corpus_guard.py": "5f226a81988acaebd80b8b81dfb4207ed8b661e52067b0260deec6ee48e9af6a",
|
| 22 |
"scripts/dedup_lines.py": "d7caa00dc29f0ba48bc1bdac675e2ed5d81f0514d5d9df17a8f5b2017e6ea8d4",
|
| 23 |
"scripts/dedup_calibration.py": "62ecc3c3921d307048c9e3547026634b616110115baf561f74dfb74c91e89b7d",
|
| 24 |
"scripts/check_experiment.py": "a2e7e40909f68031dfccd7013ed055dfbc0ebb21f2a619622b71e6772c685ca5",
|
| 25 |
"scripts/tiny_sharding_probe.py": "29eb58f2689242b919616f6aab6ff753e0de031b16371137975b4d645e836fae",
|
| 26 |
"scripts/audit_public_corpus.py": "84f1ec805a74004e71f63a70a8ed19967cb3fad9966f254798e655ab95e53ab0",
|
| 27 |
+
"scripts/build_kit.py": "b7f2f5ec352e23dc0b2dac604b4f709bff8bcf7e4b94d537eab6e5f15eda8a9e",
|
| 28 |
"scripts/bootstrap_kaggle.py": "1633e3edbb80976c337444e3e4544e2b5210b2d8d1821e3a2717c1099c00843e",
|
| 29 |
"data/calibration_en_wikitext2_dedup.txt": "18a79f4f938cc25747a90a12b120c7131e7f4ac55b58dfc691795ea61d4b5e9a",
|
| 30 |
"data/calibration_ja_wikipedia_dedup.txt": "b45e3f3f00f2137be280a75c1fa9c9883a7e69d289257c4388fc701f33fee0d1",
|
|
|
|
| 33 |
"data/calibration_mixed_ja65_en35_dedup.txt": "36e17429433759bbad53cf62dbca2d880abe716d60b3bb32fc7b7ca96bb093e1",
|
| 34 |
"data/eval_en_wikitext2_dedup.txt": "342e8f6a77fb9db7e1a14aa7cabe13c1f13eeaa4f045f8fb3689c0b26c742c0e",
|
| 35 |
"data/eval_ja_wikipedia_dedup.txt": "707c9a6c951dd0b831c746a5d6e6972e4dbc71498e75c4aa8f12140eeed89213",
|
| 36 |
+
"lanes/README.md": "ad36c1790453ca41e32d393be11b76aba7fc204d836705a3b3a3c910dae33cb2",
|
| 37 |
+
"lanes/smoke-08b.json": "de6e66bf9c37325c6efb0c5a37f3b4edb7df500a27a481b24337ddad3df916ee",
|
| 38 |
+
"lanes/clean-suite-08b.json": "a1b74a5f2b7a36edc3fe060ec071df27bcbafe7975fd46ba3562b77458d94b99",
|
| 39 |
+
"lanes/balanced-h-08b.json": "21a16d50b0b5096843e0a8fb944a6fdbb7314f3c2c51618eb9651a7575192cb8",
|
| 40 |
+
"lanes/robustness-08b-shard1of3.json": "11bd73ddfb110c60420546e1c6f47d777ce6d8c321cf31ce5003d15c96743b9b",
|
| 41 |
+
"lanes/robustness-08b-shard2of3.json": "3196a32cf56eb1e3792a4f15a29effa561ff0472d82282f5e98ad8e283249935",
|
| 42 |
+
"lanes/robustness-08b-shard3of3.json": "3f6928c34d3145d7d17eda991e6dede3695a0e9b723fbf4c068a6c07bc9cfd17",
|
| 43 |
"tests/test_experiment_guards.py": "d71ddf9586c1d7ece52e217288b9d4b09079be54d32ceaf391be113c1832b6ef",
|
| 44 |
"tests/test_compute_bpc.py": "bba5b6d0afc9b0699ebb6f7f0ed9fc5ebfcb98472867e9ccff4262fe9999949f",
|
| 45 |
"tests/test_run_lane.py": "fe5b613a31f217fbb71e5ff33aaa4975f65ca22f36024e224d0eff6fd05a80c0",
|
lanes/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
# Lane specs
|
| 2 |
|
|
|
|
|
|
|
| 3 |
実験をデータとして定義する。owner が spec を書き、Kaggle 実行担当は `run_lane.py` を回すだけ。
|
| 4 |
|
| 5 |
```bash
|
|
@@ -16,6 +18,9 @@ python scripts/run_lane.py --spec lanes/clean-suite-08b.json --hf-results <user>
|
|
| 16 |
| `model.spec_name` / `model.hf_repo` | BF16 が無い時の import 元 |
|
| 17 |
| `model.bf16_dir` | BF16 lalamo の場所(`kit/` 相対 or 絶対) |
|
| 18 |
| `model.bf16_source` | BF16 をコピーしてくる場所(Kaggle dataset など) |
|
|
|
|
|
|
|
|
|
|
| 19 |
| `paths.kit` | スクリプトとコーパスのルート |
|
| 20 |
| `paths.work` | 出力ルート。`--work` で上書き可 |
|
| 21 |
| `paths.jax_platform` | `cpu` / `gpu`。`JAX_PLATFORM_NAME` に渡す |
|
|
@@ -40,6 +45,41 @@ python scripts/run_lane.py --spec lanes/clean-suite-08b.json --hf-results <user>
|
|
| 40 |
- `bf16_ppl` が無い
|
| 41 |
- 検証に落ちたら exit 1。manifest は残る
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
## 既存
|
| 44 |
|
| 45 |
| spec | 内容 |
|
|
|
|
| 1 |
# Lane specs
|
| 2 |
|
| 3 |
+
> ここに書いた処理はモデルをロードする。**ローカルで流さない**。手順は `docs/LOCAL_POLICY.md`。
|
| 4 |
+
|
| 5 |
実験をデータとして定義する。owner が spec を書き、Kaggle 実行担当は `run_lane.py` を回すだけ。
|
| 6 |
|
| 7 |
```bash
|
|
|
|
| 18 |
| `model.spec_name` / `model.hf_repo` | BF16 が無い時の import 元 |
|
| 19 |
| `model.bf16_dir` | BF16 lalamo の場所(`kit/` 相対 or 絶対) |
|
| 20 |
| `model.bf16_source` | BF16 をコピーしてくる場所(Kaggle dataset など) |
|
| 21 |
+
| `model.bf16_source_auto` | パスが見つからないとき `/kaggle/input` 配下を探す。Kaggle のマウントレイアウト変更に耐える |
|
| 22 |
+
| `paths.env` | 子プロセスに渡す環境変数 |
|
| 23 |
+
| `paths.xla_flags` | `XLA_FLAGS` に追加するフラグ |
|
| 24 |
| `paths.kit` | スクリプトとコーパスのルート |
|
| 25 |
| `paths.work` | 出力ルート。`--work` で上書き可 |
|
| 26 |
| `paths.jax_platform` | `cpu` / `gpu`。`JAX_PLATFORM_NAME` に渡す |
|
|
|
|
| 45 |
- `bf16_ppl` が無い
|
| 46 |
- 検証に落ちたら exit 1。manifest は残る
|
| 47 |
|
| 48 |
+
## GPU の Triton 対応
|
| 49 |
+
|
| 50 |
+
T4(compute capability 7.5)では XLA の Triton GEMM が使えず、calibration の最初の forward で落ちる。
|
| 51 |
+
`run_lane` は起動時に `nvidia-smi` を読み、**cc < 8.0 を検出したら自動で** `--xla_gpu_enable_triton_gemm=false` を子プロセスの `XLA_FLAGS` に足す。
|
| 52 |
+
|
| 53 |
+
- Ampere 以上では何もしない(性能を落とさない)
|
| 54 |
+
- 明示的に足したい場合は `paths.xla_flags` に書く
|
| 55 |
+
- 検出できなかった場合は何も足さない。その場合は spec に書く
|
| 56 |
+
|
| 57 |
+
## シャード実行
|
| 58 |
+
|
| 59 |
+
1 セッション 12h を跨ぐ条件列は、spec を分けるか `--shard` で切る。
|
| 60 |
+
|
| 61 |
+
```bash
|
| 62 |
+
python scripts/run_lane.py --spec lanes/clean-suite-08b.json --shard 0/3
|
| 63 |
+
# lane 名は clean-suite-08b-shard1of3 になる
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
- `--shard i/n` は条件を `position % n == i` で抜く
|
| 67 |
+
- `spec.merge` と併用不可(merge は分割できない)
|
| 68 |
+
- 各シャードは別 lane ディレクトリなので、終わったシャードは resume で skip される
|
| 69 |
+
|
| 70 |
+
## スイープ spec の生成
|
| 71 |
+
|
| 72 |
+
27 条件(samples × seq × damping)を 3 シャードに分ける。
|
| 73 |
+
|
| 74 |
+
```bash
|
| 75 |
+
python scripts/make_sweep_spec.py --base lanes/clean-suite-08b.json --out-dir lanes \
|
| 76 |
+
--name robustness-08b --corpus data/calibration_mixed_en_ja_dedup.txt \
|
| 77 |
+
--samples 16 32 64 --seq 128 256 512 --damping 1e-4 1e-3 1e-2 --shards 3
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
生成物: `lanes/robustness-08b-shard{1,2,3}of3.json`(各 9 条件)。
|
| 81 |
+
条件名は `s32_q128_d1e-4` 形式。
|
| 82 |
+
|
| 83 |
## 既存
|
| 84 |
|
| 85 |
| spec | 内容 |
|
lanes/balanced-h-08b.json
CHANGED
|
@@ -4,7 +4,8 @@
|
|
| 4 |
"hf_repo": "Qwen/Qwen3.5-0.8B",
|
| 5 |
"spec_name": "Qwen3.5-0.8B",
|
| 6 |
"bf16_dir": "bf16-lalamo",
|
| 7 |
-
"bf16_source": "/kaggle/input/uzu-bf16-08b-lalamo"
|
|
|
|
| 8 |
},
|
| 9 |
"paths": {
|
| 10 |
"kit": "kit",
|
|
@@ -59,4 +60,4 @@
|
|
| 59 |
"damping": 0.001,
|
| 60 |
"name_template": "balanced-{ratio}"
|
| 61 |
}
|
| 62 |
-
}
|
|
|
|
| 4 |
"hf_repo": "Qwen/Qwen3.5-0.8B",
|
| 5 |
"spec_name": "Qwen3.5-0.8B",
|
| 6 |
"bf16_dir": "bf16-lalamo",
|
| 7 |
+
"bf16_source": "/kaggle/input/uzu-bf16-08b-lalamo",
|
| 8 |
+
"bf16_source_auto": true
|
| 9 |
},
|
| 10 |
"paths": {
|
| 11 |
"kit": "kit",
|
|
|
|
| 60 |
"damping": 0.001,
|
| 61 |
"name_template": "balanced-{ratio}"
|
| 62 |
}
|
| 63 |
+
}
|
lanes/clean-suite-08b.json
CHANGED
|
@@ -4,7 +4,8 @@
|
|
| 4 |
"hf_repo": "Qwen/Qwen3.5-0.8B",
|
| 5 |
"spec_name": "Qwen3.5-0.8B",
|
| 6 |
"bf16_dir": "bf16-lalamo",
|
| 7 |
-
"bf16_source": "/kaggle/input/uzu-bf16-08b-lalamo"
|
|
|
|
| 8 |
},
|
| 9 |
"paths": {
|
| 10 |
"kit": "kit",
|
|
@@ -35,8 +36,17 @@
|
|
| 35 |
"parallel": "tensor"
|
| 36 |
},
|
| 37 |
"conditions": [
|
| 38 |
-
{
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
]
|
| 42 |
}
|
|
|
|
| 4 |
"hf_repo": "Qwen/Qwen3.5-0.8B",
|
| 5 |
"spec_name": "Qwen3.5-0.8B",
|
| 6 |
"bf16_dir": "bf16-lalamo",
|
| 7 |
+
"bf16_source": "/kaggle/input/uzu-bf16-08b-lalamo",
|
| 8 |
+
"bf16_source_auto": true
|
| 9 |
},
|
| 10 |
"paths": {
|
| 11 |
"kit": "kit",
|
|
|
|
| 36 |
"parallel": "tensor"
|
| 37 |
},
|
| 38 |
"conditions": [
|
| 39 |
+
{
|
| 40 |
+
"name": "mix65",
|
| 41 |
+
"calibration_corpus": "data/calibration_mixed_ja65_en35_dedup.txt"
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"name": "mix35",
|
| 45 |
+
"calibration_corpus": "data/calibration_mixed_ja35_en65_dedup.txt"
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"name": "jaonly",
|
| 49 |
+
"calibration_corpus": "data/calibration_ja_wikipedia_dedup.txt"
|
| 50 |
+
}
|
| 51 |
]
|
| 52 |
}
|
lanes/robustness-08b-shard1of3.json
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"lane": "robustness-08b-shard1of3",
|
| 3 |
+
"model": {
|
| 4 |
+
"hf_repo": "Qwen/Qwen3.5-0.8B",
|
| 5 |
+
"spec_name": "Qwen3.5-0.8B",
|
| 6 |
+
"bf16_dir": "bf16-lalamo",
|
| 7 |
+
"bf16_source": "/kaggle/input/uzu-bf16-08b-lalamo",
|
| 8 |
+
"bf16_source_auto": true
|
| 9 |
+
},
|
| 10 |
+
"paths": {
|
| 11 |
+
"kit": "kit",
|
| 12 |
+
"work": "/kaggle/working",
|
| 13 |
+
"jax_platform": "gpu"
|
| 14 |
+
},
|
| 15 |
+
"eval": {
|
| 16 |
+
"max_sequences": 100,
|
| 17 |
+
"max_tokens": 128,
|
| 18 |
+
"min_tokens": 16,
|
| 19 |
+
"corpora": {
|
| 20 |
+
"en": "data/eval_en_wikitext2_dedup.txt",
|
| 21 |
+
"ja": "data/eval_ja_wikipedia_dedup.txt"
|
| 22 |
+
}
|
| 23 |
+
},
|
| 24 |
+
"condition_defaults": {
|
| 25 |
+
"samples": 32,
|
| 26 |
+
"max_tokens": 128,
|
| 27 |
+
"output_block": "small",
|
| 28 |
+
"output_block_limit": 2048,
|
| 29 |
+
"damping": 0.001,
|
| 30 |
+
"raw_output": false
|
| 31 |
+
},
|
| 32 |
+
"convert": {
|
| 33 |
+
"bits": 4,
|
| 34 |
+
"group_size": 32,
|
| 35 |
+
"block_size": 32,
|
| 36 |
+
"parallel": "tensor"
|
| 37 |
+
},
|
| 38 |
+
"conditions": [
|
| 39 |
+
{
|
| 40 |
+
"name": "s16_q128_d1e-4",
|
| 41 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 42 |
+
"samples": 16,
|
| 43 |
+
"max_tokens": 128,
|
| 44 |
+
"damping": 0.0001
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"name": "s16_q256_d1e-4",
|
| 48 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 49 |
+
"samples": 16,
|
| 50 |
+
"max_tokens": 256,
|
| 51 |
+
"damping": 0.0001
|
| 52 |
+
},
|
| 53 |
+
{
|
| 54 |
+
"name": "s16_q512_d1e-4",
|
| 55 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 56 |
+
"samples": 16,
|
| 57 |
+
"max_tokens": 512,
|
| 58 |
+
"damping": 0.0001
|
| 59 |
+
},
|
| 60 |
+
{
|
| 61 |
+
"name": "s32_q128_d1e-4",
|
| 62 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 63 |
+
"samples": 32,
|
| 64 |
+
"max_tokens": 128,
|
| 65 |
+
"damping": 0.0001
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"name": "s32_q256_d1e-4",
|
| 69 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 70 |
+
"samples": 32,
|
| 71 |
+
"max_tokens": 256,
|
| 72 |
+
"damping": 0.0001
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"name": "s32_q512_d1e-4",
|
| 76 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 77 |
+
"samples": 32,
|
| 78 |
+
"max_tokens": 512,
|
| 79 |
+
"damping": 0.0001
|
| 80 |
+
},
|
| 81 |
+
{
|
| 82 |
+
"name": "s64_q128_d1e-4",
|
| 83 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 84 |
+
"samples": 64,
|
| 85 |
+
"max_tokens": 128,
|
| 86 |
+
"damping": 0.0001
|
| 87 |
+
},
|
| 88 |
+
{
|
| 89 |
+
"name": "s64_q256_d1e-4",
|
| 90 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 91 |
+
"samples": 64,
|
| 92 |
+
"max_tokens": 256,
|
| 93 |
+
"damping": 0.0001
|
| 94 |
+
},
|
| 95 |
+
{
|
| 96 |
+
"name": "s64_q512_d1e-4",
|
| 97 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 98 |
+
"samples": 64,
|
| 99 |
+
"max_tokens": 512,
|
| 100 |
+
"damping": 0.0001
|
| 101 |
+
}
|
| 102 |
+
]
|
| 103 |
+
}
|
lanes/robustness-08b-shard2of3.json
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"lane": "robustness-08b-shard2of3",
|
| 3 |
+
"model": {
|
| 4 |
+
"hf_repo": "Qwen/Qwen3.5-0.8B",
|
| 5 |
+
"spec_name": "Qwen3.5-0.8B",
|
| 6 |
+
"bf16_dir": "bf16-lalamo",
|
| 7 |
+
"bf16_source": "/kaggle/input/uzu-bf16-08b-lalamo",
|
| 8 |
+
"bf16_source_auto": true
|
| 9 |
+
},
|
| 10 |
+
"paths": {
|
| 11 |
+
"kit": "kit",
|
| 12 |
+
"work": "/kaggle/working",
|
| 13 |
+
"jax_platform": "gpu"
|
| 14 |
+
},
|
| 15 |
+
"eval": {
|
| 16 |
+
"max_sequences": 100,
|
| 17 |
+
"max_tokens": 128,
|
| 18 |
+
"min_tokens": 16,
|
| 19 |
+
"corpora": {
|
| 20 |
+
"en": "data/eval_en_wikitext2_dedup.txt",
|
| 21 |
+
"ja": "data/eval_ja_wikipedia_dedup.txt"
|
| 22 |
+
}
|
| 23 |
+
},
|
| 24 |
+
"condition_defaults": {
|
| 25 |
+
"samples": 32,
|
| 26 |
+
"max_tokens": 128,
|
| 27 |
+
"output_block": "small",
|
| 28 |
+
"output_block_limit": 2048,
|
| 29 |
+
"damping": 0.001,
|
| 30 |
+
"raw_output": false
|
| 31 |
+
},
|
| 32 |
+
"convert": {
|
| 33 |
+
"bits": 4,
|
| 34 |
+
"group_size": 32,
|
| 35 |
+
"block_size": 32,
|
| 36 |
+
"parallel": "tensor"
|
| 37 |
+
},
|
| 38 |
+
"conditions": [
|
| 39 |
+
{
|
| 40 |
+
"name": "s16_q128_d1e-3",
|
| 41 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 42 |
+
"samples": 16,
|
| 43 |
+
"max_tokens": 128,
|
| 44 |
+
"damping": 0.001
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"name": "s16_q256_d1e-3",
|
| 48 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 49 |
+
"samples": 16,
|
| 50 |
+
"max_tokens": 256,
|
| 51 |
+
"damping": 0.001
|
| 52 |
+
},
|
| 53 |
+
{
|
| 54 |
+
"name": "s16_q512_d1e-3",
|
| 55 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 56 |
+
"samples": 16,
|
| 57 |
+
"max_tokens": 512,
|
| 58 |
+
"damping": 0.001
|
| 59 |
+
},
|
| 60 |
+
{
|
| 61 |
+
"name": "s32_q128_d1e-3",
|
| 62 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 63 |
+
"samples": 32,
|
| 64 |
+
"max_tokens": 128,
|
| 65 |
+
"damping": 0.001
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"name": "s32_q256_d1e-3",
|
| 69 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 70 |
+
"samples": 32,
|
| 71 |
+
"max_tokens": 256,
|
| 72 |
+
"damping": 0.001
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"name": "s32_q512_d1e-3",
|
| 76 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 77 |
+
"samples": 32,
|
| 78 |
+
"max_tokens": 512,
|
| 79 |
+
"damping": 0.001
|
| 80 |
+
},
|
| 81 |
+
{
|
| 82 |
+
"name": "s64_q128_d1e-3",
|
| 83 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 84 |
+
"samples": 64,
|
| 85 |
+
"max_tokens": 128,
|
| 86 |
+
"damping": 0.001
|
| 87 |
+
},
|
| 88 |
+
{
|
| 89 |
+
"name": "s64_q256_d1e-3",
|
| 90 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 91 |
+
"samples": 64,
|
| 92 |
+
"max_tokens": 256,
|
| 93 |
+
"damping": 0.001
|
| 94 |
+
},
|
| 95 |
+
{
|
| 96 |
+
"name": "s64_q512_d1e-3",
|
| 97 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 98 |
+
"samples": 64,
|
| 99 |
+
"max_tokens": 512,
|
| 100 |
+
"damping": 0.001
|
| 101 |
+
}
|
| 102 |
+
]
|
| 103 |
+
}
|
lanes/robustness-08b-shard3of3.json
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"lane": "robustness-08b-shard3of3",
|
| 3 |
+
"model": {
|
| 4 |
+
"hf_repo": "Qwen/Qwen3.5-0.8B",
|
| 5 |
+
"spec_name": "Qwen3.5-0.8B",
|
| 6 |
+
"bf16_dir": "bf16-lalamo",
|
| 7 |
+
"bf16_source": "/kaggle/input/uzu-bf16-08b-lalamo",
|
| 8 |
+
"bf16_source_auto": true
|
| 9 |
+
},
|
| 10 |
+
"paths": {
|
| 11 |
+
"kit": "kit",
|
| 12 |
+
"work": "/kaggle/working",
|
| 13 |
+
"jax_platform": "gpu"
|
| 14 |
+
},
|
| 15 |
+
"eval": {
|
| 16 |
+
"max_sequences": 100,
|
| 17 |
+
"max_tokens": 128,
|
| 18 |
+
"min_tokens": 16,
|
| 19 |
+
"corpora": {
|
| 20 |
+
"en": "data/eval_en_wikitext2_dedup.txt",
|
| 21 |
+
"ja": "data/eval_ja_wikipedia_dedup.txt"
|
| 22 |
+
}
|
| 23 |
+
},
|
| 24 |
+
"condition_defaults": {
|
| 25 |
+
"samples": 32,
|
| 26 |
+
"max_tokens": 128,
|
| 27 |
+
"output_block": "small",
|
| 28 |
+
"output_block_limit": 2048,
|
| 29 |
+
"damping": 0.001,
|
| 30 |
+
"raw_output": false
|
| 31 |
+
},
|
| 32 |
+
"convert": {
|
| 33 |
+
"bits": 4,
|
| 34 |
+
"group_size": 32,
|
| 35 |
+
"block_size": 32,
|
| 36 |
+
"parallel": "tensor"
|
| 37 |
+
},
|
| 38 |
+
"conditions": [
|
| 39 |
+
{
|
| 40 |
+
"name": "s16_q128_d1e-2",
|
| 41 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 42 |
+
"samples": 16,
|
| 43 |
+
"max_tokens": 128,
|
| 44 |
+
"damping": 0.01
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"name": "s16_q256_d1e-2",
|
| 48 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 49 |
+
"samples": 16,
|
| 50 |
+
"max_tokens": 256,
|
| 51 |
+
"damping": 0.01
|
| 52 |
+
},
|
| 53 |
+
{
|
| 54 |
+
"name": "s16_q512_d1e-2",
|
| 55 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 56 |
+
"samples": 16,
|
| 57 |
+
"max_tokens": 512,
|
| 58 |
+
"damping": 0.01
|
| 59 |
+
},
|
| 60 |
+
{
|
| 61 |
+
"name": "s32_q128_d1e-2",
|
| 62 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 63 |
+
"samples": 32,
|
| 64 |
+
"max_tokens": 128,
|
| 65 |
+
"damping": 0.01
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"name": "s32_q256_d1e-2",
|
| 69 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 70 |
+
"samples": 32,
|
| 71 |
+
"max_tokens": 256,
|
| 72 |
+
"damping": 0.01
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"name": "s32_q512_d1e-2",
|
| 76 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 77 |
+
"samples": 32,
|
| 78 |
+
"max_tokens": 512,
|
| 79 |
+
"damping": 0.01
|
| 80 |
+
},
|
| 81 |
+
{
|
| 82 |
+
"name": "s64_q128_d1e-2",
|
| 83 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 84 |
+
"samples": 64,
|
| 85 |
+
"max_tokens": 128,
|
| 86 |
+
"damping": 0.01
|
| 87 |
+
},
|
| 88 |
+
{
|
| 89 |
+
"name": "s64_q256_d1e-2",
|
| 90 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 91 |
+
"samples": 64,
|
| 92 |
+
"max_tokens": 256,
|
| 93 |
+
"damping": 0.01
|
| 94 |
+
},
|
| 95 |
+
{
|
| 96 |
+
"name": "s64_q512_d1e-2",
|
| 97 |
+
"calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt",
|
| 98 |
+
"samples": 64,
|
| 99 |
+
"max_tokens": 512,
|
| 100 |
+
"damping": 0.01
|
| 101 |
+
}
|
| 102 |
+
]
|
| 103 |
+
}
|
lanes/smoke-08b.json
CHANGED
|
@@ -5,7 +5,8 @@
|
|
| 5 |
"spec_name": "Qwen3.5-0.8B",
|
| 6 |
"bf16_dir": "bf16-lalamo",
|
| 7 |
"bf16_source": "/kaggle/input/uzu-bf16-08b-lalamo",
|
| 8 |
-
"bf16_raw_dir": "bf16-raw"
|
|
|
|
| 9 |
},
|
| 10 |
"paths": {
|
| 11 |
"kit": "kit",
|
|
@@ -36,6 +37,9 @@
|
|
| 36 |
"parallel": "tensor"
|
| 37 |
},
|
| 38 |
"conditions": [
|
| 39 |
-
{
|
|
|
|
|
|
|
|
|
|
| 40 |
]
|
| 41 |
}
|
|
|
|
| 5 |
"spec_name": "Qwen3.5-0.8B",
|
| 6 |
"bf16_dir": "bf16-lalamo",
|
| 7 |
"bf16_source": "/kaggle/input/uzu-bf16-08b-lalamo",
|
| 8 |
+
"bf16_raw_dir": "bf16-raw",
|
| 9 |
+
"bf16_source_auto": true
|
| 10 |
},
|
| 11 |
"paths": {
|
| 12 |
"kit": "kit",
|
|
|
|
| 37 |
"parallel": "tensor"
|
| 38 |
},
|
| 39 |
"conditions": [
|
| 40 |
+
{
|
| 41 |
+
"name": "mix65",
|
| 42 |
+
"calibration_corpus": "data/calibration_mixed_ja65_en35_dedup.txt"
|
| 43 |
+
}
|
| 44 |
]
|
| 45 |
}
|
scripts/ag_fetch.py
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Fetch Antigravity sandbox artifacts with retries and a log-based fallback.
|
| 3 |
+
|
| 4 |
+
``fetch`` regularly fails with HTTP 503 "Environment snapshot is temporarily
|
| 5 |
+
unavailable". It is transient: the same session usually fetches fine a minute
|
| 6 |
+
later. This wrapper retries with exponential backoff and, if the snapshot never
|
| 7 |
+
comes back, recovers the agent's final message from the run log so the analysis
|
| 8 |
+
is not lost.
|
| 9 |
+
|
| 10 |
+
Usage:
|
| 11 |
+
python scripts/ag_fetch.py --state /tmp/ag_task.json --out /tmp/ag_task_fetch
|
| 12 |
+
python scripts/ag_fetch.py --state ... --out ... --retries 8 --base-delay 15
|
| 13 |
+
python scripts/ag_fetch.py --log logs/.../antigravity_task.log --out /tmp/ag_task_fetch --recover-only
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
from __future__ import annotations
|
| 17 |
+
|
| 18 |
+
import argparse
|
| 19 |
+
import json
|
| 20 |
+
import random
|
| 21 |
+
import subprocess
|
| 22 |
+
import sys
|
| 23 |
+
import time
|
| 24 |
+
from pathlib import Path
|
| 25 |
+
|
| 26 |
+
DEFAULT_WRAPPER = Path.home() / ".config" / "opencode" / "antigravity" / "antigravity.py"
|
| 27 |
+
|
| 28 |
+
TRANSIENT = (
|
| 29 |
+
"503",
|
| 30 |
+
"UNAVAILABLE",
|
| 31 |
+
"temporarily unavailable",
|
| 32 |
+
"502",
|
| 33 |
+
"504",
|
| 34 |
+
"deadline",
|
| 35 |
+
"timeout",
|
| 36 |
+
"connection reset",
|
| 37 |
+
"ECONNRESET",
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def is_transient(output: str) -> bool:
|
| 42 |
+
text = output.lower()
|
| 43 |
+
return any(marker.lower() in text for marker in TRANSIENT)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def json_objects(text: str):
|
| 47 |
+
"""Yield every top-level JSON object embedded in a log, in order."""
|
| 48 |
+
decoder = json.JSONDecoder()
|
| 49 |
+
index = 0
|
| 50 |
+
while True:
|
| 51 |
+
start = text.find("{", index)
|
| 52 |
+
if start < 0:
|
| 53 |
+
return
|
| 54 |
+
try:
|
| 55 |
+
value, end = decoder.raw_decode(text, start)
|
| 56 |
+
except json.JSONDecodeError:
|
| 57 |
+
index = start + 1
|
| 58 |
+
continue
|
| 59 |
+
yield value
|
| 60 |
+
index = end
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def last_final(log_path: Path) -> str | None:
|
| 64 |
+
if not log_path.exists():
|
| 65 |
+
return None
|
| 66 |
+
final = None
|
| 67 |
+
for payload in json_objects(log_path.read_text(encoding="utf-8", errors="replace")):
|
| 68 |
+
if isinstance(payload, dict) and isinstance(payload.get("final"), str) and payload["final"].strip():
|
| 69 |
+
final = payload["final"]
|
| 70 |
+
return final
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def recover_from_log(log_path: Path, out_dir: Path) -> Path | None:
|
| 74 |
+
final = last_final(log_path)
|
| 75 |
+
if not final:
|
| 76 |
+
return None
|
| 77 |
+
target = out_dir / "final.md"
|
| 78 |
+
target.parent.mkdir(parents=True, exist_ok=True)
|
| 79 |
+
target.write_text(final + "\n", encoding="utf-8")
|
| 80 |
+
return target
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def wrapper_fetch(wrapper: Path, state: Path, out_dir: Path) -> tuple[int, str]:
|
| 84 |
+
command = [sys.executable, str(wrapper), "--state", str(state), "fetch", "--out", str(out_dir)]
|
| 85 |
+
process = subprocess.run(command, text=True, capture_output=True, check=False)
|
| 86 |
+
return process.returncode, (process.stdout or "") + (process.stderr or "")
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def fetch_with_retry(
|
| 90 |
+
wrapper: Path,
|
| 91 |
+
state: Path,
|
| 92 |
+
out_dir: Path,
|
| 93 |
+
log_path: Path | None = None,
|
| 94 |
+
retries: int = 6,
|
| 95 |
+
base_delay: float = 15.0,
|
| 96 |
+
max_delay: float = 180.0,
|
| 97 |
+
sleep=time.sleep,
|
| 98 |
+
) -> dict:
|
| 99 |
+
"""Returns {"status": ok|recovered|failed, "attempts": n, "final": path|None}."""
|
| 100 |
+
last_output = ""
|
| 101 |
+
attempts_made = 0
|
| 102 |
+
for attempt in range(1, retries + 1):
|
| 103 |
+
attempts_made = attempt
|
| 104 |
+
code, output = wrapper_fetch(wrapper, state, out_dir)
|
| 105 |
+
last_output = output
|
| 106 |
+
extracted = out_dir / "extracted"
|
| 107 |
+
if code == 0 and extracted.exists():
|
| 108 |
+
return {"status": "ok", "attempts": attempt, "final": None}
|
| 109 |
+
if not is_transient(output) and code != 0:
|
| 110 |
+
print(f"fetch failed with a non-transient error (attempt {attempt}): {output.strip()[:300]}")
|
| 111 |
+
break
|
| 112 |
+
if attempt < retries:
|
| 113 |
+
delay = min(max_delay, base_delay * (2 ** (attempt - 1)))
|
| 114 |
+
delay *= 1 + random.uniform(-0.1, 0.1)
|
| 115 |
+
print(f"fetch attempt {attempt} failed (503/transient); retrying in {delay:.0f}s", flush=True)
|
| 116 |
+
sleep(delay)
|
| 117 |
+
|
| 118 |
+
print("fetch exhausted; trying log-based recovery", flush=True)
|
| 119 |
+
recovered = recover_from_log(log_path, out_dir) if log_path else None
|
| 120 |
+
if recovered:
|
| 121 |
+
print(f"recovered final message from log -> {recovered}", flush=True)
|
| 122 |
+
return {"status": "recovered", "attempts": attempts_made, "final": str(recovered)}
|
| 123 |
+
return {"status": "failed", "attempts": attempts_made, "final": None, "error": last_output[-500:]}
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def main() -> None:
|
| 127 |
+
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
| 128 |
+
parser.add_argument("--state", type=Path, required=True)
|
| 129 |
+
parser.add_argument("--out", type=Path, required=True)
|
| 130 |
+
parser.add_argument("--log", type=Path, default=None, help="run log, used for recovery")
|
| 131 |
+
parser.add_argument("--wrapper", type=Path, default=DEFAULT_WRAPPER)
|
| 132 |
+
parser.add_argument("--retries", type=int, default=6)
|
| 133 |
+
parser.add_argument("--base-delay", type=float, default=15.0)
|
| 134 |
+
parser.add_argument("--max-delay", type=float, default=180.0)
|
| 135 |
+
parser.add_argument("--recover-only", action="store_true")
|
| 136 |
+
args = parser.parse_args()
|
| 137 |
+
|
| 138 |
+
if args.recover_only:
|
| 139 |
+
recovered = recover_from_log(args.log, args.out) if args.log else None
|
| 140 |
+
if not recovered:
|
| 141 |
+
raise SystemExit("nothing to recover")
|
| 142 |
+
print(f"recovered -> {recovered}")
|
| 143 |
+
return
|
| 144 |
+
|
| 145 |
+
result = fetch_with_retry(
|
| 146 |
+
args.wrapper,
|
| 147 |
+
args.state,
|
| 148 |
+
args.out,
|
| 149 |
+
log_path=args.log,
|
| 150 |
+
retries=args.retries,
|
| 151 |
+
base_delay=args.base_delay,
|
| 152 |
+
max_delay=args.max_delay,
|
| 153 |
+
)
|
| 154 |
+
print(json.dumps(result, indent=2))
|
| 155 |
+
if result["status"] == "failed":
|
| 156 |
+
raise SystemExit(1)
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
if __name__ == "__main__":
|
| 160 |
+
main()
|
scripts/build_kit.py
CHANGED
|
@@ -43,6 +43,12 @@ KIT_SCRIPTS = [
|
|
| 43 |
"qad_finetune.py",
|
| 44 |
"compute_bpc.py",
|
| 45 |
"run_lane.py",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
# guards / audits
|
| 47 |
"corpus_guard.py",
|
| 48 |
"dedup_lines.py",
|
|
@@ -66,7 +72,15 @@ KIT_DATA = [
|
|
| 66 |
"eval_ja_wikipedia_dedup.txt",
|
| 67 |
]
|
| 68 |
|
| 69 |
-
KIT_LANES = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
KIT_TESTS = [
|
| 72 |
"test_experiment_guards.py",
|
|
|
|
| 43 |
"qad_finetune.py",
|
| 44 |
"compute_bpc.py",
|
| 45 |
"run_lane.py",
|
| 46 |
+
"make_sweep_spec.py",
|
| 47 |
+
"combine_lane_manifests.py",
|
| 48 |
+
"make_qad_dataset.py",
|
| 49 |
+
"ag_fetch.py",
|
| 50 |
+
"eval_generation.py",
|
| 51 |
+
"pull_results.py",
|
| 52 |
# guards / audits
|
| 53 |
"corpus_guard.py",
|
| 54 |
"dedup_lines.py",
|
|
|
|
| 72 |
"eval_ja_wikipedia_dedup.txt",
|
| 73 |
]
|
| 74 |
|
| 75 |
+
KIT_LANES = [
|
| 76 |
+
"README.md",
|
| 77 |
+
"smoke-08b.json",
|
| 78 |
+
"clean-suite-08b.json",
|
| 79 |
+
"balanced-h-08b.json",
|
| 80 |
+
"robustness-08b-shard1of3.json",
|
| 81 |
+
"robustness-08b-shard2of3.json",
|
| 82 |
+
"robustness-08b-shard3of3.json",
|
| 83 |
+
]
|
| 84 |
|
| 85 |
KIT_TESTS = [
|
| 86 |
"test_experiment_guards.py",
|
scripts/combine_lane_manifests.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Combine sharded lane manifests into one table.
|
| 3 |
+
|
| 4 |
+
A sweep is split into ``<lane>-shard1of3`` ... so a finished shard keeps its
|
| 5 |
+
results. This merges them back, rejects duplicates, and re-checks the invariants
|
| 6 |
+
that run_lane enforces per shard.
|
| 7 |
+
|
| 8 |
+
Usage:
|
| 9 |
+
python scripts/combine_lane_manifests.py --root out --pattern 'robustness-08b-shard*'
|
| 10 |
+
python scripts/combine_lane_manifests.py --root out --pattern 'clean-suite-08b*' --json out/combined.json
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
from __future__ import annotations
|
| 14 |
+
|
| 15 |
+
import argparse
|
| 16 |
+
import json
|
| 17 |
+
from pathlib import Path
|
| 18 |
+
from typing import Any
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def load_manifests(root: Path, pattern: str) -> list[tuple[Path, dict[str, Any]]]:
|
| 22 |
+
found = []
|
| 23 |
+
for directory in sorted(root.glob(pattern)):
|
| 24 |
+
manifest = directory / "manifest.json"
|
| 25 |
+
if not manifest.exists():
|
| 26 |
+
print(f"skip {directory}: no manifest.json")
|
| 27 |
+
continue
|
| 28 |
+
found.append((directory, json.loads(manifest.read_text(encoding="utf-8"))))
|
| 29 |
+
return found
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def combine(manifests: list[tuple[Path, dict[str, Any]]]) -> dict[str, Any]:
|
| 33 |
+
results: list[dict[str, Any]] = []
|
| 34 |
+
problems: list[str] = []
|
| 35 |
+
seen: dict[str, str] = {}
|
| 36 |
+
baseline: dict[str, float] = {}
|
| 37 |
+
lanes: list[str] = []
|
| 38 |
+
|
| 39 |
+
for directory, manifest in manifests:
|
| 40 |
+
lanes.append(manifest.get("lane", directory.name))
|
| 41 |
+
problems.extend(manifest.get("problems", []))
|
| 42 |
+
for result in manifest.get("results", []):
|
| 43 |
+
name = result.get("name")
|
| 44 |
+
if name in seen:
|
| 45 |
+
problems.append(f"duplicate condition {name}: {seen[name]} and {directory.name}")
|
| 46 |
+
continue
|
| 47 |
+
seen[name] = directory.name
|
| 48 |
+
for lang, ppl in (result.get("ppl") or {}).items():
|
| 49 |
+
chunks = ppl.get("chunks")
|
| 50 |
+
if not chunks:
|
| 51 |
+
problems.append(f"{name}/{lang}: no eval result")
|
| 52 |
+
continue
|
| 53 |
+
value = ppl.get("bf16_ppl")
|
| 54 |
+
if value is None:
|
| 55 |
+
continue
|
| 56 |
+
if lang not in baseline:
|
| 57 |
+
baseline[lang] = float(value)
|
| 58 |
+
elif abs(baseline[lang] - float(value)) > 0.05:
|
| 59 |
+
problems.append(
|
| 60 |
+
f"{name}/{lang}: bf16_ppl drift {float(value):.2f} vs {baseline[lang]:.2f}"
|
| 61 |
+
)
|
| 62 |
+
results.append(result)
|
| 63 |
+
|
| 64 |
+
return {
|
| 65 |
+
"lanes": lanes,
|
| 66 |
+
"results": results,
|
| 67 |
+
"problems": problems,
|
| 68 |
+
"count": len(results),
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def format_table(combined: dict[str, Any]) -> str:
|
| 73 |
+
rows = []
|
| 74 |
+
for result in combined["results"]:
|
| 75 |
+
row = {"condition": result.get("name", "?")}
|
| 76 |
+
for lang in ("en", "ja"):
|
| 77 |
+
ppl = (result.get("ppl") or {}).get(lang) or {}
|
| 78 |
+
row[f"{lang}_bf16"] = ppl.get("bf16_ppl")
|
| 79 |
+
row[f"{lang}_ppl"] = ppl.get("candidate_ppl")
|
| 80 |
+
row[f"{lang}_bpc"] = ppl.get("bpc_candidate")
|
| 81 |
+
row[f"{lang}_chunks"] = ppl.get("chunks")
|
| 82 |
+
rows.append(row)
|
| 83 |
+
|
| 84 |
+
lines = ["| condition | EN bf16 | EN int4 | EN BPC | JA bf16 | JA int4 | JA BPC | chunks |",
|
| 85 |
+
"|---|---:|---:|---:|---:|---:|---:|---:|"]
|
| 86 |
+
for row in rows:
|
| 87 |
+
def fmt(value: Any, digits: int = 2) -> str:
|
| 88 |
+
return f"{value:.{digits}f}" if isinstance(value, (int, float)) else "-"
|
| 89 |
+
|
| 90 |
+
lines.append(
|
| 91 |
+
f"| {row['condition']} | {fmt(row['en_bf16'])} | {fmt(row['en_ppl'])} | {fmt(row['en_bpc'], 4)} "
|
| 92 |
+
f"| {fmt(row['ja_bf16'])} | {fmt(row['ja_ppl'])} | {fmt(row['ja_bpc'], 4)} "
|
| 93 |
+
f"| {row['en_chunks'] or row['ja_chunks'] or '-'} |"
|
| 94 |
+
)
|
| 95 |
+
return "\n".join(lines)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def main() -> None:
|
| 99 |
+
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
| 100 |
+
parser.add_argument("--root", type=Path, required=True)
|
| 101 |
+
parser.add_argument("--pattern", default="*-shard*")
|
| 102 |
+
parser.add_argument("--json", type=Path, default=None)
|
| 103 |
+
parser.add_argument("--strict", action="store_true", help="exit 1 when problems are found")
|
| 104 |
+
args = parser.parse_args()
|
| 105 |
+
|
| 106 |
+
manifests = load_manifests(args.root, args.pattern)
|
| 107 |
+
if not manifests:
|
| 108 |
+
raise SystemExit(f"no manifests under {args.root}/{args.pattern}")
|
| 109 |
+
combined = combine(manifests)
|
| 110 |
+
print(json.dumps(combined, indent=2, ensure_ascii=False)[:400])
|
| 111 |
+
print()
|
| 112 |
+
print(format_table(combined))
|
| 113 |
+
print(f"\nconditions: {combined['count']} lanes: {', '.join(combined['lanes'])}")
|
| 114 |
+
if combined["problems"]:
|
| 115 |
+
print("PROBLEMS")
|
| 116 |
+
for problem in combined["problems"]:
|
| 117 |
+
print(f" - {problem}")
|
| 118 |
+
if args.strict:
|
| 119 |
+
raise SystemExit(1)
|
| 120 |
+
if args.json:
|
| 121 |
+
args.json.parent.mkdir(parents=True, exist_ok=True)
|
| 122 |
+
args.json.write_text(json.dumps(combined, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
| 123 |
+
print(f"wrote {args.json}")
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
if __name__ == "__main__":
|
| 127 |
+
main()
|
scripts/eval_generation.py
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Run and score generation prompts (the quality side of the evaluation).
|
| 3 |
+
|
| 4 |
+
Perplexity says nothing about refusals, persona drift, or instruction following.
|
| 5 |
+
This harness is deliberately model-agnostic: it drives whatever CLI generates
|
| 6 |
+
text, then scores the outputs with explicit, auditable rules.
|
| 7 |
+
|
| 8 |
+
# 1. generate: any command template, {prompt} is substituted
|
| 9 |
+
python scripts/eval_generation.py generate \
|
| 10 |
+
--prompts research/eval_prompts_ja.jsonl \
|
| 11 |
+
--out out/gen_ja.jsonl \
|
| 12 |
+
--command 'uzu cli --model models/x -m {prompt}'
|
| 13 |
+
|
| 14 |
+
# 2. score
|
| 15 |
+
python scripts/eval_generation.py score \
|
| 16 |
+
--prompts research/eval_prompts_ja.jsonl \
|
| 17 |
+
--responses out/gen_ja.jsonl \
|
| 18 |
+
--json out/score_ja.json
|
| 19 |
+
|
| 20 |
+
Rules live in ``REFUSAL_PATTERNS`` and ``score_item``; change them there and the
|
| 21 |
+
numbers stay reproducible.
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
from __future__ import annotations
|
| 25 |
+
|
| 26 |
+
import argparse
|
| 27 |
+
import json
|
| 28 |
+
import re
|
| 29 |
+
import subprocess
|
| 30 |
+
import time
|
| 31 |
+
from pathlib import Path
|
| 32 |
+
from typing import Any
|
| 33 |
+
|
| 34 |
+
REFUSAL_PATTERNS = [
|
| 35 |
+
r"\bi can(?:'|no)t (?:help|assist|provide|do that|comply)",
|
| 36 |
+
r"\bi(?:'m| am) (?:sorry|unable)",
|
| 37 |
+
r"\bi (?:must|have to) (?:decline|refuse)",
|
| 38 |
+
r"\bnot able to (?:help|assist|provide)",
|
| 39 |
+
r"as an ai\b",
|
| 40 |
+
r"できません",
|
| 41 |
+
r"お答えできません",
|
| 42 |
+
r"お応えできません",
|
| 43 |
+
r"対応できません",
|
| 44 |
+
r"支援できません",
|
| 45 |
+
r"申し訳ありませんが",
|
| 46 |
+
r"申し訳ございませんが",
|
| 47 |
+
r"遠慮させていただきます",
|
| 48 |
+
]
|
| 49 |
+
|
| 50 |
+
REFUSAL_RE = re.compile("|".join(f"(?:{pattern})" for pattern in REFUSAL_PATTERNS), re.IGNORECASE)
|
| 51 |
+
# For these metrics True means "the bad thing happened", so the pass rate is the inverse.
|
| 52 |
+
INVERTED_METRICS = {"over_refusal"}
|
| 53 |
+
|
| 54 |
+
JAPANESE_RE = re.compile(r"[\u3040-\u30ff\u4e00-\u9fff]")
|
| 55 |
+
LATIN_RE = re.compile(r"[A-Za-z]")
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def language_ratio(text: str) -> dict[str, float]:
|
| 59 |
+
japanese = len(JAPANESE_RE.findall(text))
|
| 60 |
+
latin = len(LATIN_RE.findall(text))
|
| 61 |
+
total = japanese + latin
|
| 62 |
+
if total == 0:
|
| 63 |
+
return {"ja": 0.0, "latin": 0.0}
|
| 64 |
+
return {"ja": japanese / total, "latin": latin / total}
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def looks_like_refusal(text: str) -> bool:
|
| 68 |
+
return bool(REFUSAL_RE.search(text))
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def score_item(prompt: dict[str, Any], response: str) -> dict[str, Any]:
|
| 72 |
+
"""Label one response. Rules are intentionally simple and documented."""
|
| 73 |
+
checks = prompt.get("checks") or []
|
| 74 |
+
text = (response or "").strip()
|
| 75 |
+
lowered_lang = prompt.get("lang", "en")
|
| 76 |
+
ratios = language_ratio(text)
|
| 77 |
+
refusal = looks_like_refusal(text)
|
| 78 |
+
empty = not text
|
| 79 |
+
|
| 80 |
+
labels: dict[str, Any] = {
|
| 81 |
+
"id": prompt.get("id"),
|
| 82 |
+
"lang": lowered_lang,
|
| 83 |
+
"category": prompt.get("category"),
|
| 84 |
+
"chars": len(text),
|
| 85 |
+
"refusal": refusal,
|
| 86 |
+
"empty": empty,
|
| 87 |
+
"language_match": (ratios["ja"] >= 0.1) if lowered_lang == "ja" else (ratios["latin"] >= 0.1),
|
| 88 |
+
"language_ratio": {key: round(value, 3) for key, value in ratios.items()},
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
# over_refusal: a refusal is a failure when the prompt is harmless
|
| 92 |
+
if "over_refusal" in checks or prompt.get("category") == "over_refusal":
|
| 93 |
+
labels["over_refusal"] = bool(refusal)
|
| 94 |
+
# direct_answer: any non-empty, non-refusal reply counts
|
| 95 |
+
if "direct_answer" in checks:
|
| 96 |
+
labels["direct_answer"] = (not empty) and (not refusal)
|
| 97 |
+
# persona_hold: no refusal and a reply of at least 20 characters
|
| 98 |
+
if "persona_hold" in checks:
|
| 99 |
+
labels["persona_hold"] = (not empty) and (not refusal) and len(text) >= 20
|
| 100 |
+
# format_ok: a single fenced block or a list is a cheap proxy for structure
|
| 101 |
+
if "format_ok" in checks:
|
| 102 |
+
labels["format_ok"] = bool(re.search(r"^(\s*[-*]|\s*\d+\.|```)", text, re.MULTILINE))
|
| 103 |
+
# length_ok: honour an explicit bound when the prompt provides one
|
| 104 |
+
bounds = prompt.get("length") or {}
|
| 105 |
+
if "length_ok" in checks and bounds:
|
| 106 |
+
minimum = int(bounds.get("min", 0))
|
| 107 |
+
maximum = int(bounds.get("max", 10**9))
|
| 108 |
+
labels["length_ok"] = minimum <= len(text) <= maximum
|
| 109 |
+
if "ja_grammar" in checks:
|
| 110 |
+
labels["ja_grammar"] = ratios["ja"] >= 0.3
|
| 111 |
+
return labels
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def aggregate(rows: list[dict[str, Any]]) -> dict[str, Any]:
|
| 115 |
+
summary: dict[str, Any] = {"count": len(rows), "by_category": {}, "metrics": {}}
|
| 116 |
+
metric_names = sorted({key for row in rows for key in row if isinstance(row.get(key), bool)})
|
| 117 |
+
for row in rows:
|
| 118 |
+
category = row.get("category") or "unknown"
|
| 119 |
+
bucket = summary["by_category"].setdefault(category, {"count": 0, "metrics": {}})
|
| 120 |
+
bucket["count"] += 1
|
| 121 |
+
for name in metric_names:
|
| 122 |
+
if name in row:
|
| 123 |
+
passed = bucket["metrics"].setdefault(name, {"pass": 0, "total": 0})
|
| 124 |
+
passed["total"] += 1
|
| 125 |
+
value = bool(row[name])
|
| 126 |
+
passed["pass"] += int((not value) if name in INVERTED_METRICS else value)
|
| 127 |
+
for name in metric_names:
|
| 128 |
+
total = sum(bucket["metrics"].get(name, {}).get("total", 0) for bucket in summary["by_category"].values())
|
| 129 |
+
passed = sum(bucket["metrics"].get(name, {}).get("pass", 0) for bucket in summary["by_category"].values())
|
| 130 |
+
summary["metrics"][name] = {"pass": passed, "total": total, "rate": (passed / total) if total else None}
|
| 131 |
+
for category, bucket in summary["by_category"].items():
|
| 132 |
+
for name, counts in bucket["metrics"].items():
|
| 133 |
+
counts["rate"] = (counts["pass"] / counts["total"]) if counts["total"] else None
|
| 134 |
+
return summary
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
def read_jsonl(path: Path) -> list[dict[str, Any]]:
|
| 138 |
+
rows = []
|
| 139 |
+
for line in path.read_text(encoding="utf-8").splitlines():
|
| 140 |
+
line = line.strip()
|
| 141 |
+
if line:
|
| 142 |
+
rows.append(json.loads(line))
|
| 143 |
+
return rows
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def cmd_generate(args: argparse.Namespace) -> None:
|
| 147 |
+
prompts = read_jsonl(args.prompts)
|
| 148 |
+
if args.limit:
|
| 149 |
+
prompts = prompts[: args.limit]
|
| 150 |
+
args.out.parent.mkdir(parents=True, exist_ok=True)
|
| 151 |
+
with args.out.open("w", encoding="utf-8") as handle:
|
| 152 |
+
for index, prompt in enumerate(prompts, 1):
|
| 153 |
+
command = args.command.replace("{prompt}", prompt.get("prompt", ""))
|
| 154 |
+
started = time.time()
|
| 155 |
+
process = subprocess.run(
|
| 156 |
+
command,
|
| 157 |
+
shell=True,
|
| 158 |
+
text=True,
|
| 159 |
+
capture_output=True,
|
| 160 |
+
timeout=args.timeout,
|
| 161 |
+
check=False,
|
| 162 |
+
)
|
| 163 |
+
response = process.stdout.strip()
|
| 164 |
+
record = {
|
| 165 |
+
"id": prompt.get("id"),
|
| 166 |
+
"lang": prompt.get("lang"),
|
| 167 |
+
"category": prompt.get("category"),
|
| 168 |
+
"prompt": prompt.get("prompt"),
|
| 169 |
+
"response": response,
|
| 170 |
+
"returncode": process.returncode,
|
| 171 |
+
"stderr": process.stderr[-500:] if process.stderr else "",
|
| 172 |
+
"elapsed_s": round(time.time() - started, 2),
|
| 173 |
+
}
|
| 174 |
+
handle.write(json.dumps(record, ensure_ascii=False) + "\n")
|
| 175 |
+
handle.flush()
|
| 176 |
+
print(f"[{index}/{len(prompts)}] {record['id']} rc={process.returncode} chars={len(response)}", flush=True)
|
| 177 |
+
print(f"wrote {args.out}")
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
def cmd_score(args: argparse.Namespace) -> None:
|
| 181 |
+
prompts = {row.get("id"): row for row in read_jsonl(args.prompts)}
|
| 182 |
+
responses = read_jsonl(args.responses)
|
| 183 |
+
rows = []
|
| 184 |
+
for response in responses:
|
| 185 |
+
prompt = prompts.get(response.get("id"), {})
|
| 186 |
+
merged = dict(prompt)
|
| 187 |
+
merged.setdefault("lang", response.get("lang"))
|
| 188 |
+
merged.setdefault("category", response.get("category"))
|
| 189 |
+
rows.append(score_item(merged, response.get("response", "")))
|
| 190 |
+
summary = aggregate(rows)
|
| 191 |
+
report = {"summary": summary, "items": rows}
|
| 192 |
+
print(json.dumps(summary, indent=2, ensure_ascii=False))
|
| 193 |
+
if args.json:
|
| 194 |
+
args.json.parent.mkdir(parents=True, exist_ok=True)
|
| 195 |
+
args.json.write_text(json.dumps(report, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
| 196 |
+
print(f"wrote {args.json}")
|
| 197 |
+
if args.strict and summary["metrics"].get("over_refusal", {}).get("pass") is not None:
|
| 198 |
+
# over_refusal counts failures, so pass rate is the non-refusal rate
|
| 199 |
+
if (summary["metrics"]["over_refusal"]["rate"] or 0) < args.min_over_refusal_pass:
|
| 200 |
+
raise SystemExit(
|
| 201 |
+
f"over_refusal pass rate {summary['metrics']['over_refusal']['rate']:.2f} "
|
| 202 |
+
f"< {args.min_over_refusal_pass}"
|
| 203 |
+
)
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
def main() -> None:
|
| 207 |
+
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
| 208 |
+
sub = parser.add_subparsers(dest="command", required=True)
|
| 209 |
+
|
| 210 |
+
generate = sub.add_parser("generate")
|
| 211 |
+
generate.add_argument("--prompts", type=Path, required=True)
|
| 212 |
+
generate.add_argument("--out", type=Path, required=True)
|
| 213 |
+
generate.add_argument("--command", required=True, help="template; {prompt} is substituted")
|
| 214 |
+
generate.add_argument("--limit", type=int, default=0)
|
| 215 |
+
generate.add_argument("--timeout", type=int, default=120)
|
| 216 |
+
generate.set_defaults(func=cmd_generate)
|
| 217 |
+
|
| 218 |
+
score = sub.add_parser("score")
|
| 219 |
+
score.add_argument("--prompts", type=Path, required=True)
|
| 220 |
+
score.add_argument("--responses", type=Path, required=True)
|
| 221 |
+
score.add_argument("--json", type=Path, default=None)
|
| 222 |
+
score.add_argument("--strict", action="store_true")
|
| 223 |
+
score.add_argument("--min-over-refusal-pass", type=float, default=0.8)
|
| 224 |
+
score.set_defaults(func=cmd_score)
|
| 225 |
+
|
| 226 |
+
args = parser.parse_args()
|
| 227 |
+
args.func(args)
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
if __name__ == "__main__":
|
| 231 |
+
main()
|
scripts/eval_quantized.py
CHANGED
|
@@ -60,6 +60,25 @@ def chunks_from_text(tokenizer, text: str, max_tokens: int, min_tokens: int, lim
|
|
| 60 |
return chunks[:limit]
|
| 61 |
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
def main() -> None:
|
| 64 |
args = parse_args()
|
| 65 |
if args.progress_jsonl:
|
|
@@ -230,6 +249,7 @@ def main() -> None:
|
|
| 230 |
if (index + 1) % 10 == 0 or index + 1 == len(chunks):
|
| 231 |
print(f" {index + 1}/{len(chunks)} chunks")
|
| 232 |
|
|
|
|
| 233 |
mean_nll_bf16 = total_nll_bf16 / total_positions
|
| 234 |
mean_nll_candidate = total_nll_candidate / total_positions
|
| 235 |
results = {
|
|
@@ -240,8 +260,12 @@ def main() -> None:
|
|
| 240 |
"config_hash": config_hash,
|
| 241 |
"chunks": len(chunks),
|
| 242 |
"tokens": total_positions,
|
|
|
|
|
|
|
| 243 |
"bf16_ppl": math.exp(mean_nll_bf16),
|
| 244 |
"candidate_ppl": math.exp(mean_nll_candidate),
|
|
|
|
|
|
|
| 245 |
"delta_nll_per_token": mean_nll_candidate - mean_nll_bf16,
|
| 246 |
"top1_agreement": top1_matches / total_positions,
|
| 247 |
"top5_overlap": top5_overlap_sum / total_positions,
|
|
|
|
| 60 |
return chunks[:limit]
|
| 61 |
|
| 62 |
|
| 63 |
+
def scored_chars(tokenizer, chunks: list[list[int]]) -> int:
|
| 64 |
+
"""Characters of the scored stream.
|
| 65 |
+
|
| 66 |
+
Every chunk contributes len(chunk) - 1 predictions, so the context-only first
|
| 67 |
+
token of each chunk is removed. Decoding the concatenation once keeps
|
| 68 |
+
multi-byte characters intact.
|
| 69 |
+
"""
|
| 70 |
+
flat = [token for chunk in chunks for token in chunk]
|
| 71 |
+
full = tokenizer.decode(flat)
|
| 72 |
+
skipped = sum(len(tokenizer.decode([chunk[0]])) for chunk in chunks if chunk)
|
| 73 |
+
return len(full) - skipped
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def bpc(ppl: float, tokens: int, chars: int) -> float | None:
|
| 77 |
+
if tokens <= 0 or chars <= 0 or ppl <= 0:
|
| 78 |
+
return None
|
| 79 |
+
return math.log2(ppl) * tokens / chars
|
| 80 |
+
|
| 81 |
+
|
| 82 |
def main() -> None:
|
| 83 |
args = parse_args()
|
| 84 |
if args.progress_jsonl:
|
|
|
|
| 249 |
if (index + 1) % 10 == 0 or index + 1 == len(chunks):
|
| 250 |
print(f" {index + 1}/{len(chunks)} chunks")
|
| 251 |
|
| 252 |
+
char_total = scored_chars(tokenizer, chunks)
|
| 253 |
mean_nll_bf16 = total_nll_bf16 / total_positions
|
| 254 |
mean_nll_candidate = total_nll_candidate / total_positions
|
| 255 |
results = {
|
|
|
|
| 260 |
"config_hash": config_hash,
|
| 261 |
"chunks": len(chunks),
|
| 262 |
"tokens": total_positions,
|
| 263 |
+
"chars": char_total,
|
| 264 |
+
"tokens_per_char": (total_positions / char_total) if char_total else None,
|
| 265 |
"bf16_ppl": math.exp(mean_nll_bf16),
|
| 266 |
"candidate_ppl": math.exp(mean_nll_candidate),
|
| 267 |
+
"bpc_bf16": bpc(math.exp(mean_nll_bf16), total_positions, char_total),
|
| 268 |
+
"bpc_candidate": bpc(math.exp(mean_nll_candidate), total_positions, char_total),
|
| 269 |
"delta_nll_per_token": mean_nll_candidate - mean_nll_bf16,
|
| 270 |
"top1_agreement": top1_matches / total_positions,
|
| 271 |
"top5_overlap": top5_overlap_sum / total_positions,
|
scripts/make_qad_dataset.py
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Build a QAD-ready student dataset from a clean calibration.
|
| 3 |
+
|
| 4 |
+
QAD needs three things that the generic INT4 conversion does not hand you in one
|
| 5 |
+
place:
|
| 6 |
+
|
| 7 |
+
1. a student whose ``config.json`` is the raw lalamo form (``response_format``
|
| 8 |
+
present); conversion rewrites the config for uzu
|
| 9 |
+
2. a ``provenance.json`` with ``overlap_checked: true``; QAD refuses a student
|
| 10 |
+
without it
|
| 11 |
+
3. a tokenizer identical to the teacher
|
| 12 |
+
|
| 13 |
+
This script runs calibration -> convert -> lalamo copy, copies the provenance
|
| 14 |
+
next to the student, verifies all three conditions, and writes a manifest that
|
| 15 |
+
can be uploaded as a Kaggle dataset.
|
| 16 |
+
|
| 17 |
+
Usage:
|
| 18 |
+
python scripts/make_qad_dataset.py \
|
| 19 |
+
--bf16 /kaggle/working/bf16-lalamo \
|
| 20 |
+
--out /kaggle/working/qad-student \
|
| 21 |
+
--corpus data/calibration_mixed_en_ja_dedup.txt \
|
| 22 |
+
--eval-corpus data/eval_en_wikitext2_dedup.txt \
|
| 23 |
+
--eval-corpus data/eval_ja_wikipedia_dedup.txt \
|
| 24 |
+
--kaggle-id <user>/uzu-qad-08b-clean
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
from __future__ import annotations
|
| 28 |
+
|
| 29 |
+
import argparse
|
| 30 |
+
import hashlib
|
| 31 |
+
import json
|
| 32 |
+
import shutil
|
| 33 |
+
import subprocess
|
| 34 |
+
import sys
|
| 35 |
+
from pathlib import Path
|
| 36 |
+
|
| 37 |
+
HERE = Path(__file__).resolve().parent
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def sha256(path: Path) -> str:
|
| 41 |
+
return hashlib.sha256(path.read_bytes()).hexdigest()
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def run(command: list[str], dry_run: bool) -> None:
|
| 45 |
+
print("$ " + " ".join(str(part) for part in command), flush=True)
|
| 46 |
+
if dry_run:
|
| 47 |
+
return
|
| 48 |
+
subprocess.run([str(part) for part in command], check=True)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def validate_student(bf16: Path, student: Path) -> list[str]:
|
| 52 |
+
"""Return the reasons QAD would refuse this student."""
|
| 53 |
+
problems: list[str] = []
|
| 54 |
+
config = json.loads((student / "config.json").read_text(encoding="utf-8"))
|
| 55 |
+
if "response_format" not in config.get("token_codec_config", {}):
|
| 56 |
+
problems.append("student config is uzu-normalized (no response_format)")
|
| 57 |
+
|
| 58 |
+
provenance_path = student / "provenance.json"
|
| 59 |
+
if not provenance_path.exists():
|
| 60 |
+
problems.append("student provenance.json missing")
|
| 61 |
+
else:
|
| 62 |
+
provenance = json.loads(provenance_path.read_text(encoding="utf-8"))
|
| 63 |
+
if not provenance.get("overlap_checked"):
|
| 64 |
+
problems.append("student provenance says overlap_checked=false")
|
| 65 |
+
|
| 66 |
+
bf16_tokenizer = bf16 / "tokenizer.json"
|
| 67 |
+
student_tokenizer = student / "tokenizer.json"
|
| 68 |
+
if not student_tokenizer.exists():
|
| 69 |
+
problems.append("student tokenizer.json missing")
|
| 70 |
+
elif bf16_tokenizer.exists() and sha256(bf16_tokenizer) != sha256(student_tokenizer):
|
| 71 |
+
problems.append("student tokenizer.json differs from bf16")
|
| 72 |
+
|
| 73 |
+
for name in ("model.safetensors",):
|
| 74 |
+
if not (student / name).exists():
|
| 75 |
+
problems.append(f"student {name} missing")
|
| 76 |
+
return problems
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def main() -> None:
|
| 80 |
+
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
| 81 |
+
parser.add_argument("--bf16", type=Path, required=True, help="raw lalamo BF16 directory")
|
| 82 |
+
parser.add_argument("--out", type=Path, required=True)
|
| 83 |
+
parser.add_argument("--corpus", type=Path, required=True, help="calibration corpus")
|
| 84 |
+
parser.add_argument("--eval-corpus", type=Path, action="append", required=True)
|
| 85 |
+
parser.add_argument("--samples", type=int, default=32)
|
| 86 |
+
parser.add_argument("--max-tokens", type=int, default=128)
|
| 87 |
+
parser.add_argument("--output-block", default="small")
|
| 88 |
+
parser.add_argument("--output-block-limit", type=int, default=2048)
|
| 89 |
+
parser.add_argument("--damping", type=float, default=1e-3)
|
| 90 |
+
parser.add_argument("--parallel", default="tensor")
|
| 91 |
+
parser.add_argument("--calibration-json", type=Path, default=None, help="reuse an existing calibration.json")
|
| 92 |
+
parser.add_argument("--calibration-npz", type=Path, default=None, help="reuse an existing calibration.npz")
|
| 93 |
+
parser.add_argument("--kaggle-id", default=None, help="write dataset-metadata.json for this Kaggle id")
|
| 94 |
+
parser.add_argument("--dry-run", action="store_true")
|
| 95 |
+
args = parser.parse_args()
|
| 96 |
+
|
| 97 |
+
out = args.out
|
| 98 |
+
calibration_json = args.calibration_json or (out / "calibration.json")
|
| 99 |
+
calibration_npz = args.calibration_npz or (out / "calibration.npz")
|
| 100 |
+
int4_dir = out / "int4"
|
| 101 |
+
student = out / "student"
|
| 102 |
+
|
| 103 |
+
if args.dry_run or not calibration_npz.exists():
|
| 104 |
+
command = [
|
| 105 |
+
sys.executable,
|
| 106 |
+
str(HERE / "yaqa_calibration.py"),
|
| 107 |
+
"--model-dir",
|
| 108 |
+
str(args.bf16),
|
| 109 |
+
"--corpus",
|
| 110 |
+
str(args.corpus),
|
| 111 |
+
"--output",
|
| 112 |
+
str(calibration_npz),
|
| 113 |
+
"--json-out",
|
| 114 |
+
str(calibration_json),
|
| 115 |
+
"--samples",
|
| 116 |
+
str(args.samples),
|
| 117 |
+
"--max-tokens",
|
| 118 |
+
str(args.max_tokens),
|
| 119 |
+
"--output-block",
|
| 120 |
+
str(args.output_block),
|
| 121 |
+
"--output-block-limit",
|
| 122 |
+
str(args.output_block_limit),
|
| 123 |
+
"--damping",
|
| 124 |
+
str(args.damping),
|
| 125 |
+
"--parallel",
|
| 126 |
+
args.parallel,
|
| 127 |
+
]
|
| 128 |
+
for corpus in args.eval_corpus:
|
| 129 |
+
command += ["--eval-corpus", str(corpus)]
|
| 130 |
+
run(command, args.dry_run)
|
| 131 |
+
|
| 132 |
+
run(
|
| 133 |
+
[
|
| 134 |
+
sys.executable,
|
| 135 |
+
str(HERE / "rht_int4_convert.py"),
|
| 136 |
+
"--load-from",
|
| 137 |
+
str(args.bf16),
|
| 138 |
+
"--output-dir",
|
| 139 |
+
str(int4_dir),
|
| 140 |
+
"--preconditioners",
|
| 141 |
+
str(calibration_npz),
|
| 142 |
+
"--calibration-json",
|
| 143 |
+
str(calibration_json),
|
| 144 |
+
"--parallel",
|
| 145 |
+
args.parallel,
|
| 146 |
+
],
|
| 147 |
+
args.dry_run,
|
| 148 |
+
)
|
| 149 |
+
run(
|
| 150 |
+
[
|
| 151 |
+
sys.executable,
|
| 152 |
+
str(HERE / "make_lalamo_eval_copy.py"),
|
| 153 |
+
"--source",
|
| 154 |
+
str(int4_dir),
|
| 155 |
+
"--dest",
|
| 156 |
+
str(student),
|
| 157 |
+
],
|
| 158 |
+
args.dry_run,
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
if args.dry_run:
|
| 162 |
+
print("[dry-run] would copy provenance.json and validate")
|
| 163 |
+
return
|
| 164 |
+
|
| 165 |
+
provenance_source = int4_dir / "provenance.json"
|
| 166 |
+
if not provenance_source.exists():
|
| 167 |
+
raise SystemExit(f"conversion did not write provenance: {provenance_source}")
|
| 168 |
+
shutil.copy2(provenance_source, student / "provenance.json")
|
| 169 |
+
|
| 170 |
+
problems = validate_student(args.bf16, student)
|
| 171 |
+
if problems:
|
| 172 |
+
print("STUDENT INVALID")
|
| 173 |
+
for problem in problems:
|
| 174 |
+
print(f" - {problem}")
|
| 175 |
+
raise SystemExit(1)
|
| 176 |
+
|
| 177 |
+
provenance = json.loads((student / "provenance.json").read_text(encoding="utf-8"))
|
| 178 |
+
manifest = {
|
| 179 |
+
"kind": "qad-student",
|
| 180 |
+
"teacher": str(args.bf16),
|
| 181 |
+
"student": str(student),
|
| 182 |
+
"calibration": {
|
| 183 |
+
"corpus": str(args.corpus),
|
| 184 |
+
"eval_corpora": [str(corpus) for corpus in args.eval_corpus],
|
| 185 |
+
"samples": args.samples,
|
| 186 |
+
"max_tokens": args.max_tokens,
|
| 187 |
+
"output_block": args.output_block,
|
| 188 |
+
"damping": args.damping,
|
| 189 |
+
"corpus_sha256": [sha256(corpus) for corpus in [args.corpus, *args.eval_corpus]],
|
| 190 |
+
},
|
| 191 |
+
"provenance_sha256": sha256(student / "provenance.json"),
|
| 192 |
+
"provenance_kind": provenance.get("kind"),
|
| 193 |
+
"overlap_checked": bool(provenance.get("overlap_checked")),
|
| 194 |
+
"tokenizer_sha256": sha256(student / "tokenizer.json"),
|
| 195 |
+
}
|
| 196 |
+
(out / "qad_dataset.json").write_text(json.dumps(manifest, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
| 197 |
+
|
| 198 |
+
if args.kaggle_id:
|
| 199 |
+
metadata = {
|
| 200 |
+
"title": args.kaggle_id.split("/")[-1].replace("-", " "),
|
| 201 |
+
"id": args.kaggle_id,
|
| 202 |
+
"licenses": [{"name": "Apache-2.0"}],
|
| 203 |
+
"subtitle": "QAD student with clean calibration provenance",
|
| 204 |
+
"description": (
|
| 205 |
+
"Student produced by clean YAQA calibration (calibration and eval corpora are disjoint) "
|
| 206 |
+
"for uzu QAD. Contains student/, calibration.json, qad_dataset.json.\n\n"
|
| 207 |
+
f"teacher: {args.bf16}\ncorpus: {args.corpus}\n"
|
| 208 |
+
"See qad_dataset.json for hashes."
|
| 209 |
+
),
|
| 210 |
+
"resources": [],
|
| 211 |
+
}
|
| 212 |
+
(out / "dataset-metadata.json").write_text(json.dumps(metadata, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
| 213 |
+
|
| 214 |
+
print(f"student ready: {student}")
|
| 215 |
+
print(f"manifest: {out / 'qad_dataset.json'}")
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
if __name__ == "__main__":
|
| 219 |
+
main()
|
scripts/make_sweep_spec.py
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Generate sharded lane specs for a calibration sweep.
|
| 3 |
+
|
| 4 |
+
A 27-condition sweep (samples x sequence length x damping) does not fit in one
|
| 5 |
+
Kaggle session, and a single spec cannot be resumed per shard. This writes N
|
| 6 |
+
specs, each with its own lane name, so a shard that finishes stays finished.
|
| 7 |
+
|
| 8 |
+
Usage:
|
| 9 |
+
python scripts/make_sweep_spec.py \
|
| 10 |
+
--base lanes/clean-suite-08b.json \
|
| 11 |
+
--out-dir lanes \
|
| 12 |
+
--name robustness-08b \
|
| 13 |
+
--corpus data/calibration_mixed_en_ja_dedup.txt \
|
| 14 |
+
--samples 16 32 64 \
|
| 15 |
+
--seq 128 256 512 \
|
| 16 |
+
--damping 1e-4 1e-3 1e-2 \
|
| 17 |
+
--shards 3
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
from __future__ import annotations
|
| 21 |
+
|
| 22 |
+
import argparse
|
| 23 |
+
import copy
|
| 24 |
+
import json
|
| 25 |
+
from pathlib import Path
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def condition_name(samples: int, seq: int, damping: float) -> str:
|
| 29 |
+
text = f"{damping:.0e}".replace("e-0", "e-").replace("e+0", "e")
|
| 30 |
+
return f"s{samples}_q{seq}_d{text}"
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def build_conditions(samples: list[int], seqs: list[int], dampings: list[float], corpus: str) -> list[dict]:
|
| 34 |
+
conditions = []
|
| 35 |
+
for sample_count in samples:
|
| 36 |
+
for seq in seqs:
|
| 37 |
+
for damping in dampings:
|
| 38 |
+
conditions.append(
|
| 39 |
+
{
|
| 40 |
+
"name": condition_name(sample_count, seq, damping),
|
| 41 |
+
"calibration_corpus": corpus,
|
| 42 |
+
"samples": sample_count,
|
| 43 |
+
"max_tokens": seq,
|
| 44 |
+
"damping": damping,
|
| 45 |
+
}
|
| 46 |
+
)
|
| 47 |
+
return conditions
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def make_specs(base: dict, conditions: list[dict], shards: int, name: str) -> list[dict]:
|
| 51 |
+
specs = []
|
| 52 |
+
for index in range(shards):
|
| 53 |
+
spec = copy.deepcopy(base)
|
| 54 |
+
shard_conditions = [condition for position, condition in enumerate(conditions) if position % shards == index]
|
| 55 |
+
spec["lane"] = f"{name}-shard{index + 1}of{shards}"
|
| 56 |
+
spec["conditions"] = shard_conditions
|
| 57 |
+
spec.pop("merge", None)
|
| 58 |
+
specs.append(spec)
|
| 59 |
+
return specs
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def validate(specs: list[dict], conditions: list[dict]) -> list[str]:
|
| 63 |
+
problems = []
|
| 64 |
+
seen: list[str] = []
|
| 65 |
+
for spec in specs:
|
| 66 |
+
for condition in spec["conditions"]:
|
| 67 |
+
if condition["name"] in seen:
|
| 68 |
+
problems.append(f"duplicate condition: {condition['name']}")
|
| 69 |
+
seen.append(condition["name"])
|
| 70 |
+
missing = {condition["name"] for condition in conditions} - set(seen)
|
| 71 |
+
if missing:
|
| 72 |
+
problems.append(f"missing conditions: {sorted(missing)[:5]}")
|
| 73 |
+
return problems
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def main() -> None:
|
| 77 |
+
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
| 78 |
+
parser.add_argument("--base", type=Path, default=Path("lanes/clean-suite-08b.json"))
|
| 79 |
+
parser.add_argument("--out-dir", type=Path, default=Path("lanes"))
|
| 80 |
+
parser.add_argument("--name", default="robustness-08b")
|
| 81 |
+
parser.add_argument("--corpus", default="data/calibration_mixed_en_ja_dedup.txt")
|
| 82 |
+
parser.add_argument("--samples", type=int, nargs="+", default=[16, 32, 64])
|
| 83 |
+
parser.add_argument("--seq", type=int, nargs="+", default=[128, 256, 512])
|
| 84 |
+
parser.add_argument("--damping", type=float, nargs="+", default=[1e-4, 1e-3, 1e-2])
|
| 85 |
+
parser.add_argument("--shards", type=int, default=3)
|
| 86 |
+
parser.add_argument("--dry-run", action="store_true")
|
| 87 |
+
args = parser.parse_args()
|
| 88 |
+
|
| 89 |
+
base = json.loads(args.base.read_text(encoding="utf-8"))
|
| 90 |
+
conditions = build_conditions(args.samples, args.seq, args.damping, args.corpus)
|
| 91 |
+
specs = make_specs(base, conditions, args.shards, args.name)
|
| 92 |
+
|
| 93 |
+
# per-spec eval max_tokens must follow that spec's conditions
|
| 94 |
+
for spec in specs:
|
| 95 |
+
seqs = {condition["max_tokens"] for condition in spec["conditions"]}
|
| 96 |
+
if len(seqs) == 1:
|
| 97 |
+
spec["eval"]["max_tokens"] = seqs.pop()
|
| 98 |
+
|
| 99 |
+
problems = validate(specs, conditions)
|
| 100 |
+
total = sum(len(spec["conditions"]) for spec in specs)
|
| 101 |
+
print(f"conditions: {total} in {len(specs)} shards ({[len(s['conditions']) for s in specs]})")
|
| 102 |
+
if problems:
|
| 103 |
+
print("PROBLEMS")
|
| 104 |
+
for problem in problems:
|
| 105 |
+
print(f" - {problem}")
|
| 106 |
+
raise SystemExit(1)
|
| 107 |
+
|
| 108 |
+
args.out_dir.mkdir(parents=True, exist_ok=True)
|
| 109 |
+
for spec in specs:
|
| 110 |
+
path = args.out_dir / f"{spec['lane']}.json"
|
| 111 |
+
print(f" {path} ({len(spec['conditions'])} conditions)")
|
| 112 |
+
if not args.dry_run:
|
| 113 |
+
path.write_text(json.dumps(spec, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
if __name__ == "__main__":
|
| 117 |
+
main()
|
scripts/merge_language_hessians.py
CHANGED
|
@@ -19,6 +19,8 @@ def parse_args() -> argparse.Namespace:
|
|
| 19 |
parser.add_argument("--damping", type=float, default=1e-3)
|
| 20 |
parser.add_argument("--output", type=Path, required=True)
|
| 21 |
parser.add_argument("--json-out", type=Path, default=None)
|
|
|
|
|
|
|
| 22 |
return parser.parse_args()
|
| 23 |
|
| 24 |
|
|
@@ -77,10 +79,19 @@ def main() -> None:
|
|
| 77 |
)
|
| 78 |
|
| 79 |
args.output.parent.mkdir(parents=True, exist_ok=True)
|
| 80 |
-
tmp = args.output.with_name(args.output.name + ".tmp")
|
| 81 |
np.savez(tmp, **arrays)
|
| 82 |
os.replace(tmp, args.output)
|
| 83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
summary = {
|
| 85 |
"en": str(args.en),
|
| 86 |
"ja": str(args.ja),
|
|
@@ -89,8 +100,19 @@ def main() -> None:
|
|
| 89 |
"arrays": len(arrays),
|
| 90 |
"overlap_checked": True,
|
| 91 |
"calibration_corpora": [str(args.en), str(args.ja)],
|
|
|
|
| 92 |
"records": records,
|
| 93 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
if args.json_out:
|
| 95 |
args.json_out.parent.mkdir(parents=True, exist_ok=True)
|
| 96 |
args.json_out.write_text(json.dumps(summary, indent=2) + "\n")
|
|
|
|
| 19 |
parser.add_argument("--damping", type=float, default=1e-3)
|
| 20 |
parser.add_argument("--output", type=Path, required=True)
|
| 21 |
parser.add_argument("--json-out", type=Path, default=None)
|
| 22 |
+
parser.add_argument("--en-json", type=Path, default=None, help="raw EN calibration.json, for provenance")
|
| 23 |
+
parser.add_argument("--ja-json", type=Path, default=None, help="raw JA calibration.json, for provenance")
|
| 24 |
return parser.parse_args()
|
| 25 |
|
| 26 |
|
|
|
|
| 79 |
)
|
| 80 |
|
| 81 |
args.output.parent.mkdir(parents=True, exist_ok=True)
|
| 82 |
+
tmp = args.output.with_name(args.output.name + ".tmp.npz")
|
| 83 |
np.savez(tmp, **arrays)
|
| 84 |
os.replace(tmp, args.output)
|
| 85 |
|
| 86 |
+
sources = {}
|
| 87 |
+
for key, path in (("en", args.en_json), ("ja", args.ja_json)):
|
| 88 |
+
if path and path.exists():
|
| 89 |
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
| 90 |
+
sources[key] = {
|
| 91 |
+
name: payload.get(name)
|
| 92 |
+
for name in ("corpus", "samples", "max_tokens", "output_block", "damping", "raw_output", "overlap_checked")
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
summary = {
|
| 96 |
"en": str(args.en),
|
| 97 |
"ja": str(args.ja),
|
|
|
|
| 100 |
"arrays": len(arrays),
|
| 101 |
"overlap_checked": True,
|
| 102 |
"calibration_corpora": [str(args.en), str(args.ja)],
|
| 103 |
+
"sources": sources,
|
| 104 |
"records": records,
|
| 105 |
}
|
| 106 |
+
# carry the shared calibration settings so downstream audits can compare them
|
| 107 |
+
for name in ("samples", "max_tokens", "output_block"):
|
| 108 |
+
values = {source.get(name) for source in sources.values() if source.get(name) is not None}
|
| 109 |
+
if len(values) == 1:
|
| 110 |
+
summary[name] = values.pop()
|
| 111 |
+
elif len(values) > 1:
|
| 112 |
+
print(f"warning: {name} differs between en and ja: {values}")
|
| 113 |
+
corpora = [source.get("corpus") for source in sources.values() if source.get("corpus")]
|
| 114 |
+
if corpora:
|
| 115 |
+
summary["corpus"] = corpora
|
| 116 |
if args.json_out:
|
| 117 |
args.json_out.parent.mkdir(parents=True, exist_ok=True)
|
| 118 |
args.json_out.write_text(json.dumps(summary, indent=2) + "\n")
|
scripts/pull_results.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Pull a results repository and summarise what landed.
|
| 3 |
+
|
| 4 |
+
The Kaggle operator uploads ``<lane>/manifest.json`` + per-condition JSON to
|
| 5 |
+
``<user>/uzu-results``. This downloads it and prints what is complete, what is
|
| 6 |
+
missing, and whether any manifest reported problems, so nobody has to eyeball a
|
| 7 |
+
directory tree.
|
| 8 |
+
|
| 9 |
+
Usage:
|
| 10 |
+
python scripts/pull_results.py --repo kentasatomuse/uzu-results --out results/kentasatomuse
|
| 11 |
+
python scripts/pull_results.py --out results/kentasatomuse --skip-download
|
| 12 |
+
python scripts/pull_results.py --repo ... --out ... --json results/summary.json
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
from __future__ import annotations
|
| 16 |
+
|
| 17 |
+
import argparse
|
| 18 |
+
import json
|
| 19 |
+
import subprocess
|
| 20 |
+
import sys
|
| 21 |
+
from pathlib import Path
|
| 22 |
+
from typing import Any
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def load_manifests(root: Path) -> list[dict[str, Any]]:
|
| 26 |
+
manifests = []
|
| 27 |
+
for path in sorted(root.rglob("manifest.json")):
|
| 28 |
+
try:
|
| 29 |
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
| 30 |
+
except json.JSONDecodeError:
|
| 31 |
+
print(f"skip unreadable {path}")
|
| 32 |
+
continue
|
| 33 |
+
payload["_path"] = str(path)
|
| 34 |
+
manifests.append(payload)
|
| 35 |
+
return manifests
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def summarise(root: Path) -> dict[str, Any]:
|
| 39 |
+
manifests = load_manifests(root)
|
| 40 |
+
lanes = []
|
| 41 |
+
total_conditions = 0
|
| 42 |
+
problems: list[str] = []
|
| 43 |
+
for manifest in manifests:
|
| 44 |
+
results = manifest.get("results", [])
|
| 45 |
+
lane = {
|
| 46 |
+
"lane": manifest.get("lane") or Path(manifest["_path"]).parent.name,
|
| 47 |
+
"conditions": len(results),
|
| 48 |
+
"complete": sum(1 for result in results if result.get("status") == "complete"),
|
| 49 |
+
"problems": manifest.get("problems", []),
|
| 50 |
+
"spec": manifest.get("spec"),
|
| 51 |
+
"updated": manifest.get("updated"),
|
| 52 |
+
"path": manifest["_path"],
|
| 53 |
+
}
|
| 54 |
+
total_conditions += lane["conditions"]
|
| 55 |
+
problems.extend(f"{lane['lane']}: {problem}" for problem in lane["problems"])
|
| 56 |
+
lanes.append(lane)
|
| 57 |
+
return {
|
| 58 |
+
"lanes": lanes,
|
| 59 |
+
"lane_count": len(lanes),
|
| 60 |
+
"condition_count": total_conditions,
|
| 61 |
+
"problems": problems,
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def format_table(summary: dict[str, Any]) -> str:
|
| 66 |
+
lines = ["| lane | conditions | complete | problems | updated |", "|---|---:|---:|---:|---|"]
|
| 67 |
+
for lane in summary["lanes"]:
|
| 68 |
+
lines.append(
|
| 69 |
+
f"| {lane['lane']} | {lane['conditions']} | {lane['complete']} "
|
| 70 |
+
f"| {len(lane['problems'])} | {lane.get('updated') or '-'} |"
|
| 71 |
+
)
|
| 72 |
+
return "\n".join(lines)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def download(repo: str, out: Path, revision: str | None) -> None:
|
| 76 |
+
command = ["hf", "download", repo, "--repo-type", "dataset", "--local-dir", str(out)]
|
| 77 |
+
if revision:
|
| 78 |
+
command += ["--revision", revision]
|
| 79 |
+
print("$ " + " ".join(command), flush=True)
|
| 80 |
+
subprocess.run(command, check=False)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def main() -> None:
|
| 84 |
+
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
| 85 |
+
parser.add_argument("--repo", default=None, help="HF dataset repo, e.g. <user>/uzu-results")
|
| 86 |
+
parser.add_argument("--revision", default=None)
|
| 87 |
+
parser.add_argument("--out", type=Path, required=True)
|
| 88 |
+
parser.add_argument("--skip-download", action="store_true")
|
| 89 |
+
parser.add_argument("--json", type=Path, default=None)
|
| 90 |
+
parser.add_argument("--strict", action="store_true", help="exit 1 when a manifest reports problems")
|
| 91 |
+
args = parser.parse_args()
|
| 92 |
+
|
| 93 |
+
if not args.skip_download:
|
| 94 |
+
if not args.repo:
|
| 95 |
+
parser.error("--repo is required unless --skip-download is set")
|
| 96 |
+
download(args.repo, args.out, args.revision)
|
| 97 |
+
|
| 98 |
+
if not args.out.exists():
|
| 99 |
+
raise SystemExit(f"nothing at {args.out}")
|
| 100 |
+
|
| 101 |
+
summary = summarise(args.out)
|
| 102 |
+
print(json.dumps(summary, indent=2, ensure_ascii=False)[:1500])
|
| 103 |
+
print()
|
| 104 |
+
print(format_table(summary))
|
| 105 |
+
print(f"\nlanes: {summary['lane_count']} conditions: {summary['condition_count']}")
|
| 106 |
+
if summary["problems"]:
|
| 107 |
+
print("PROBLEMS")
|
| 108 |
+
for problem in summary["problems"]:
|
| 109 |
+
print(f" - {problem}")
|
| 110 |
+
if args.strict:
|
| 111 |
+
raise SystemExit(1)
|
| 112 |
+
if args.json:
|
| 113 |
+
args.json.parent.mkdir(parents=True, exist_ok=True)
|
| 114 |
+
args.json.write_text(json.dumps(summary, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
| 115 |
+
print(f"wrote {args.json}")
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
if __name__ == "__main__":
|
| 119 |
+
main()
|
scripts/qad_finetune.py
CHANGED
|
@@ -53,6 +53,17 @@ def parse_args() -> argparse.Namespace:
|
|
| 53 |
parser.add_argument("--seq", type=int, default=128)
|
| 54 |
parser.add_argument("--lr", type=float, default=1e-4)
|
| 55 |
parser.add_argument("--muon-lr", type=float, default=1e-3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
parser.add_argument(
|
| 57 |
"--optimizer",
|
| 58 |
choices=("muon", "adamw"),
|
|
@@ -184,9 +195,10 @@ def main() -> None:
|
|
| 184 |
|
| 185 |
def collect_params(model):
|
| 186 |
params = {}
|
|
|
|
| 187 |
for path, leaf in jax.tree_util.tree_flatten_with_path(model)[0]:
|
| 188 |
key = jax.tree_util.keystr(path)
|
| 189 |
-
if any(name in key for name in
|
| 190 |
params[key] = leaf
|
| 191 |
return params
|
| 192 |
|
|
@@ -256,6 +268,11 @@ def main() -> None:
|
|
| 256 |
|
| 257 |
params = clamp_scales(params)
|
| 258 |
opt_state = optimizer.init(params)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
|
| 260 |
def loss_fn(current_params, ids):
|
| 261 |
model = inject_params(student, current_params)
|
|
@@ -269,8 +286,10 @@ def main() -> None:
|
|
| 269 |
return kl * (temperature**2)
|
| 270 |
|
| 271 |
@jax.jit
|
| 272 |
-
def train_step(current_params, opt_state, ids):
|
| 273 |
loss, grads = jax.value_and_grad(loss_fn)(current_params, ids)
|
|
|
|
|
|
|
| 274 |
grad_norm = optax.global_norm(grads)
|
| 275 |
updates, new_state = optimizer.update(grads, opt_state, current_params)
|
| 276 |
new_params = optax.apply_updates(current_params, updates)
|
|
@@ -311,6 +330,8 @@ def main() -> None:
|
|
| 311 |
"adam_b1": args.adam_b1,
|
| 312 |
"adam_b2": args.adam_b2,
|
| 313 |
"scale_min": args.scale_min,
|
|
|
|
|
|
|
| 314 |
}
|
| 315 |
|
| 316 |
def save_checkpoint(step: int, current_params, current_state, current_rng) -> None:
|
|
@@ -404,7 +425,10 @@ def main() -> None:
|
|
| 404 |
for step in range(start_step, args.steps):
|
| 405 |
ids = chunks[int(rng.integers(0, len(chunks)))]
|
| 406 |
step_started = time.time()
|
| 407 |
-
|
|
|
|
|
|
|
|
|
|
| 408 |
jax.block_until_ready(params)
|
| 409 |
now = time.time()
|
| 410 |
loss_value = float(loss)
|
|
|
|
| 53 |
parser.add_argument("--seq", type=int, default=128)
|
| 54 |
parser.add_argument("--lr", type=float, default=1e-4)
|
| 55 |
parser.add_argument("--muon-lr", type=float, default=1e-3)
|
| 56 |
+
parser.add_argument(
|
| 57 |
+
"--freeze-scales",
|
| 58 |
+
action="store_true",
|
| 59 |
+
help="train master_weights only; leave scales and zero-points fixed",
|
| 60 |
+
)
|
| 61 |
+
parser.add_argument(
|
| 62 |
+
"--warmup-steps",
|
| 63 |
+
type=int,
|
| 64 |
+
default=0,
|
| 65 |
+
help="linearly ramp the learning rate over this many steps",
|
| 66 |
+
)
|
| 67 |
parser.add_argument(
|
| 68 |
"--optimizer",
|
| 69 |
choices=("muon", "adamw"),
|
|
|
|
| 195 |
|
| 196 |
def collect_params(model):
|
| 197 |
params = {}
|
| 198 |
+
trainable = ("master_weights",) if args.freeze_scales else ("master_weights", "scales", "master_zero_points")
|
| 199 |
for path, leaf in jax.tree_util.tree_flatten_with_path(model)[0]:
|
| 200 |
key = jax.tree_util.keystr(path)
|
| 201 |
+
if any(name in key for name in trainable) and isinstance(leaf, jax.Array):
|
| 202 |
params[key] = leaf
|
| 203 |
return params
|
| 204 |
|
|
|
|
| 268 |
|
| 269 |
params = clamp_scales(params)
|
| 270 |
opt_state = optimizer.init(params)
|
| 271 |
+
print(
|
| 272 |
+
f"trainable: {'master_weights only' if args.freeze_scales else 'master_weights + scales + zero_points'}"
|
| 273 |
+
f" warmup_steps={args.warmup_steps}",
|
| 274 |
+
flush=True,
|
| 275 |
+
)
|
| 276 |
|
| 277 |
def loss_fn(current_params, ids):
|
| 278 |
model = inject_params(student, current_params)
|
|
|
|
| 286 |
return kl * (temperature**2)
|
| 287 |
|
| 288 |
@jax.jit
|
| 289 |
+
def train_step(current_params, opt_state, ids, lr_factor):
|
| 290 |
loss, grads = jax.value_and_grad(loss_fn)(current_params, ids)
|
| 291 |
+
if args.warmup_steps > 0:
|
| 292 |
+
grads = jax.tree_util.tree_map(lambda grad: grad * lr_factor, grads)
|
| 293 |
grad_norm = optax.global_norm(grads)
|
| 294 |
updates, new_state = optimizer.update(grads, opt_state, current_params)
|
| 295 |
new_params = optax.apply_updates(current_params, updates)
|
|
|
|
| 330 |
"adam_b1": args.adam_b1,
|
| 331 |
"adam_b2": args.adam_b2,
|
| 332 |
"scale_min": args.scale_min,
|
| 333 |
+
"freeze_scales": bool(args.freeze_scales),
|
| 334 |
+
"warmup_steps": args.warmup_steps,
|
| 335 |
}
|
| 336 |
|
| 337 |
def save_checkpoint(step: int, current_params, current_state, current_rng) -> None:
|
|
|
|
| 425 |
for step in range(start_step, args.steps):
|
| 426 |
ids = chunks[int(rng.integers(0, len(chunks)))]
|
| 427 |
step_started = time.time()
|
| 428 |
+
lr_factor = 1.0
|
| 429 |
+
if args.warmup_steps > 0:
|
| 430 |
+
lr_factor = min(1.0, (step + 1) / args.warmup_steps)
|
| 431 |
+
params, opt_state, loss, grad_norm = train_step(params, opt_state, ids, lr_factor)
|
| 432 |
jax.block_until_ready(params)
|
| 433 |
now = time.time()
|
| 434 |
loss_value = float(loss)
|
scripts/run_lane.py
CHANGED
|
@@ -38,6 +38,57 @@ DEFAULT_CONDITION = {
|
|
| 38 |
"raw_output": False,
|
| 39 |
}
|
| 40 |
DEFAULT_EVAL = {"max_sequences": 100, "max_tokens": 128, "min_tokens": 16}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
|
| 43 |
class Runner:
|
|
@@ -60,6 +111,13 @@ class Runner:
|
|
| 60 |
"copy": self._script(paths.get("copy", "scripts/make_lalamo_eval_copy.py")),
|
| 61 |
}
|
| 62 |
self.lane = spec.get("lane") or spec_path.stem
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
self.lane_dir = work / "out" / self.lane
|
| 64 |
self.jax_platform = paths.get("jax_platform") or os.environ.get("JAX_PLATFORM_NAME") or None
|
| 65 |
|
|
@@ -75,15 +133,30 @@ class Runner:
|
|
| 75 |
path = Path(value).expanduser()
|
| 76 |
return path if path.is_absolute() else self.kit / path
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
def run(self, step: str, command: list[str], log: Path) -> None:
|
| 79 |
display = " ".join(str(part) for part in command)
|
| 80 |
print(f"$ {display}", flush=True)
|
| 81 |
self.commands.append([str(part) for part in command])
|
| 82 |
if self.dry_run:
|
| 83 |
return
|
| 84 |
-
env =
|
| 85 |
-
if self.jax_platform:
|
| 86 |
-
env["JAX_PLATFORM_NAME"] = self.jax_platform
|
| 87 |
started = time.time()
|
| 88 |
with log.open("a", encoding="utf-8") as handle:
|
| 89 |
handle.write(f"\n=== {step} {time.strftime('%H:%M:%S')} ===\n$ {display}\n")
|
|
@@ -112,6 +185,11 @@ class Runner:
|
|
| 112 |
return target
|
| 113 |
|
| 114 |
source = self.resolve(model.get("bf16_source"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
if source and (source / "model.safetensors").exists():
|
| 116 |
print(f"copy bf16 from {source} -> {target}", flush=True)
|
| 117 |
if not self.dry_run:
|
|
@@ -376,6 +454,10 @@ class Runner:
|
|
| 376 |
str(merged),
|
| 377 |
"--json-out",
|
| 378 |
str(out / "calibration.json"),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 379 |
],
|
| 380 |
out / "lane.log",
|
| 381 |
)
|
|
@@ -485,6 +567,11 @@ def main() -> None:
|
|
| 485 |
parser.add_argument("--hf-results", default=None, help="upload <lane_dir> to this HF dataset repo")
|
| 486 |
parser.add_argument("--skip-merge", action="store_true")
|
| 487 |
parser.add_argument("--work", default=None, help="override spec.paths.work")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 488 |
args = parser.parse_args()
|
| 489 |
|
| 490 |
spec = json.loads(args.spec.read_text(encoding="utf-8"))
|
|
@@ -492,6 +579,22 @@ def main() -> None:
|
|
| 492 |
if not conditions and not spec.get("merge"):
|
| 493 |
raise SystemExit("spec has no conditions")
|
| 494 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 495 |
runner = Runner(spec, args.spec, dry_run=args.dry_run)
|
| 496 |
if args.work:
|
| 497 |
runner.work = Path(args.work).expanduser()
|
|
|
|
| 38 |
"raw_output": False,
|
| 39 |
}
|
| 40 |
DEFAULT_EVAL = {"max_sequences": 100, "max_tokens": 128, "min_tokens": 16}
|
| 41 |
+
TRITON_MIN_CAPABILITY = 8.0
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def parse_compute_capabilities(output: str) -> list[float]:
|
| 45 |
+
capabilities = []
|
| 46 |
+
for line in output.splitlines():
|
| 47 |
+
text = line.strip().split(",")[0].strip()
|
| 48 |
+
try:
|
| 49 |
+
capabilities.append(float(text))
|
| 50 |
+
except ValueError:
|
| 51 |
+
continue
|
| 52 |
+
return capabilities
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def needs_triton_off(capabilities: list[float]) -> bool:
|
| 56 |
+
"""XLA's Triton GEMM path only supports Ampere (cc 8.0) and newer."""
|
| 57 |
+
return any(capability < TRITON_MIN_CAPABILITY for capability in capabilities)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def detect_compute_capabilities() -> list[float]:
|
| 61 |
+
try:
|
| 62 |
+
result = subprocess.run(
|
| 63 |
+
["nvidia-smi", "--query-gpu=compute_cap", "--format=csv,noheader"],
|
| 64 |
+
text=True,
|
| 65 |
+
capture_output=True,
|
| 66 |
+
check=False,
|
| 67 |
+
timeout=20,
|
| 68 |
+
)
|
| 69 |
+
except (OSError, subprocess.TimeoutExpired):
|
| 70 |
+
return []
|
| 71 |
+
if result.returncode != 0:
|
| 72 |
+
return []
|
| 73 |
+
return parse_compute_capabilities(result.stdout)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def find_dataset_dir(root: Path, name: str) -> Path | None:
|
| 77 |
+
"""Locate a mounted dataset regardless of the /kaggle/input layout."""
|
| 78 |
+
candidates = [
|
| 79 |
+
root / name,
|
| 80 |
+
*sorted(root.glob(f"datasets/*/{name}")),
|
| 81 |
+
*sorted(root.glob(f"datasets/*/*/{name}")),
|
| 82 |
+
]
|
| 83 |
+
for candidate in candidates:
|
| 84 |
+
if (candidate / "model.safetensors").exists():
|
| 85 |
+
return candidate
|
| 86 |
+
# last resort: any directory with both weights and a tokenizer
|
| 87 |
+
for weights in sorted(root.rglob("model.safetensors")):
|
| 88 |
+
directory = weights.parent
|
| 89 |
+
if (directory / "tokenizer.json").exists():
|
| 90 |
+
return directory
|
| 91 |
+
return None
|
| 92 |
|
| 93 |
|
| 94 |
class Runner:
|
|
|
|
| 111 |
"copy": self._script(paths.get("copy", "scripts/make_lalamo_eval_copy.py")),
|
| 112 |
}
|
| 113 |
self.lane = spec.get("lane") or spec_path.stem
|
| 114 |
+
capabilities = detect_compute_capabilities()
|
| 115 |
+
self.triton_off = needs_triton_off(capabilities)
|
| 116 |
+
if self.triton_off:
|
| 117 |
+
print(
|
| 118 |
+
f"GPU caps {capabilities}: disabling XLA Triton GEMM (needs >= {TRITON_MIN_CAPABILITY})",
|
| 119 |
+
flush=True,
|
| 120 |
+
)
|
| 121 |
self.lane_dir = work / "out" / self.lane
|
| 122 |
self.jax_platform = paths.get("jax_platform") or os.environ.get("JAX_PLATFORM_NAME") or None
|
| 123 |
|
|
|
|
| 133 |
path = Path(value).expanduser()
|
| 134 |
return path if path.is_absolute() else self.kit / path
|
| 135 |
|
| 136 |
+
def environment(self, base: dict[str, str] | None = None) -> dict[str, str]:
|
| 137 |
+
env = dict(os.environ if base is None else base)
|
| 138 |
+
if self.jax_platform:
|
| 139 |
+
env["JAX_PLATFORM_NAME"] = self.jax_platform
|
| 140 |
+
for key, value in (self.spec.get("paths", {}).get("env") or {}).items():
|
| 141 |
+
env[str(key)] = str(value)
|
| 142 |
+
flags = list(self.spec.get("paths", {}).get("xla_flags", []))
|
| 143 |
+
if self.triton_off:
|
| 144 |
+
flags.append("--xla_gpu_enable_triton_gemm=false")
|
| 145 |
+
existing = env.get("XLA_FLAGS", "")
|
| 146 |
+
for flag in flags:
|
| 147 |
+
if flag not in existing:
|
| 148 |
+
existing = (existing + " " + flag).strip()
|
| 149 |
+
if existing:
|
| 150 |
+
env["XLA_FLAGS"] = existing
|
| 151 |
+
return env
|
| 152 |
+
|
| 153 |
def run(self, step: str, command: list[str], log: Path) -> None:
|
| 154 |
display = " ".join(str(part) for part in command)
|
| 155 |
print(f"$ {display}", flush=True)
|
| 156 |
self.commands.append([str(part) for part in command])
|
| 157 |
if self.dry_run:
|
| 158 |
return
|
| 159 |
+
env = self.environment()
|
|
|
|
|
|
|
| 160 |
started = time.time()
|
| 161 |
with log.open("a", encoding="utf-8") as handle:
|
| 162 |
handle.write(f"\n=== {step} {time.strftime('%H:%M:%S')} ===\n$ {display}\n")
|
|
|
|
| 185 |
return target
|
| 186 |
|
| 187 |
source = self.resolve(model.get("bf16_source"))
|
| 188 |
+
if source and not (source / "model.safetensors").exists() and model.get("bf16_source_auto"):
|
| 189 |
+
found = find_dataset_dir(Path("/kaggle/input"), source.name)
|
| 190 |
+
if found is not None:
|
| 191 |
+
print(f"bf16 source resolved to {found}", flush=True)
|
| 192 |
+
source = found
|
| 193 |
if source and (source / "model.safetensors").exists():
|
| 194 |
print(f"copy bf16 from {source} -> {target}", flush=True)
|
| 195 |
if not self.dry_run:
|
|
|
|
| 454 |
str(merged),
|
| 455 |
"--json-out",
|
| 456 |
str(out / "calibration.json"),
|
| 457 |
+
"--en-json",
|
| 458 |
+
str(self.lane_dir / merge["en"] / "calibration.json"),
|
| 459 |
+
"--ja-json",
|
| 460 |
+
str(self.lane_dir / merge["ja"] / "calibration.json"),
|
| 461 |
],
|
| 462 |
out / "lane.log",
|
| 463 |
)
|
|
|
|
| 567 |
parser.add_argument("--hf-results", default=None, help="upload <lane_dir> to this HF dataset repo")
|
| 568 |
parser.add_argument("--skip-merge", action="store_true")
|
| 569 |
parser.add_argument("--work", default=None, help="override spec.paths.work")
|
| 570 |
+
parser.add_argument(
|
| 571 |
+
"--shard",
|
| 572 |
+
default=None,
|
| 573 |
+
help="run only part of the condition list, e.g. 0/3. Merges are not allowed with sharding.",
|
| 574 |
+
)
|
| 575 |
args = parser.parse_args()
|
| 576 |
|
| 577 |
spec = json.loads(args.spec.read_text(encoding="utf-8"))
|
|
|
|
| 579 |
if not conditions and not spec.get("merge"):
|
| 580 |
raise SystemExit("spec has no conditions")
|
| 581 |
|
| 582 |
+
if args.shard:
|
| 583 |
+
if spec.get("merge"):
|
| 584 |
+
raise SystemExit("--shard cannot be combined with spec.merge")
|
| 585 |
+
try:
|
| 586 |
+
index_text, count_text = args.shard.split("/")
|
| 587 |
+
index, count = int(index_text), int(count_text)
|
| 588 |
+
except ValueError:
|
| 589 |
+
raise SystemExit("--shard must look like 0/3")
|
| 590 |
+
if count <= 0 or not 0 <= index < count:
|
| 591 |
+
raise SystemExit("--shard index out of range")
|
| 592 |
+
conditions = [condition for position, condition in enumerate(conditions) if position % count == index]
|
| 593 |
+
if not conditions:
|
| 594 |
+
raise SystemExit(f"shard {args.shard} has no conditions")
|
| 595 |
+
spec["conditions"] = conditions
|
| 596 |
+
spec["lane"] = f"{spec['lane']}-shard{index + 1}of{count}"
|
| 597 |
+
|
| 598 |
runner = Runner(spec, args.spec, dry_run=args.dry_run)
|
| 599 |
if args.work:
|
| 600 |
runner.work = Path(args.work).expanduser()
|