yamahei21 commited on
Commit
d2136d7
·
verified ·
1 Parent(s): 5e00f9a

Rebuild: XLA attention on T4, calib dtype, quota ledger

Browse files
kit_manifest.json CHANGED
@@ -1,21 +1,23 @@
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",
@@ -24,7 +26,7 @@
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,16 +35,17 @@
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",
46
  "tests/test_tiny_sharding.py": "eaed062b5547ed66923d567753494fe2c26d15c7df4a160601182aacdbf0ceb1",
47
  "configs/qwen35-0.8b.json": "12640a7b738d8c8dbc046f59e9249b85d5d3775b8ee2afe9becaba285ae90764",
48
  "configs/qwen35-4b.json": "8f32da42655963134c1f73f4fa825c8ae16b464254d4fd9ddccf6b2f8ecae833",
 
1
  {
2
+ "built_from_commit": "6cd35afd5dc2643aa317d19781ba43441181ddd8",
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": "1b3a6d7b2099a87c773093c1f03444be0160d4d98aaeac061560836e982f869d",
9
  "scripts/merge_language_hessians.py": "a6385caaa0d7190024b4e47ded59d1ab662e771ce81e18de94b30c8846829b4e",
10
  "scripts/merge_calibration_groups.py": "58a347ff40c47f629c073c23aea54e215c1e75c052737e5b4a48ff81946d8060",
11
+ "scripts/eval_quantized.py": "f5a1bcf8972e258f99b563934430779642473a54b5bfa4c31cfe2a28b0a424fb",
12
+ "scripts/qad_finetune.py": "26830bf55203a6a2e7fd79451c400949a1f6cdd1fc8d4011b62ff59d39c6e486",
13
  "scripts/compute_bpc.py": "2b55fd1df406d54b40daeeca2ecaf2efb35981655f5bf5e0cc10c057ce796256",
14
+ "scripts/run_lane.py": "d5137c69ce30024e54d1fe61274963b53a8d38654d1aa4c986fbd48054cc8596",
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": "22c9a1ba1b93f360191d08f5992dceee40b168010de98aeff78ac7e219395342",
19
+ "scripts/lalamo_forward.py": "e4429221ecb6127faae9a5770bcc16d4e72d7c5ab7a7e2171477266be820745a",
20
+ "scripts/kaggle_usage.py": "e1c4c1a902d716e09a9b8fce9a0019b152a758f2390dd34c678fc44c7aef48b1",
21
  "scripts/eval_generation.py": "bc240aef06c6ede583c3334fd0483ca9153ca07a52e22ef53c85c0b4fb90f7d2",
22
  "scripts/pull_results.py": "e5873cfda71dcebcf86e1ecfaacefc9bf01a142521d06c065654eaea7d07de5c",
23
  "scripts/corpus_guard.py": "5f226a81988acaebd80b8b81dfb4207ed8b661e52067b0260deec6ee48e9af6a",
 
26
  "scripts/check_experiment.py": "a2e7e40909f68031dfccd7013ed055dfbc0ebb21f2a619622b71e6772c685ca5",
27
  "scripts/tiny_sharding_probe.py": "29eb58f2689242b919616f6aab6ff753e0de031b16371137975b4d645e836fae",
28
  "scripts/audit_public_corpus.py": "84f1ec805a74004e71f63a70a8ed19967cb3fad9966f254798e655ab95e53ab0",
29
+ "scripts/build_kit.py": "b60973e4a7de8167284e128e7f812384ebc01b44a138440132a9ceaed84c8126",
30
  "scripts/bootstrap_kaggle.py": "1633e3edbb80976c337444e3e4544e2b5210b2d8d1821e3a2717c1099c00843e",
31
  "data/calibration_en_wikitext2_dedup.txt": "18a79f4f938cc25747a90a12b120c7131e7f4ac55b58dfc691795ea61d4b5e9a",
32
  "data/calibration_ja_wikipedia_dedup.txt": "b45e3f3f00f2137be280a75c1fa9c9883a7e69d289257c4388fc701f33fee0d1",
 
35
  "data/calibration_mixed_ja65_en35_dedup.txt": "36e17429433759bbad53cf62dbca2d880abe716d60b3bb32fc7b7ca96bb093e1",
36
  "data/eval_en_wikitext2_dedup.txt": "342e8f6a77fb9db7e1a14aa7cabe13c1f13eeaa4f045f8fb3689c0b26c742c0e",
37
  "data/eval_ja_wikipedia_dedup.txt": "707c9a6c951dd0b831c746a5d6e6972e4dbc71498e75c4aa8f12140eeed89213",
38
+ "lanes/README.md": "44743cd2b9831d0a2249da307c031f70b2822ca71339db7182964e71d8b4a887",
39
  "lanes/smoke-08b.json": "de6e66bf9c37325c6efb0c5a37f3b4edb7df500a27a481b24337ddad3df916ee",
40
  "lanes/clean-suite-08b.json": "a1b74a5f2b7a36edc3fe060ec071df27bcbafe7975fd46ba3562b77458d94b99",
41
  "lanes/balanced-h-08b.json": "21a16d50b0b5096843e0a8fb944a6fdbb7314f3c2c51618eb9651a7575192cb8",
42
+ "lanes/damping-ablation-08b.json": "bb0a635c8b3e2b80d701af45c3561bbc9570af01614a800ee3acef3dccd22c1a",
43
  "lanes/robustness-08b-shard1of3.json": "11bd73ddfb110c60420546e1c6f47d777ce6d8c321cf31ce5003d15c96743b9b",
44
  "lanes/robustness-08b-shard2of3.json": "3196a32cf56eb1e3792a4f15a29effa561ff0472d82282f5e98ad8e283249935",
45
  "lanes/robustness-08b-shard3of3.json": "3f6928c34d3145d7d17eda991e6dede3695a0e9b723fbf4c068a6c07bc9cfd17",
46
  "tests/test_experiment_guards.py": "d71ddf9586c1d7ece52e217288b9d4b09079be54d32ceaf391be113c1832b6ef",
47
  "tests/test_compute_bpc.py": "bba5b6d0afc9b0699ebb6f7f0ed9fc5ebfcb98472867e9ccff4262fe9999949f",
48
+ "tests/test_run_lane.py": "222939127650e04d98a9e3da52ec2f972bb45a030eb297cd2f59e3f3a9496139",
49
  "tests/test_tiny_sharding.py": "eaed062b5547ed66923d567753494fe2c26d15c7df4a160601182aacdbf0ceb1",
50
  "configs/qwen35-0.8b.json": "12640a7b738d8c8dbc046f59e9249b85d5d3775b8ee2afe9becaba285ae90764",
51
  "configs/qwen35-4b.json": "8f32da42655963134c1f73f4fa825c8ae16b464254d4fd9ddccf6b2f8ecae833",
lanes/README.md CHANGED
@@ -54,6 +54,15 @@ T4(compute capability 7.5)では XLA の Triton GEMM が使えず、calibrat
54
  - 明示的に足したい場合は `paths.xla_flags` に書く
55
  - 検出できなかった場合は何も足さない。その場合は spec に書く
56
 
 
 
 
 
 
 
 
 
 
57
  ## シャード実行
58
 
59
  1 セッション 12h を跨ぐ条件列は、spec を分けるか `--shard` で切る。
 
54
  - 明示的に足したい場合は `paths.xla_flags` に書く
55
  - 検出できなかった場合は何も足さない。その場合は spec に書く
56
 
57
+ さらに lalamo の推論は既定で **Pallas-Triton flash attention** を使い、これも T4 ではコンパイルできない。
58
+ `run_lane` は cc < 8.0 を検出すると `UZU_ATTENTION_IMPL=xla` も渡す(`scripts/lalamo_forward.py`)。
59
+ 手動で切り替える場合:
60
+
61
+ ```bash
62
+ UZU_ATTENTION_IMPL=xla python scripts/eval_quantized.py ...
63
+ UZU_ATTENTION_IMPL=pallas ... # 既定に戻す
64
+ ```
65
+
66
  ## シャード実行
67
 
68
  1 セッション 12h を跨ぐ条件列は、spec を分けるか `--shard` で切る。
lanes/damping-ablation-08b.json ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "lane": "damping-ablation-08b",
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.01,
30
+ "calib_dtype": "float32",
31
+ "raw_output": false
32
+ },
33
+ "convert": {
34
+ "bits": 4,
35
+ "group_size": 32,
36
+ "block_size": 32,
37
+ "parallel": "tensor"
38
+ },
39
+ "conditions": [
40
+ {"name": "enonly-d1e-2", "calibration_corpus": "data/calibration_en_wikitext2_dedup.txt"},
41
+ {"name": "mixed50-d1e-2", "calibration_corpus": "data/calibration_mixed_en_ja_dedup.txt"}
42
+ ]
43
+ }
scripts/ag_fetch.py CHANGED
@@ -70,6 +70,20 @@ def last_final(log_path: Path) -> str | None:
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:
 
70
  return final
71
 
72
 
73
+ def log_completed(log_path: Path) -> bool:
74
+ """True when the run log already holds a completed response.
75
+
76
+ The wrapper writes its state file only after the process returns, so a dead
77
+ pid plus no state is not proof of failure: the log often has the result.
78
+ """
79
+ if not log_path.exists():
80
+ return False
81
+ for payload in json_objects(log_path.read_text(encoding="utf-8", errors="replace")):
82
+ if isinstance(payload, dict) and payload.get("status") == "completed":
83
+ return True
84
+ return False
85
+
86
+
87
  def recover_from_log(log_path: Path, out_dir: Path) -> Path | None:
88
  final = last_final(log_path)
89
  if not final:
scripts/build_kit.py CHANGED
@@ -47,6 +47,8 @@ KIT_SCRIPTS = [
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
@@ -77,6 +79,7 @@ KIT_LANES = [
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",
 
47
  "combine_lane_manifests.py",
48
  "make_qad_dataset.py",
49
  "ag_fetch.py",
50
+ "lalamo_forward.py",
51
+ "kaggle_usage.py",
52
  "eval_generation.py",
53
  "pull_results.py",
54
  # guards / audits
 
79
  "smoke-08b.json",
80
  "clean-suite-08b.json",
81
  "balanced-h-08b.json",
82
+ "damping-ablation-08b.json",
83
  "robustness-08b-shard1of3.json",
84
  "robustness-08b-shard2of3.json",
85
  "robustness-08b-shard3of3.json",
scripts/eval_quantized.py CHANGED
@@ -126,6 +126,7 @@ def main() -> None:
126
  from lalamo.model import Model
127
  from lalamo.module import Keychain
128
  from lalamo.modules import DecoderForwardPassConfig, ForwardPassMode
 
129
  from lalamo.utils.sharding import ShardingConfig
130
  from tokenizers import Tokenizer
131
 
@@ -150,6 +151,8 @@ def main() -> None:
150
  sharding = ShardingConfig.replicated()
151
  keychain = Keychain.init(seed=0, sharding_config=sharding)
152
  forward_pass_config = DecoderForwardPassConfig.for_inference(mode=ForwardPassMode.MULTI_TOKEN)
 
 
153
 
154
  print("loading BF16 model...")
155
  bf16 = Model.load(args.bf16_dir, sharding, dtype=jnp.bfloat16)
 
126
  from lalamo.model import Model
127
  from lalamo.module import Keychain
128
  from lalamo.modules import DecoderForwardPassConfig, ForwardPassMode
129
+ from lalamo_forward import apply_attention_env, describe
130
  from lalamo.utils.sharding import ShardingConfig
131
  from tokenizers import Tokenizer
132
 
 
151
  sharding = ShardingConfig.replicated()
152
  keychain = Keychain.init(seed=0, sharding_config=sharding)
153
  forward_pass_config = DecoderForwardPassConfig.for_inference(mode=ForwardPassMode.MULTI_TOKEN)
154
+ forward_pass_config = apply_attention_env(forward_pass_config)
155
+ print(f"attention: {describe()}", flush=True)
156
 
157
  print("loading BF16 model...")
158
  bf16 = Model.load(args.bf16_dir, sharding, dtype=jnp.bfloat16)
scripts/kaggle_usage.py ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Kaggle GPU usage ledger.
3
+
4
+ Kaggle gives each account ~30 GPU-hours per week, 2 concurrent sessions. The
5
+ number that matters is not "did it finish" but "how many GPU seconds did it
6
+ cost", and nobody was tracking it.
7
+
8
+ # record a finished run by hand
9
+ python scripts/kaggle_usage.py log --kernel yamahei21python/uzu-eval-4b-rtn-probe \
10
+ --account owner --seconds 5420 --gpu T4x2 --note "4B RTN eval v3"
11
+
12
+ # or track it until it stops
13
+ python scripts/kaggle_usage.py track --kernel yamahei21python/uzu-emb8-08b-gpu --account owner
14
+
15
+ # weekly report against the quota
16
+ python scripts/kaggle_usage.py report --week 2026-W45 --quota-hours 30
17
+
18
+ The ledger is JSON Lines so a crashed run cannot corrupt it.
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ import argparse
24
+ import json
25
+ import subprocess
26
+ import time
27
+ from datetime import date, datetime
28
+ from pathlib import Path
29
+ from typing import Any
30
+
31
+ ROOT = Path(__file__).resolve().parents[1]
32
+ LEDGER = ROOT / "logs" / "kaggle_usage.jsonl"
33
+ TERMINAL = ("COMPLETE", "ERROR", "FAILED", "CANCEL", "CANCELLED")
34
+
35
+
36
+ def week_key(value: date) -> str:
37
+ year, week, _ = value.isocalendar()
38
+ return f"{year}-W{week:02d}"
39
+
40
+
41
+ def is_terminal(status: str) -> bool:
42
+ upper = status.upper()
43
+ return any(marker in upper for marker in TERMINAL)
44
+
45
+
46
+ def append_entry(ledger: Path, entry: dict[str, Any]) -> None:
47
+ ledger.parent.mkdir(parents=True, exist_ok=True)
48
+ with ledger.open("a", encoding="utf-8") as handle:
49
+ handle.write(json.dumps(entry, ensure_ascii=False) + "\n")
50
+
51
+
52
+ def read_entries(ledger: Path) -> list[dict[str, Any]]:
53
+ if not ledger.exists():
54
+ return []
55
+ entries = []
56
+ for line in ledger.read_text(encoding="utf-8").splitlines():
57
+ line = line.strip()
58
+ if not line:
59
+ continue
60
+ try:
61
+ entries.append(json.loads(line))
62
+ except json.JSONDecodeError:
63
+ continue
64
+ return entries
65
+
66
+
67
+ def summarize(entries: list[dict[str, Any]], week: str, quota_hours: float) -> dict[str, Any]:
68
+ filtered = [entry for entry in entries if entry.get("week") == week]
69
+ by_account: dict[str, dict[str, Any]] = {}
70
+ for entry in filtered:
71
+ account = entry.get("account", "unknown")
72
+ bucket = by_account.setdefault(account, {"runs": 0, "seconds": 0.0, "kernels": []})
73
+ bucket["runs"] += 1
74
+ bucket["seconds"] += float(entry.get("seconds", 0))
75
+ bucket["kernels"].append(entry.get("kernel"))
76
+ quota_seconds = quota_hours * 3600
77
+ for account, bucket in by_account.items():
78
+ bucket["hours"] = round(bucket["seconds"] / 3600, 2)
79
+ bucket["remaining_hours"] = round((quota_seconds - bucket["seconds"]) / 3600, 2)
80
+ bucket["used_pct"] = round(100 * bucket["seconds"] / quota_seconds, 1) if quota_seconds else None
81
+ total_seconds = sum(bucket["seconds"] for bucket in by_account.values())
82
+ return {
83
+ "week": week,
84
+ "quota_hours_per_account": quota_hours,
85
+ "accounts": by_account,
86
+ "total_hours": round(total_seconds / 3600, 2),
87
+ "runs": len(filtered),
88
+ }
89
+
90
+
91
+ def format_report(summary: dict[str, Any]) -> str:
92
+ lines = [
93
+ f"week {summary['week']} quota {summary['quota_hours_per_account']}h/account runs {summary['runs']}",
94
+ f"{'account':10s} {'hours':>8s} {'left':>8s} {'used':>7s} kernels",
95
+ "-" * 72,
96
+ ]
97
+ for account, bucket in sorted(summary["accounts"].items()):
98
+ kernels = ", ".join(str(name) for name in bucket["kernels"][-3:])
99
+ lines.append(
100
+ f"{account:10s} {bucket['hours']:8.2f} {bucket['remaining_hours']:8.2f} "
101
+ f"{(bucket['used_pct'] or 0):6.1f}% {kernels}"
102
+ )
103
+ return "\n".join(lines)
104
+
105
+
106
+ def kernel_status(kernel: str) -> str:
107
+ result = subprocess.run(
108
+ ["kaggle", "kernels", "status", kernel], text=True, capture_output=True, check=False
109
+ )
110
+ text = (result.stdout or "") + (result.stderr or "")
111
+ for line in text.splitlines():
112
+ if "status" in line.lower():
113
+ return line.strip()
114
+ return text.strip()
115
+
116
+
117
+ def track(kernel: str, account: str, interval: float, ledger: Path) -> dict[str, Any]:
118
+ started = time.time()
119
+ status = ""
120
+ while True:
121
+ status = kernel_status(kernel)
122
+ if is_terminal(status):
123
+ break
124
+ print(f"{time.strftime('%H:%M:%S')} {status}", flush=True)
125
+ time.sleep(interval)
126
+ entry = {
127
+ "kernel": kernel,
128
+ "account": account,
129
+ "seconds": round(time.time() - started, 1),
130
+ "status": status,
131
+ "week": week_key(date.today()),
132
+ "finished": datetime.now().isoformat(timespec="seconds"),
133
+ "note": "tracked",
134
+ }
135
+ append_entry(ledger, entry)
136
+ return entry
137
+
138
+
139
+ def main() -> None:
140
+ parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
141
+ parser.add_argument("--ledger", type=Path, default=LEDGER)
142
+ sub = parser.add_subparsers(dest="command", required=True)
143
+
144
+ log = sub.add_parser("log")
145
+ log.add_argument("--kernel", required=True)
146
+ log.add_argument("--account", default="owner")
147
+ log.add_argument("--seconds", type=float, required=True)
148
+ log.add_argument("--gpu", default="T4x2")
149
+ log.add_argument("--week", default=None)
150
+ log.add_argument("--note", default="")
151
+
152
+ track_cmd = sub.add_parser("track")
153
+ track_cmd.add_argument("--kernel", required=True)
154
+ track_cmd.add_argument("--account", default="owner")
155
+ track_cmd.add_argument("--interval", type=float, default=60.0)
156
+
157
+ report = sub.add_parser("report")
158
+ report.add_argument("--week", default=None)
159
+ report.add_argument("--quota-hours", type=float, default=30.0)
160
+ report.add_argument("--json", type=Path, default=None)
161
+
162
+ args = parser.parse_args()
163
+
164
+ if args.command == "log":
165
+ entry = {
166
+ "kernel": args.kernel,
167
+ "account": args.account,
168
+ "seconds": args.seconds,
169
+ "gpu": args.gpu,
170
+ "week": args.week or week_key(date.today()),
171
+ "logged": datetime.now().isoformat(timespec="seconds"),
172
+ "note": args.note,
173
+ }
174
+ append_entry(args.ledger, entry)
175
+ print(json.dumps(entry, ensure_ascii=False))
176
+ elif args.command == "track":
177
+ entry = track(args.kernel, args.account, args.interval, args.ledger)
178
+ print(json.dumps(entry, ensure_ascii=False))
179
+ else:
180
+ week = args.week or week_key(date.today())
181
+ summary = summarize(read_entries(args.ledger), week, args.quota_hours)
182
+ print(format_report(summary))
183
+ if args.json:
184
+ args.json.parent.mkdir(parents=True, exist_ok=True)
185
+ args.json.write_text(json.dumps(summary, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
186
+ print(f"wrote {args.json}")
187
+
188
+
189
+ if __name__ == "__main__":
190
+ main()
scripts/lalamo_forward.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Force the lalamo attention implementation when the GPU cannot run Pallas.
2
+
3
+ lalamo's inference config defaults to the Pallas-Triton flash attention kernel
4
+ (``MixerForwardPassConfig.for_inference``). Pallas-Triton needs a Triton backend
5
+ that T4 (compute capability 7.5) does not provide, so the first forward fails
6
+ during XLA compilation even with ``--xla_gpu_enable_triton_gemm=false``.
7
+
8
+ ``UZU_ATTENTION_IMPL=xla`` switches the mixer config to the plain XLA path.
9
+ ``pallas`` forces the default back. Anything else (including unset) keeps the
10
+ config as-is.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import os
16
+
17
+ ENV_VAR = "UZU_ATTENTION_IMPL"
18
+
19
+
20
+ def requested() -> str | None:
21
+ value = os.environ.get(ENV_VAR, "").strip().lower()
22
+ return value if value in ("xla", "pallas") else None
23
+
24
+
25
+ def apply_attention_env(config):
26
+ """Return config with the attention implementation overridden, if requested."""
27
+ mode = requested()
28
+ if mode is None:
29
+ return config
30
+
31
+ from dataclasses import replace
32
+
33
+ from lalamo.modules import AttentionImplementation
34
+
35
+ target = AttentionImplementation.XLA if mode == "xla" else AttentionImplementation.PALLAS
36
+ transformer = config.transformer_forward_pass_config
37
+ mixer = transformer.mixer_forward_pass_config
38
+ if getattr(mixer, "attention_implementation", None) == target:
39
+ return config
40
+ return replace(
41
+ config,
42
+ transformer_forward_pass_config=replace(
43
+ transformer,
44
+ mixer_forward_pass_config=replace(mixer, attention_implementation=target),
45
+ ),
46
+ )
47
+
48
+
49
+ def describe() -> str:
50
+ mode = requested()
51
+ return f"attention={mode or 'default'}"
scripts/qad_finetune.py CHANGED
@@ -108,6 +108,7 @@ def main() -> None:
108
 
109
  from lalamo.compressed.hybrid import HybridMatrix
110
  from lalamo.model import Model
 
111
  from lalamo.module import Keychain
112
  from lalamo.modules import DecoderForwardPassConfig, ForwardPassMode
113
  from lalamo.utils.sharding import ShardingConfig
@@ -126,10 +127,15 @@ def main() -> None:
126
  else:
127
  sharding = ShardingConfig.replicated()
128
  keychain = Keychain.init(seed=args.seed, sharding_config=sharding)
129
- inference_config = DecoderForwardPassConfig.for_inference(mode=ForwardPassMode.MULTI_TOKEN)
130
- training_config = DecoderForwardPassConfig.for_training(
131
- gradient_estimator=GradientEstimator.DETERMINISTIC_ROUNDING
132
  )
 
 
 
 
 
 
133
 
134
  def tokenizer_hash(directory: Path) -> str:
135
  return hashlib.sha256((directory / "tokenizer.json").read_bytes()).hexdigest()
 
108
 
109
  from lalamo.compressed.hybrid import HybridMatrix
110
  from lalamo.model import Model
111
+ from lalamo_forward import apply_attention_env, describe
112
  from lalamo.module import Keychain
113
  from lalamo.modules import DecoderForwardPassConfig, ForwardPassMode
114
  from lalamo.utils.sharding import ShardingConfig
 
127
  else:
128
  sharding = ShardingConfig.replicated()
129
  keychain = Keychain.init(seed=args.seed, sharding_config=sharding)
130
+ inference_config = apply_attention_env(
131
+ DecoderForwardPassConfig.for_inference(mode=ForwardPassMode.MULTI_TOKEN)
 
132
  )
133
+ training_config = apply_attention_env(
134
+ DecoderForwardPassConfig.for_training(
135
+ gradient_estimator=GradientEstimator.DETERMINISTIC_ROUNDING
136
+ )
137
+ )
138
+ print(f"attention: {describe()}", flush=True)
139
 
140
  def tokenizer_hash(directory: Path) -> str:
141
  return hashlib.sha256((directory / "tokenizer.json").read_bytes()).hexdigest()
scripts/run_lane.py CHANGED
@@ -31,6 +31,7 @@ from typing import Any
31
 
32
  DEFAULT_CONDITION = {
33
  "samples": 32,
 
34
  "max_tokens": 128,
35
  "output_block": "small",
36
  "output_block_limit": 2048,
@@ -142,6 +143,9 @@ class Runner:
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:
@@ -263,6 +267,7 @@ class Runner:
263
  "max_tokens": base.get("max_tokens"),
264
  "output_block": base.get("output_block"),
265
  "damping": base.get("damping"),
 
266
  "raw_output": base.get("raw_output"),
267
  "ja_ratio": base.get("ja_ratio"),
268
  "overlap_checked": base.get("overlap_checked"),
@@ -350,6 +355,8 @@ class Runner:
350
  ]
351
  for eval_corpus in self.eval_corpora().values():
352
  command += ["--eval-corpus", str(eval_corpus)]
 
 
353
  if settings.get("raw_output"):
354
  command.append("--raw-output")
355
  if self.spec.get("convert", {}).get("parallel"):
 
31
 
32
  DEFAULT_CONDITION = {
33
  "samples": 32,
34
+ "calib_dtype": "float32",
35
  "max_tokens": 128,
36
  "output_block": "small",
37
  "output_block_limit": 2048,
 
143
  flags = list(self.spec.get("paths", {}).get("xla_flags", []))
144
  if self.triton_off:
145
  flags.append("--xla_gpu_enable_triton_gemm=false")
146
+ # lalamo inference defaults to the Pallas-Triton flash attention kernel,
147
+ # which T4 cannot compile. XLA attention is the supported path there.
148
+ env.setdefault("UZU_ATTENTION_IMPL", "xla")
149
  existing = env.get("XLA_FLAGS", "")
150
  for flag in flags:
151
  if flag not in existing:
 
267
  "max_tokens": base.get("max_tokens"),
268
  "output_block": base.get("output_block"),
269
  "damping": base.get("damping"),
270
+ "calib_dtype": base.get("calib_dtype"),
271
  "raw_output": base.get("raw_output"),
272
  "ja_ratio": base.get("ja_ratio"),
273
  "overlap_checked": base.get("overlap_checked"),
 
355
  ]
356
  for eval_corpus in self.eval_corpora().values():
357
  command += ["--eval-corpus", str(eval_corpus)]
358
+ if settings.get("calib_dtype"):
359
+ command += ["--calib-dtype", str(settings["calib_dtype"])]
360
  if settings.get("raw_output"):
361
  command.append("--raw-output")
362
  if self.spec.get("convert", {}).get("parallel"):
scripts/yaqa_calibration.py CHANGED
@@ -114,6 +114,7 @@ def main() -> None:
114
  import numpy as np
115
 
116
  from lalamo.model import Model
 
117
  from lalamo.module import Keychain
118
  from lalamo.modules import DecoderForwardPassConfig, ForwardPassMode
119
  from lalamo.modules.linear import Linear
@@ -131,6 +132,8 @@ def main() -> None:
131
  sharding = ShardingConfig.replicated()
132
  keychain = Keychain.init(seed=args.seed, sharding_config=sharding)
133
  forward_pass_config = DecoderForwardPassConfig.for_inference(mode=ForwardPassMode.MULTI_TOKEN)
 
 
134
 
135
  dtype = jnp.dtype(args.calib_dtype)
136
  if args.hf_repo or args.hf_dir:
 
114
  import numpy as np
115
 
116
  from lalamo.model import Model
117
+ from lalamo_forward import apply_attention_env, describe
118
  from lalamo.module import Keychain
119
  from lalamo.modules import DecoderForwardPassConfig, ForwardPassMode
120
  from lalamo.modules.linear import Linear
 
132
  sharding = ShardingConfig.replicated()
133
  keychain = Keychain.init(seed=args.seed, sharding_config=sharding)
134
  forward_pass_config = DecoderForwardPassConfig.for_inference(mode=ForwardPassMode.MULTI_TOKEN)
135
+ forward_pass_config = apply_attention_env(forward_pass_config)
136
+ print(f"attention: {describe()}", flush=True)
137
 
138
  dtype = jnp.dtype(args.calib_dtype)
139
  if args.hf_repo or args.hf_dir:
tests/test_run_lane.py CHANGED
@@ -71,6 +71,17 @@ def test_smoke_spec_is_cheap_and_single_condition() -> None:
71
  assert all("--max-sequences 2" in line for line in evals)
72
 
73
 
 
 
 
 
 
 
 
 
 
 
 
74
  def test_missing_spec_fields_fail_loudly(tmp_path: Path) -> None:
75
  spec = tmp_path / "bad.json"
76
  spec.write_text(json.dumps({"lane": "bad", "paths": {"kit": "kit", "work": str(tmp_path)}}), encoding="utf-8")
 
71
  assert all("--max-sequences 2" in line for line in evals)
72
 
73
 
74
+ def test_calib_dtype_is_passed_to_calibration() -> None:
75
+ result = run_lane(LANES / "damping-ablation-08b.json")
76
+ assert result.returncode == 0, result.stdout + result.stderr
77
+ calibration = [
78
+ line for line in result.stdout.splitlines() if line.startswith("$ ") and "yaqa_calibration.py" in line
79
+ ]
80
+ assert len(calibration) == 2
81
+ assert all("--calib-dtype float32" in line for line in calibration)
82
+ assert all("--damping 0.01" in line for line in calibration)
83
+
84
+
85
  def test_missing_spec_fields_fail_loudly(tmp_path: Path) -> None:
86
  spec = tmp_path / "bad.json"
87
  spec.write_text(json.dumps({"lane": "bad", "paths": {"kit": "kit", "work": str(tmp_path)}}), encoding="utf-8")