BurnyCoder commited on
Commit
93c0c81
·
verified ·
1 Parent(s): 4115a81

Record recovered adapter pilot and completed training before full validation

Browse files
.gitattributes CHANGED
@@ -34,3 +34,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
  research/reports/paper.pdf filter=lfs diff=lfs merge=lfs -text
 
 
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
  research/reports/paper.pdf filter=lfs diff=lfs merge=lfs -text
37
+ research/docs/figures/curves.png filter=lfs diff=lfs merge=lfs -text
research/docs/explorer.js CHANGED
@@ -81,9 +81,13 @@ function showLedger() {
81
  link.href = repository + "/tree/main/results/" + encodeURIComponent(run.id);
82
  first.append(link);
83
  tr.append(first);
 
 
 
 
84
  for (const value of [methodName(run.method), run.seed ?? "—", number(run.ratio, 3),
85
  number(run.tokens, 0), number(run.dev_nll, 4), number(run.test_nll, 4),
86
- number(run.tokens_per_sec, 0), number(run.peak_vram_mb, 0), run.status]) {
87
  tr.append(node("td", value));
88
  }
89
  body.append(tr);
 
81
  link.href = repository + "/tree/main/results/" + encodeURIComponent(run.id);
82
  first.append(link);
83
  tr.append(first);
84
+ const evaluation = run.evaluation_progress;
85
+ const status = evaluation?.targets_to_score > 0
86
+ ? `${run.status} (${number(100 * evaluation.targets_scored / evaluation.targets_to_score, 1)}%)`
87
+ : run.status;
88
  for (const value of [methodName(run.method), run.seed ?? "—", number(run.ratio, 3),
89
  number(run.tokens, 0), number(run.dev_nll, 4), number(run.test_nll, 4),
90
+ number(run.tokens_per_sec, 0), number(run.peak_vram_mb, 0), status]) {
91
  tr.append(node("td", value));
92
  }
93
  body.append(tr);
research/docs/figures/curves.png CHANGED

Git LFS Details

  • SHA256: 938b476d37ff940dadec86da45b7e065a516307130787354ebe39d5ae3aa91eb
  • Pointer size: 131 Bytes
  • Size of remote file: 113 kB
research/docs/runbook.md CHANGED
@@ -15,6 +15,8 @@ Run `uv run thirdloss study` to execute both stages, select strengths on develop
15
 
16
  Use `uv run thirdloss report` to regenerate the README results, PDF, figures, experiment notes, progress and explorer from `results/`. Use `uv run thirdloss progress` for current status. `uv run thirdloss evaluate RUN_ID` verifies the registered weight digest and test split before scoring a frozen run. Both tokenizers are stored alongside their stage data. Full untruncated generated token IDs, prompts, reference continuations and outputs are in each run's `samples.jsonl`. Timestamped session logs are stored locally under `logs/`.
17
 
 
 
18
  ## Load a published checkpoint
19
 
20
  All models are indexed in the [Hugging Face collection](https://huggingface.co/collections/BurnyCoder/third-derivatives-in-language-model-training-6b067fb7d5ae3eca49ebb378). The run name identifies its objective, phase, seed and penalty strength. Replace the example run name with the desired published checkpoint. Run from a clone with the locked environment.
 
15
 
16
  Use `uv run thirdloss report` to regenerate the README results, PDF, figures, experiment notes, progress and explorer from `results/`. Use `uv run thirdloss progress` for current status. `uv run thirdloss evaluate RUN_ID` verifies the registered weight digest and test split before scoring a frozen run. Both tokenizers are stored alongside their stage data. Full untruncated generated token IDs, prompts, reference continuations and outputs are in each run's `samples.jsonl`. Timestamped session logs are stored locally under `logs/`.
17
 
18
+ After preparing abstracts, `uv run thirdloss verify --pretrained --device cuda` also compares both implementations of the penalty and its entire training gradient on the same pair of training windows, adapter initialization and sign probes. The diagnostic materializes the original joint graph for comparison. Its GPU allocation exceeded 10 GiB during the original replay. The ordinary adapter training path processes the two windows sequentially. `--device cpu` runs the optional comparison in host memory. [Adapter verification](../reports/reviews/adapter-verification.md)
19
+
20
  ## Load a published checkpoint
21
 
22
  All models are indexed in the [Hugging Face collection](https://huggingface.co/collections/BurnyCoder/third-derivatives-in-language-model-training-6b067fb7d5ae3eca49ebb378). The run name identifies its objective, phase, seed and penalty strength. Replace the example run name with the desired published checkpoint. Run from a clone with the locked environment.
research/docs/study.json CHANGED
The diff for this file is too large to render. See raw diff
 
research/reports/experiments/abstracts-pilot-s00-third-r03/experiment.md CHANGED
@@ -4,9 +4,9 @@ Run `abstracts-pilot-s00-third-r03` · [raw records](../../../results/abstracts-
4
 
5
  | Stage | Method | Phase | Seed | Ratio | Train tokens | Dev NLL | Test NLL | Tokens/s | Status |
6
  | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
7
- | Research abstracts | Third derivative | pilot | 0 | 0.030 | — | — | — | — | failed |
8
 
9
- Training time is — seconds. Peak allocated GPU memory is — MiB. Development token accuracy is —. Test token accuracy is —.
10
 
11
  [Design and hyperparameter rationale](../../planned-runs.md) · [Saved configuration](../../../results/abstracts-pilot-s00-third-r03/config.json)
12
 
 
4
 
5
  | Stage | Method | Phase | Seed | Ratio | Train tokens | Dev NLL | Test NLL | Tokens/s | Status |
6
  | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
7
+ | Research abstracts | Third derivative | pilot | 0 | 0.030 | 65,536 | 3.0909 | — | — | scoring development |
8
 
9
+ Training time is 72.3 seconds. Peak allocated GPU memory is — MiB. Development token accuracy is 0.4143. Test token accuracy is —.
10
 
11
  [Design and hyperparameter rationale](../../planned-runs.md) · [Saved configuration](../../../results/abstracts-pilot-s00-third-r03/config.json)
12
 
research/reports/experiments/abstracts-pilot-s00-third-r03/learnings.md CHANGED
@@ -1,5 +1,5 @@
1
  # Run learnings
2
 
3
- The run recorded a failure. The run ledger contains the error and last metrics. The run ledger records 1 interrupted attempt(s).
4
 
5
  [Experiment and source records](experiment.md)
 
1
  # Run learnings
2
 
3
+ Development NLL changed by -0.1143 nats per target token from 4,096 to 65,536 training targets. Attribution to the regularizer uses matched comparisons across seeds. The run ledger records 1 interrupted attempt(s).
4
 
5
  [Experiment and source records](experiment.md)
research/reports/experiments/experiments.md CHANGED
@@ -6,7 +6,7 @@ NLL is negative log-likelihood in nats per target token. A smaller value assigns
6
 
7
  | Run | Stage | Method | Phase | Seed | Ratio | Train tokens | Dev NLL | Test NLL | Tokens/s | Status |
8
  | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
9
- | [abstracts-pilot-s00-third-r03](./abstracts-pilot-s00-third-r03/experiment.md) | Research abstracts | Third derivative | pilot | 0 | 0.030 | — | — | — | — | failed |
10
  | [stories-control-s00-initial-r00](./stories-control-s00-initial-r00/experiment.md) | TinyStories | Initial checkpoint | control | 0 | 0.000 | 0 | 8.3437 | — | 0 | complete |
11
  | [stories-control-s00-unigram-r00](./stories-control-s00-unigram-r00/experiment.md) | TinyStories | Unigram | control | 0 | 0.000 | 0 | 6.0036 | — | 0 | complete |
12
  | [stories-pilot-s00-ce-r00](./stories-pilot-s00-ce-r00/experiment.md) | TinyStories | Ordinary AdamW | pilot | 0 | 0.000 | 2,097,152 | 3.8770 | — | 123,871 | complete |
 
6
 
7
  | Run | Stage | Method | Phase | Seed | Ratio | Train tokens | Dev NLL | Test NLL | Tokens/s | Status |
8
  | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
9
+ | [abstracts-pilot-s00-third-r03](./abstracts-pilot-s00-third-r03/experiment.md) | Research abstracts | Third derivative | pilot | 0 | 0.030 | 65,536 | 3.0909 | — | — | scoring development |
10
  | [stories-control-s00-initial-r00](./stories-control-s00-initial-r00/experiment.md) | TinyStories | Initial checkpoint | control | 0 | 0.000 | 0 | 8.3437 | — | 0 | complete |
11
  | [stories-control-s00-unigram-r00](./stories-control-s00-unigram-r00/experiment.md) | TinyStories | Unigram | control | 0 | 0.000 | 0 | 6.0036 | — | 0 | complete |
12
  | [stories-pilot-s00-ce-r00](./stories-pilot-s00-ce-r00/experiment.md) | TinyStories | Ordinary AdamW | pilot | 0 | 0.000 | 2,097,152 | 3.8770 | — | 123,871 | complete |
research/reports/experiments/learnings.md CHANGED
@@ -6,7 +6,7 @@
6
 
7
  Independent random signs include mixed weight derivatives in the expected penalty. The trace implementation motivating the gradient check converted its estimate to a Python number. [Derivation and references](../literature-review.md)
8
 
9
- - [abstracts-pilot-s00-third-r03](./abstracts-pilot-s00-third-r03/experiment.md) — The run recorded a failure. The run ledger contains the error and last metrics. The run ledger records 1 interrupted attempt(s).
10
 
11
  - [stories-control-s00-initial-r00](./stories-control-s00-initial-r00/experiment.md) — The observed development NLL is 8.3437 nats per target token.
12
 
 
6
 
7
  Independent random signs include mixed weight derivatives in the expected penalty. The trace implementation motivating the gradient check converted its estimate to a Python number. [Derivation and references](../literature-review.md)
8
 
9
+ - [abstracts-pilot-s00-third-r03](./abstracts-pilot-s00-third-r03/experiment.md) — Development NLL changed by -0.1143 nats per target token from 4,096 to 65,536 training targets. Attribution to the regularizer uses matched comparisons across seeds. The run ledger records 1 interrupted attempt(s).
10
 
11
  - [stories-control-s00-initial-r00](./stories-control-s00-initial-r00/experiment.md) — The observed development NLL is 8.3437 nats per target token.
12
 
research/reports/paper.pdf CHANGED
Binary files a/research/reports/paper.pdf and b/research/reports/paper.pdf differ
 
research/reports/progress.md CHANGED
@@ -1,6 +1,6 @@
1
  # Study progress
2
 
3
- Updated 2026-11-25T07:08:06+00:00.
4
 
5
  12 training/control records and 0 final evaluations are complete. This is 10.0% of 120 planned model milestones.
6
 
@@ -12,7 +12,7 @@ Pilot rates project 1.69 remaining confirmation GPU-hours, excluding validation,
12
 
13
  Statistical status: pending. Awaiting confirmatory runs.
14
 
15
- **abstracts** has 0 completed runs. Current records: abstracts-pilot-s00-third-r03 (failed, 0 targets).
16
 
17
  Statistical status: pending. Awaiting confirmatory runs.
18
 
 
1
  # Study progress
2
 
3
+ Updated 2026-11-25T07:22:10+00:00.
4
 
5
  12 training/control records and 0 final evaluations are complete. This is 10.0% of 120 planned model milestones.
6
 
 
12
 
13
  Statistical status: pending. Awaiting confirmatory runs.
14
 
15
+ **abstracts** has 0 completed runs. Current records: abstracts-pilot-s00-third-r03 (scoring development, 65,536 targets).
16
 
17
  Statistical status: pending. Awaiting confirmatory runs.
18
 
research/results/abstracts-pilot-s00-third-r03/attempts.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "failures": [
3
+ {
4
+ "timestamp": "2026-11-25T07:00:21+00:00",
5
+ "error": "FloatingPointError('Nonfinite or zero third calibration norm at draw 0: inf')"
6
+ }
7
+ ]
8
+ }
research/results/abstracts-pilot-s00-third-r03/config.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": "abstracts-pilot-s00-third-r03",
3
+ "stage": "abstracts",
4
+ "method": "third",
5
+ "phase": "pilot",
6
+ "seed": 0,
7
+ "ratio": 0.03,
8
+ "token_budget": 65536,
9
+ "batch_windows": 8,
10
+ "context": 128,
11
+ "data_manifest_sha256": "0638bd23a7d1dc3ecb9138074ecd922211df2637f60736ddfab7e9aec0b3ccb9",
12
+ "microbatch": 2,
13
+ "coefficients": {
14
+ "third": 8.794990192182448e-22
15
+ }
16
+ }
research/results/abstracts-pilot-s00-third-r03/events.jsonl ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {"timestamp": "2026-11-25T07:10:36+00:00", "step": 1, "tokens": 1024, "train_seconds": 0.7549512999976287, "loss": 3.3628768920898438, "accuracy": 0.38671875, "lr": 3.3333333333333335e-05, "gradient_norm": 1.1452151536941528, "derivatives": {}}
2
+ {"timestamp": "2026-11-25T07:10:43+00:00", "step": 2, "tokens": 2048, "train_seconds": 7.784967199997482, "loss": 3.4265871047973633, "accuracy": 0.3720703125, "lr": 6.666666666666667e-05, "gradient_norm": 1.1557306051254272, "derivatives": {"third": {"estimate": 63550970134528.0, "raw_grad_norm": 1.0867890687798411e+19, "lambda": 8.794990192182448e-22}}, "penalty": 4.4714412722948273e-07}
3
+ {"timestamp": "2026-11-25T07:10:46+00:00", "step": 4, "tokens": 4096, "train_seconds": 8.992709899997863, "loss": 3.3350443840026855, "accuracy": 0.3671875, "lr": 9.994033404481737e-05, "gradient_norm": 1.148818850517273, "derivatives": {}, "dev_nll": 3.2052710236166604, "dev_accuracy": 0.40283203125}
4
+ {"timestamp": "2026-11-25T07:10:51+00:00", "step": 8, "tokens": 8192, "train_seconds": 11.37447599999723, "loss": 3.153599977493286, "accuracy": 0.412109375, "lr": 9.851624761560943e-05, "gradient_norm": 1.330934762954712, "derivatives": {}, "dev_nll": 3.1850391061161645, "dev_accuracy": 0.4056396484375}
5
+ {"timestamp": "2026-11-25T07:10:59+00:00", "step": 11, "tokens": 11264, "train_seconds": 19.229515199996968, "loss": 3.2227602005004883, "accuracy": 0.4150390625, "lr": 9.623426070191522e-05, "gradient_norm": 20.010913848876953, "derivatives": {"third": {"estimate": 1530587563163648.0, "raw_grad_norm": 2.8263922879758997e+21, "lambda": 8.794990192182448e-22}}, "penalty": 1.0769202085040574e-05}
6
+ {"timestamp": "2026-11-25T07:11:01+00:00", "step": 12, "tokens": 12288, "train_seconds": 19.830211699998472, "loss": 3.2258496284484863, "accuracy": 0.421875, "lr": 9.525191870029581e-05, "gradient_norm": 1.1856259107589722, "derivatives": {}, "dev_nll": 3.1686210415209644, "dev_accuracy": 0.4073486328125}
7
+ {"timestamp": "2026-11-25T07:11:05+00:00", "step": 16, "tokens": 16384, "train_seconds": 22.11336940000183, "loss": 3.1759636402130127, "accuracy": 0.404296875, "lr": 9.028539129595197e-05, "gradient_norm": 1.2954821586608887, "derivatives": {}, "dev_nll": 3.1556127692456357, "dev_accuracy": 0.4083251953125}
8
+ {"timestamp": "2026-11-25T07:11:10+00:00", "step": 20, "tokens": 20480, "train_seconds": 24.520824300005188, "loss": 3.365950584411621, "accuracy": 0.3798828125, "lr": 8.38266930414179e-05, "gradient_norm": 1.2729922533035278, "derivatives": {}, "dev_nll": 3.143591393774841, "dev_accuracy": 0.4073486328125}
9
+ {"timestamp": "2026-11-25T07:11:17+00:00", "step": 22, "tokens": 22528, "train_seconds": 32.07198700000663, "loss": 3.1026458740234375, "accuracy": 0.400390625, "lr": 8.01209674912089e-05, "gradient_norm": 9.28732681274414, "derivatives": {"third": {"estimate": 1165224627404800.0, "raw_grad_norm": 1.3197244810220038e+21, "lambda": 8.794990192182448e-22}}, "penalty": 8.19851133577173e-06}
10
+ {"timestamp": "2026-11-25T07:11:20+00:00", "step": 24, "tokens": 24576, "train_seconds": 33.262805500005925, "loss": 3.1675891876220703, "accuracy": 0.4130859375, "lr": 7.614895343622941e-05, "gradient_norm": 1.4086129665374756, "derivatives": {}, "dev_nll": 3.1338581111631356, "dev_accuracy": 0.4075927734375}
11
+ {"timestamp": "2026-11-25T07:11:27+00:00", "step": 25, "tokens": 25600, "train_seconds": 40.032943500005786, "loss": 3.1646835803985596, "accuracy": 0.400390625, "lr": 7.407614758194375e-05, "gradient_norm": 1.3745598793029785, "derivatives": {"third": {"estimate": 143147149557760.0, "raw_grad_norm": 8.819714745499946e+19, "lambda": 8.794990192182448e-22}}, "penalty": 1.0071822211194986e-06}
12
+ {"timestamp": "2026-11-25T07:11:31+00:00", "step": 28, "tokens": 28672, "train_seconds": 41.769987900010165, "loss": 3.24495267868042, "accuracy": 0.3994140625, "lr": 6.757685356832243e-05, "gradient_norm": 1.2910264730453491, "derivatives": {}, "dev_nll": 3.1247553065186366, "dev_accuracy": 0.407958984375}
13
+ {"timestamp": "2026-11-25T07:11:36+00:00", "step": 32, "tokens": 32768, "train_seconds": 44.11454810001305, "loss": 3.475984573364258, "accuracy": 0.376953125, "lr": 5.84728957956991e-05, "gradient_norm": 1.348798394203186, "derivatives": {}, "dev_nll": 3.116393227071967, "dev_accuracy": 0.40966796875}
14
+ {"timestamp": "2026-11-25T07:11:40+00:00", "step": 36, "tokens": 36864, "train_seconds": 46.52359150001212, "loss": 3.1366770267486572, "accuracy": 0.3994140625, "lr": 4.9222074018405206e-05, "gradient_norm": 1.3073307275772095, "derivatives": {}, "dev_nll": 3.109527630964294, "dev_accuracy": 0.4110107421875}
15
+ {"timestamp": "2026-11-25T07:11:45+00:00", "step": 40, "tokens": 40960, "train_seconds": 49.058105700012675, "loss": 3.069873094558716, "accuracy": 0.421875, "lr": 4.021559281401244e-05, "gradient_norm": 1.2526063919067383, "derivatives": {}, "dev_nll": 3.1042128810076974, "dev_accuracy": 0.412109375}
16
+ {"timestamp": "2026-11-25T07:11:49+00:00", "step": 44, "tokens": 45056, "train_seconds": 51.578499600014766, "loss": 3.3931686878204346, "accuracy": 0.3740234375, "lr": 3.183432393205763e-05, "gradient_norm": 1.2775940895080566, "derivatives": {}, "dev_nll": 3.100137497414835, "dev_accuracy": 0.41259765625}
17
+ {"timestamp": "2026-11-25T07:11:54+00:00", "step": 48, "tokens": 49152, "train_seconds": 54.11914360001538, "loss": 3.235374927520752, "accuracy": 0.37890625, "lr": 2.443269974962181e-05, "gradient_norm": 1.304945468902588, "derivatives": {}, "dev_nll": 3.097055894031655, "dev_accuracy": 0.4124755859375}
18
+ {"timestamp": "2026-11-25T07:12:02+00:00", "step": 50, "tokens": 51200, "train_seconds": 61.74632690001454, "loss": 3.0874135494232178, "accuracy": 0.4052734375, "lr": 2.1199063110826618e-05, "gradient_norm": 1.267307996749878, "derivatives": {"third": {"estimate": 36042237280256.0, "raw_grad_norm": 1.8375159269671567e+19, "lambda": 8.794990192182448e-22}}, "penalty": 2.535928987073313e-07}
19
+ {"timestamp": "2026-11-25T07:12:05+00:00", "step": 52, "tokens": 53248, "train_seconds": 63.20483800001239, "loss": 3.068760871887207, "accuracy": 0.408203125, "lr": 1.8323724811743496e-05, "gradient_norm": 1.184583306312561, "derivatives": {}, "dev_nll": 3.0948601723648608, "dev_accuracy": 0.412841796875}
20
+ {"timestamp": "2026-11-25T07:12:10+00:00", "step": 56, "tokens": 57344, "train_seconds": 66.32172880001235, "loss": 3.2506747245788574, "accuracy": 0.40234375, "lr": 1.3765739298084793e-05, "gradient_norm": 1.1677639484405518, "derivatives": {}, "dev_nll": 3.0932112977607176, "dev_accuracy": 0.4134521484375}
21
+ {"timestamp": "2026-11-25T07:12:16+00:00", "step": 60, "tokens": 61440, "train_seconds": 69.4508472000125, "loss": 3.1683192253112793, "accuracy": 0.4091796875, "lr": 1.09514941707089e-05, "gradient_norm": 1.2090530395507812, "derivatives": {}, "dev_nll": 3.091967608779669, "dev_accuracy": 0.414306640625}
22
+ {"timestamp": "2026-11-25T07:12:21+00:00", "step": 64, "tokens": 65536, "train_seconds": 72.27489250001236, "loss": 3.1733510494232178, "accuracy": 0.400390625, "lr": 1e-05, "gradient_norm": 1.1200544834136963, "derivatives": {}, "dev_nll": 3.09093911992386, "dev_accuracy": 0.414306640625}
research/results/calibration/abstracts-third.json ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "stage": "abstracts",
3
+ "kind": "third",
4
+ "data_manifest_sha256": "0638bd23a7d1dc3ecb9138074ecd922211df2637f60736ddfab7e9aec0b3ccb9",
5
+ "unit_lambda": 2.931663397394149e-20,
6
+ "draws": [
7
+ {
8
+ "draw": 0,
9
+ "ce_grad_norm": 1.1272474527359009,
10
+ "penalty_grad_norm": 1.744107653806619e+20,
11
+ "value": 265727747555328.0,
12
+ "norm_ratio": 6.4631758841010535e-21,
13
+ "probe_seconds": 6.6500113000001875,
14
+ "peak_allocated_mib": 6354.271484375
15
+ },
16
+ {
17
+ "draw": 1,
18
+ "ce_grad_norm": 1.1757105588912964,
19
+ "penalty_grad_norm": 4.98717745431209e+21,
20
+ "value": 3010543904358400.0,
21
+ "norm_ratio": 2.357466863094545e-22,
22
+ "probe_seconds": 6.50068470000042,
23
+ "peak_allocated_mib": 6354.27197265625
24
+ },
25
+ {
26
+ "draw": 2,
27
+ "ce_grad_norm": 1.2021815776824951,
28
+ "penalty_grad_norm": 2.7038835357767434e+18,
29
+ "value": 17962486464512.0,
30
+ "norm_ratio": 4.446129286915256e-19,
31
+ "probe_seconds": 6.208909000000858,
32
+ "peak_allocated_mib": 6354.27197265625
33
+ },
34
+ {
35
+ "draw": 3,
36
+ "ce_grad_norm": 1.0702996253967285,
37
+ "penalty_grad_norm": 1.6400195825337523e+20,
38
+ "value": 296954944815104.0,
39
+ "norm_ratio": 6.526139302209834e-21,
40
+ "probe_seconds": 6.415160799999285,
41
+ "peak_allocated_mib": 6354.27197265625
42
+ },
43
+ {
44
+ "draw": 4,
45
+ "ce_grad_norm": 1.181842565536499,
46
+ "penalty_grad_norm": 5.48905451595078e+18,
47
+ "value": 31501934657536.0,
48
+ "norm_ratio": 2.1530895022123633e-19,
49
+ "probe_seconds": 6.108574300000328,
50
+ "peak_allocated_mib": 6354.27197265625
51
+ },
52
+ {
53
+ "draw": 5,
54
+ "ce_grad_norm": 1.2219445705413818,
55
+ "penalty_grad_norm": 2.274370169494697e+19,
56
+ "value": 27829452406784.0,
57
+ "norm_ratio": 5.37267234213182e-20,
58
+ "probe_seconds": 5.9862028999996255,
59
+ "peak_allocated_mib": 6354.27197265625
60
+ },
61
+ {
62
+ "draw": 6,
63
+ "ce_grad_norm": 1.1192132234573364,
64
+ "penalty_grad_norm": 3.59346047387737e+19,
65
+ "value": 15019091689472.0,
66
+ "norm_ratio": 3.114583370523893e-20,
67
+ "probe_seconds": 6.139835399997537,
68
+ "peak_allocated_mib": 6354.27197265625
69
+ },
70
+ {
71
+ "draw": 7,
72
+ "ce_grad_norm": 1.0118643045425415,
73
+ "penalty_grad_norm": 2.757049388682895e+21,
74
+ "value": 1504090567737344.0,
75
+ "norm_ratio": 3.670098579648339e-22,
76
+ "probe_seconds": 6.22955169999841,
77
+ "peak_allocated_mib": 6354.27197265625
78
+ },
79
+ {
80
+ "draw": 8,
81
+ "ce_grad_norm": 1.225813627243042,
82
+ "penalty_grad_norm": 6.602691569608819e+18,
83
+ "value": 5855106301952.0,
84
+ "norm_ratio": 1.8565362539199544e-19,
85
+ "probe_seconds": 5.914080399998056,
86
+ "peak_allocated_mib": 6354.27197265625
87
+ },
88
+ {
89
+ "draw": 9,
90
+ "ce_grad_norm": 1.167998194694519,
91
+ "penalty_grad_norm": 2.1537623831724413e+19,
92
+ "value": 32228790763520.0,
93
+ "norm_ratio": 5.423059683000338e-20,
94
+ "probe_seconds": 6.2061707000029855,
95
+ "peak_allocated_mib": 6354.27197265625
96
+ },
97
+ {
98
+ "draw": 10,
99
+ "ce_grad_norm": 1.1549506187438965,
100
+ "penalty_grad_norm": 1.2663927538607718e+19,
101
+ "value": 27836349939712.0,
102
+ "norm_ratio": 9.12000337354167e-20,
103
+ "probe_seconds": 6.111348800000997,
104
+ "peak_allocated_mib": 6354.27197265625
105
+ },
106
+ {
107
+ "draw": 11,
108
+ "ce_grad_norm": 1.0679398775100708,
109
+ "penalty_grad_norm": 5.172649748649782e+19,
110
+ "value": 83065531531264.0,
111
+ "norm_ratio": 2.064589580589398e-20,
112
+ "probe_seconds": 6.134617499999877,
113
+ "peak_allocated_mib": 6354.27197265625
114
+ },
115
+ {
116
+ "draw": 12,
117
+ "ce_grad_norm": 1.2423405647277832,
118
+ "penalty_grad_norm": 4.519667255084921e+19,
119
+ "value": 40152789417984.0,
120
+ "norm_ratio": 2.7487434242644055e-20,
121
+ "probe_seconds": 6.022774100001698,
122
+ "peak_allocated_mib": 6354.27197265625
123
+ },
124
+ {
125
+ "draw": 13,
126
+ "ce_grad_norm": 1.177032709121704,
127
+ "penalty_grad_norm": 2.6147074281208077e+20,
128
+ "value": 137183746850816.0,
129
+ "norm_ratio": 4.501584752706495e-21,
130
+ "probe_seconds": 5.9077686999989965,
131
+ "peak_allocated_mib": 6354.27197265625
132
+ },
133
+ {
134
+ "draw": 14,
135
+ "ce_grad_norm": 1.1937261819839478,
136
+ "penalty_grad_norm": 7.480117052732963e+19,
137
+ "value": 202575806726144.0,
138
+ "norm_ratio": 1.595865644305397e-20,
139
+ "probe_seconds": 6.179321399999026,
140
+ "peak_allocated_mib": 6354.27197265625
141
+ },
142
+ {
143
+ "draw": 15,
144
+ "ce_grad_norm": 1.1019200086593628,
145
+ "penalty_grad_norm": 6.702447510817866e+18,
146
+ "value": 7641613991936.0,
147
+ "norm_ratio": 1.6440561554280656e-19,
148
+ "probe_seconds": 6.32930209999904,
149
+ "peak_allocated_mib": 6354.27197265625
150
+ }
151
+ ]
152
+ }
research/results/verification/pythia-initializations.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "timestamp": "2026-11-25T07:10:36+00:00",
3
+ "seed": 0,
4
+ "cpu_adapter_sha256_by_build": [
5
+ "1c45ca4d5b3a6cd1b53eadaa7df8af15e21a040a8a61aa7f0e91d1b6f019320b",
6
+ "1c45ca4d5b3a6cd1b53eadaa7df8af15e21a040a8a61aa7f0e91d1b6f019320b",
7
+ "1c45ca4d5b3a6cd1b53eadaa7df8af15e21a040a8a61aa7f0e91d1b6f019320b"
8
+ ]
9
+ }
research/results/verification/pythia-window-comparison.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "timestamp": "2026-11-25T07:12:23+00:00",
3
+ "model": "EleutherAI/pythia-410m",
4
+ "seed": 0,
5
+ "calibration_draw": 0,
6
+ "probe_generation": "CUDA stream 827, seed 6247, FP32 CPU model derivatives, FP64 reductions",
7
+ "max_logit_abs_diff": 0.0,
8
+ "joint_penalty": 3507310145714932.0,
9
+ "two_window_penalty": 3507310136327515.0,
10
+ "relative_vector_error": 7.224275647290446e-08,
11
+ "cosine": 0.9999999999999951
12
+ }
research/src/thirdloss/cli.py CHANGED
@@ -42,6 +42,9 @@ def parser():
42
  sub.add_argument("--stage",choices=HORIZONS,required=True)
43
  if action in {"train","study","evaluate"}:
44
  sub.add_argument("--device",default="cuda")
 
 
 
45
  if action=="train":
46
  sub.add_argument("--method",choices=(*METHODS,"unigram","initial"),required=True)
47
  sub.add_argument("--phase",choices=("pilot","control","confirm","smoke"),default="pilot")
@@ -65,7 +68,12 @@ def main(argv=None):
65
  storage = storage_root(project)
66
  if args.action=="verify":
67
  from .verification import verify
68
- return verify(project)
 
 
 
 
 
69
  if args.action=="dashboard":
70
  return dashboard(project,args.port)
71
  if args.action in {"report","progress","publish"}:
 
42
  sub.add_argument("--stage",choices=HORIZONS,required=True)
43
  if action in {"train","study","evaluate"}:
44
  sub.add_argument("--device",default="cuda")
45
+ if action=="verify":
46
+ sub.add_argument("--pretrained",action="store_true",help="Also compare a full joint derivative on the prepared adapter training corpus")
47
+ sub.add_argument("--device",default="cuda",help="Device for the optional full pretrained cross-check")
48
  if action=="train":
49
  sub.add_argument("--method",choices=(*METHODS,"unigram","initial"),required=True)
50
  sub.add_argument("--phase",choices=("pilot","control","confirm","smoke"),default="pilot")
 
68
  storage = storage_root(project)
69
  if args.action=="verify":
70
  from .verification import verify
71
+ verify(project)
72
+ if args.pretrained:
73
+ from .probe_check import verify_pretrained
74
+ from .records import setup_device
75
+ verify_pretrained(project,setup_device(args.device))
76
+ return
77
  if args.action=="dashboard":
78
  return dashboard(project,args.port)
79
  if args.action in {"report","progress","publish"}:
research/src/thirdloss/evaluation.py CHANGED
@@ -1,6 +1,7 @@
1
  """Token-weighted NLL, exact token accuracy, and uncurated paired development continuations."""
2
 
3
  import math
 
4
  import numpy as np
5
  import torch
6
  from tokenizers import Tokenizer
@@ -10,7 +11,7 @@ from .records import CONTEXT
10
 
11
 
12
  @torch.no_grad()
13
- def score(model, path, device, batch_size, limit_windows=None, unigram=None):
14
  """Score each packed target once, including a final short window, with a fixed context grid."""
15
  tokens = np.memmap(path, mode="r", dtype="<u2")
16
  n = len(tokens) - 1
@@ -22,6 +23,11 @@ def score(model, path, device, batch_size, limit_windows=None, unigram=None):
22
  indices = np.linspace(0, full-1, limit_windows, dtype=np.int64)
23
  tail = 0
24
  total_loss, correct, count = 0.0, 0, 0
 
 
 
 
 
25
  if model is not None:
26
  model.eval()
27
 
@@ -38,10 +44,15 @@ def score(model, path, device, batch_size, limit_windows=None, unigram=None):
38
  offsets = indices[start:start+batch_size, None] * CONTEXT + np.arange(CONTEXT+1)
39
  loss, hits = batch_score(tokens[offsets])
40
  total_loss, correct, count = total_loss+loss, correct+hits, count+offsets.shape[0]*CONTEXT
 
 
 
41
  if tail:
42
  loss, hits = batch_score(np.asarray(tokens[full*CONTEXT:])[None, :])
43
  total_loss, correct, count = total_loss+loss, correct+hits, count+tail
44
  nll = total_loss/count
 
 
45
  return {"nll": nll, "accuracy": correct/count, "tokens": count, "perplexity": math.exp(nll)}
46
 
47
 
 
1
  """Token-weighted NLL, exact token accuracy, and uncurated paired development continuations."""
2
 
3
  import math
4
+ import time
5
  import numpy as np
6
  import torch
7
  from tokenizers import Tokenizer
 
11
 
12
 
13
  @torch.no_grad()
14
+ def score(model, path, device, batch_size, limit_windows=None, unigram=None, progress=None):
15
  """Score each packed target once, including a final short window, with a fixed context grid."""
16
  tokens = np.memmap(path, mode="r", dtype="<u2")
17
  n = len(tokens) - 1
 
23
  indices = np.linspace(0, full-1, limit_windows, dtype=np.int64)
24
  tail = 0
25
  total_loss, correct, count = 0.0, 0, 0
26
+ started = last_log = time.perf_counter()
27
+ def report():
28
+ progress({"targets_scored":count,"targets_to_score":len(indices)*CONTEXT+tail,
29
+ "nll_so_far":total_loss/count,"accuracy_so_far":correct/count,
30
+ "score_seconds":time.perf_counter()-started})
31
  if model is not None:
32
  model.eval()
33
 
 
44
  offsets = indices[start:start+batch_size, None] * CONTEXT + np.arange(CONTEXT+1)
45
  loss, hits = batch_score(tokens[offsets])
46
  total_loss, correct, count = total_loss+loss, correct+hits, count+offsets.shape[0]*CONTEXT
47
+ if progress and time.perf_counter()-last_log>=60:
48
+ report()
49
+ last_log = time.perf_counter()
50
  if tail:
51
  loss, hits = batch_score(np.asarray(tokens[full*CONTEXT:])[None, :])
52
  total_loss, correct, count = total_loss+loss, correct+hits, count+tail
53
  nll = total_loss/count
54
+ if progress:
55
+ report()
56
  return {"nll": nll, "accuracy": correct/count, "tokens": count, "perplexity": math.exp(nll)}
57
 
58
 
research/src/thirdloss/models.py CHANGED
@@ -6,6 +6,7 @@ and PEFT LoRA (https://arxiv.org/abs/2106.09685).
6
  """
7
 
8
  from dataclasses import asdict, dataclass
 
9
  from pathlib import Path
10
 
11
  import torch
@@ -133,6 +134,16 @@ def logits_of(model, ids):
133
  return out if isinstance(out, torch.Tensor) else out.logits
134
 
135
 
 
 
 
 
 
 
 
 
 
 
136
  def token_nll(logits, targets):
137
  """Elementwise stable next-token NLL, exposing all derivative orders in the log partition."""
138
  observed = logits.gather(-1, targets.unsqueeze(-1)).squeeze(-1)
 
6
  """
7
 
8
  from dataclasses import asdict, dataclass
9
+ import hashlib
10
  from pathlib import Path
11
 
12
  import torch
 
134
  return out if isinstance(out, torch.Tensor) else out.logits
135
 
136
 
137
+ def trainable_digest(model):
138
+ """Fingerprint each named trainable tensor at initialization to audit seed pairing."""
139
+ digest = hashlib.sha256()
140
+ for name,p in model.named_parameters():
141
+ if p.requires_grad:
142
+ digest.update(name.encode("utf-8"))
143
+ digest.update(p.detach().contiguous().cpu().view(torch.uint8).numpy().tobytes())
144
+ return digest.hexdigest()
145
+
146
+
147
  def token_nll(logits, targets):
148
  """Elementwise stable next-token NLL, exposing all derivative orders in the log partition."""
149
  observed = logits.gather(-1, targets.unsqueeze(-1)).squeeze(-1)
research/src/thirdloss/probe_check.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Compare both fourth-order implementations on identical pretrained weights and probes."""
2
+
3
+ import hashlib
4
+ import time
5
+
6
+ import torch
7
+
8
+ from .models import build_model, logits_of, token_loss, trainable_digest
9
+ from .objectives import two_window_third_gradient
10
+ from .penalties import estimate, partials, random_signs
11
+ from .records import BATCHES, storage_root, time_now, write_json
12
+ from .windows import TrainingWindows, generator, probe_rows
13
+
14
+
15
+ def verify_pretrained(project,device):
16
+ """Use training calibration draw zero. The full joint GPU graph can exceed 10 GiB."""
17
+ storage = storage_root(project)
18
+ model = build_model("abstracts",0,device,storage).eval()
19
+ parameters = tuple(p for p in model.parameters() if p.requires_grad)
20
+ seed,step = 6247,0
21
+ x,y = TrainingWindows(storage/"data"/"abstracts"/"train.bin",seed,BATCHES["abstracts"]).get(step,device)
22
+ rows = probe_rows(seed,step,len(x))
23
+ x,y = x[rows],y[rows]
24
+ rng = generator(device,seed,step,827)
25
+ u,v = random_signs(parameters,rng),random_signs(parameters,rng)
26
+ def digest(tensors):
27
+ h = hashlib.sha256()
28
+ for tensor in tensors:
29
+ h.update(tensor.detach().contiguous().cpu().numpy().tobytes())
30
+ return h.hexdigest()
31
+ result = {"timestamp":time_now(),"device":str(device),"seed":0,"calibration_seed":seed,"draw":step,
32
+ "initial_trainable_sha256":trainable_digest(model),"input_sha256":digest((x,y)),
33
+ "probes_sha256":digest((*u,*v))}
34
+ with torch.no_grad():
35
+ single = torch.cat([logits_of(model,t[None,:]) for t in x])
36
+ result["max_logit_abs_difference"] = (logits_of(model,x)-single).abs().max().item()
37
+ del single
38
+ def calculate(implementation):
39
+ if device.type=="cuda":
40
+ torch.cuda.empty_cache()
41
+ torch.cuda.reset_peak_memory_stats(device)
42
+ start = time.perf_counter()
43
+ if implementation=="joint":
44
+ loss = token_loss(logits_of(model,x),y)
45
+ value = estimate(loss,parameters,"third",u=u,v=v)
46
+ gradient = partials(value,parameters,create_graph=False)
47
+ else:
48
+ value,gradient = two_window_third_gradient(model,parameters,x,y,u,v)
49
+ flat = torch.cat([g.detach().reshape(-1).cpu().double() for g in gradient])
50
+ result[implementation] = {"penalty":value.item(),"gradient_norm":flat.norm().item(),
51
+ "seconds":time.perf_counter()-start,"finite":bool(flat.isfinite().all()),
52
+ "peak_allocated_mib":torch.cuda.max_memory_allocated(device)/2**20 if device.type=="cuda" else None}
53
+ return flat
54
+ joint = calculate("joint")
55
+ split = calculate("sequential")
56
+ result["relative_gradient_difference"] = ((joint-split).norm()/joint.norm()).item()
57
+ result["gradient_cosine"] = torch.nn.functional.cosine_similarity(joint,split,dim=0).item()
58
+ result["relative_penalty_difference"] = abs(result["joint"]["penalty"]-result["sequential"]["penalty"])/result["joint"]["penalty"]
59
+ write_json(project/"results"/"verification"/f"pythia-joint-{device.type}.json",result)
60
+ print(result,flush=True)
61
+ return result
research/src/thirdloss/report_records.py CHANGED
@@ -37,7 +37,7 @@ FIELDS = (
37
  "batch_size", "architecture", "commit", "dataset_revision", "data_hash",
38
  "freeze_id", "test_manifest_sha256", "test_tokens", "data_manifest_sha256",
39
  "token_budget", "batch_windows", "microbatch", "context", "weights_sha256", "dev_tokens",
40
- "git_revision", "gpu", "torch", "matched_dev_nll", "finished_at",
41
  )
42
  EVENT_FIELDS = (
43
  "step", "tokens", "train_seconds", "loss", "accuracy", "penalty", "dev_nll",
@@ -104,7 +104,8 @@ def fmt(value, digits: int = 3) -> str:
104
 
105
  def run_record(folder: Path) -> dict:
106
  """Join configuration, events and final summary with explicit completion state."""
107
- config = read_json(folder / "config.json")
 
108
  summary = read_json(folder / "summary.json")
109
  last_error = read_json(folder / "failure.json")
110
  events = read_lines(folder / "events.jsonl")
@@ -124,14 +125,19 @@ def run_record(folder: Path) -> dict:
124
  if "token_budget" in record:
125
  record["target_tokens"] = record["token_budget"]
126
  record["id"] = folder.name
 
 
127
  failures = read_json(folder / "attempts.json").get("failures", [])
128
  if last_error and last_error not in failures:
129
  failures.append(last_error)
130
  if failures:
131
  record["failures"] = failures
132
- if last_error and not summary:
 
133
  record["status"] = "failed"
134
  record["error"] = str(last_error.get("error", "Recorded failure"))
 
 
135
  else:
136
  record.setdefault("status", "complete" if summary else "in progress" if events else "configured")
137
  record["events"] = []
@@ -177,7 +183,7 @@ def study_snapshot(root: Path = Path(".")) -> dict:
177
  directory = Path(root) / "results"
178
  runs = []
179
  for folder in sorted(directory.glob("*")):
180
- if folder.is_dir() and any((folder / f).is_file() for f in ("config.json", "summary.json", "failure.json")):
181
  runs.append(run_record(folder))
182
  stages = {stage: analyze_stage(runs, stage) for stage in STAGES}
183
  for run in runs:
 
37
  "batch_size", "architecture", "commit", "dataset_revision", "data_hash",
38
  "freeze_id", "test_manifest_sha256", "test_tokens", "data_manifest_sha256",
39
  "token_budget", "batch_windows", "microbatch", "context", "weights_sha256", "dev_tokens",
40
+ "git_revision", "gpu", "torch", "matched_dev_nll", "finished_at", "initial_trainable_sha256",
41
  )
42
  EVENT_FIELDS = (
43
  "step", "tokens", "train_seconds", "loss", "accuracy", "penalty", "dev_nll",
 
104
 
105
  def run_record(folder: Path) -> dict:
106
  """Join configuration, events and final summary with explicit completion state."""
107
+ state = read_json(folder / "state.json")
108
+ config = {**state,**read_json(folder / "config.json")}
109
  summary = read_json(folder / "summary.json")
110
  last_error = read_json(folder / "failure.json")
111
  events = read_lines(folder / "events.jsonl")
 
125
  if "token_budget" in record:
126
  record["target_tokens"] = record["token_budget"]
127
  record["id"] = folder.name
128
+ if "targets_scored" in state and not summary:
129
+ record["evaluation_progress"] = state
130
  failures = read_json(folder / "attempts.json").get("failures", [])
131
  if last_error and last_error not in failures:
132
  failures.append(last_error)
133
  if failures:
134
  record["failures"] = failures
135
+ resumed = bool(last_error and events and events[-1].get("timestamp", "")>last_error.get("timestamp", ""))
136
+ if last_error and not summary and not resumed:
137
  record["status"] = "failed"
138
  record["error"] = str(last_error.get("error", "Recorded failure"))
139
+ elif resumed and not summary:
140
+ record["status"] = "scoring development" if record.get("tokens")==record.get("token_budget") else "training"
141
  else:
142
  record.setdefault("status", "complete" if summary else "in progress" if events else "configured")
143
  record["events"] = []
 
183
  directory = Path(root) / "results"
184
  runs = []
185
  for folder in sorted(directory.glob("*")):
186
+ if folder.is_dir() and any((folder / f).is_file() for f in ("config.json", "summary.json", "failure.json", "state.json")):
187
  runs.append(run_record(folder))
188
  stages = {stage: analyze_stage(runs, stage) for stage in STAGES}
189
  for run in runs:
research/src/thirdloss/study.py CHANGED
@@ -60,6 +60,7 @@ def freeze(project, storage, stage):
60
  split = read_json(storage/"data"/stage/"manifest.json")["splits"]["test"]
61
  frozen = {"stage":stage,"ratios":selection,"test_sha256":split["sha256"],"runs":{}}
62
  for seed in range(1,9):
 
63
  for method in ("ce","trace","third"):
64
  name = run_name(stage,method,"confirm",seed,selection.get(method,0))
65
  summary = read_json(project/"results"/name/"summary.json")
@@ -69,6 +70,12 @@ def freeze(project, storage, stage):
69
  raise ValueError(f"Different corpus for {name}")
70
  weights_file(storage,summary)
71
  frozen["runs"][name] = summary["weights_sha256"]
 
 
 
 
 
 
72
  frozen["freeze_id"] = hashlib.sha256(json.dumps(frozen,sort_keys=True).encode()).hexdigest()
73
  path = project/"results"/"freeze"/f"{stage}.json"
74
  if path.exists() and read_json(path)!=frozen:
 
60
  split = read_json(storage/"data"/stage/"manifest.json")["splits"]["test"]
61
  frozen = {"stage":stage,"ratios":selection,"test_sha256":split["sha256"],"runs":{}}
62
  for seed in range(1,9):
63
+ initial = set()
64
  for method in ("ce","trace","third"):
65
  name = run_name(stage,method,"confirm",seed,selection.get(method,0))
66
  summary = read_json(project/"results"/name/"summary.json")
 
70
  raise ValueError(f"Different corpus for {name}")
71
  weights_file(storage,summary)
72
  frozen["runs"][name] = summary["weights_sha256"]
73
+ if summary.get("initial_trainable_sha256"):
74
+ initial.add(summary["initial_trainable_sha256"])
75
+ if len(initial)>1:
76
+ raise ValueError(f"Initial trainable weights differ across {stage} seed {seed} arms")
77
+ if initial:
78
+ frozen.setdefault("initializations",{})[str(seed)] = initial.pop()
79
  frozen["freeze_id"] = hashlib.sha256(json.dumps(frozen,sort_keys=True).encode()).hexdigest()
80
  path = project/"results"/"freeze"/f"{stage}.json"
81
  if path.exists() and read_json(path)!=frozen:
research/src/thirdloss/train.py CHANGED
@@ -12,7 +12,7 @@ import torch
12
  from filelock import FileLock
13
 
14
  from .evaluation import sample_outputs, score, unigram_distribution
15
- from .models import build_model, export_weights
16
  from .objectives import add_penalty, calibrate, ce_backward
17
  from .records import (BATCHES, CONTEXT, HORIZONS, RATIOS, Recorder, json_lines, read_json,
18
  run_name, sha256, time_now, write_json)
@@ -115,6 +115,7 @@ def run_one(project, storage, stage, method, phase, seed, ratio, device, microba
115
  write_json(log,history)
116
  if marker.exists():
117
  remember(read_json(marker))
 
118
  try:
119
  return _run(project, storage, config, recorder, device, microbatch)
120
  except Exception as exc:
@@ -130,8 +131,11 @@ def _run(project, storage, config, recorder, device, microbatch):
130
  manifest = read_json(data/"manifest.json")
131
  config["data_manifest_sha256"] = sha256(data/"manifest.json")
132
  config["microbatch"] = microbatch
133
- config["coefficients"] = chosen_coefficients(project,storage,config,device,microbatch)
134
  output = recorder.directory
 
 
 
 
135
  if (output/"config.json").exists() and read_json(output/"config.json") != config:
136
  raise ValueError(f"Existing run configuration conflicts with {config['id']}")
137
  write_json(output/"config.json",config)
@@ -147,12 +151,14 @@ def _run(project, storage, config, recorder, device, microbatch):
147
  parameters = tuple(p for p in model.parameters() if p.requires_grad) if model is not None else ()
148
  summary = {**config, "device":str(device), "torch":str(torch.__version__), "platform":platform.platform(),
149
  "gpu":torch.cuda.get_device_name(device) if device.type=="cuda" else None,
 
150
  "git_revision":subprocess.check_output(["git","rev-parse","HEAD"],cwd=project,text=True).strip(),
151
  "trainable_parameters":sum(p.numel() for p in parameters)}
152
  batch = BATCHES[stage]
153
  steps = budget//(batch*CONTEXT)
154
  elapsed = 0.0
155
  if budget:
 
156
  windows = TrainingWindows(data/"train.bin",seed,batch)
157
  groups = [{"params":[p for p in parameters if p.ndim>1],"weight_decay":0.1},
158
  {"params":[p for p in parameters if p.ndim<=1],"weight_decay":0.0}]
@@ -190,7 +196,11 @@ def _run(project, storage, config, recorder, device, microbatch):
190
  save_state(ckpt/"latest.pt",model,optimizer,done,elapsed,config)
191
  del optimizer
192
  dist = unigram_distribution(data/"train.bin",4096 if stage=="stories" else 50304) if method=="unigram" else None
193
- validation = score(model,data/"dev.bin",device,microbatch,unigram=dist)
 
 
 
 
194
  # A rerun after final-checkpoint interruption writes each documented sample exactly once.
195
  sample_path = output/"samples.jsonl"
196
  if sample_path.exists():
@@ -207,6 +217,7 @@ def _run(project, storage, config, recorder, device, microbatch):
207
  dev_nll=validation["nll"],dev_accuracy=validation["accuracy"],dev_tokens=validation["tokens"],
208
  finished_at=time_now(),status="complete")
209
  write_json(summary_path,summary)
 
210
  (output/"failure.json").unlink(missing_ok=True)
211
  print(f"Completed {config['id']} development NLL {summary['dev_nll']:.6f}",flush=True)
212
  return summary
 
12
  from filelock import FileLock
13
 
14
  from .evaluation import sample_outputs, score, unigram_distribution
15
+ from .models import build_model, export_weights, trainable_digest
16
  from .objectives import add_penalty, calibrate, ce_backward
17
  from .records import (BATCHES, CONTEXT, HORIZONS, RATIOS, Recorder, json_lines, read_json,
18
  run_name, sha256, time_now, write_json)
 
115
  write_json(log,history)
116
  if marker.exists():
117
  remember(read_json(marker))
118
+ marker.unlink()
119
  try:
120
  return _run(project, storage, config, recorder, device, microbatch)
121
  except Exception as exc:
 
131
  manifest = read_json(data/"manifest.json")
132
  config["data_manifest_sha256"] = sha256(data/"manifest.json")
133
  config["microbatch"] = microbatch
 
134
  output = recorder.directory
135
+ state_path = output/"state.json"
136
+ if not (output/"summary.json").exists():
137
+ write_json(state_path,{**config,"status":"initializing","timestamp":time_now()})
138
+ config["coefficients"] = chosen_coefficients(project,storage,config,device,microbatch)
139
  if (output/"config.json").exists() and read_json(output/"config.json") != config:
140
  raise ValueError(f"Existing run configuration conflicts with {config['id']}")
141
  write_json(output/"config.json",config)
 
151
  parameters = tuple(p for p in model.parameters() if p.requires_grad) if model is not None else ()
152
  summary = {**config, "device":str(device), "torch":str(torch.__version__), "platform":platform.platform(),
153
  "gpu":torch.cuda.get_device_name(device) if device.type=="cuda" else None,
154
+ "initial_trainable_sha256":trainable_digest(model) if model is not None else None,
155
  "git_revision":subprocess.check_output(["git","rev-parse","HEAD"],cwd=project,text=True).strip(),
156
  "trainable_parameters":sum(p.numel() for p in parameters)}
157
  batch = BATCHES[stage]
158
  steps = budget//(batch*CONTEXT)
159
  elapsed = 0.0
160
  if budget:
161
+ write_json(state_path,{"status":"training","timestamp":time_now()})
162
  windows = TrainingWindows(data/"train.bin",seed,batch)
163
  groups = [{"params":[p for p in parameters if p.ndim>1],"weight_decay":0.1},
164
  {"params":[p for p in parameters if p.ndim<=1],"weight_decay":0.0}]
 
196
  save_state(ckpt/"latest.pt",model,optimizer,done,elapsed,config)
197
  del optimizer
198
  dist = unigram_distribution(data/"train.bin",4096 if stage=="stories" else 50304) if method=="unigram" else None
199
+ write_json(state_path,{"status":"scoring development","timestamp":time_now()})
200
+ def evaluation_progress(row):
201
+ write_json(state_path,{"status":"scoring development",**row})
202
+ recorder.emit({"split":"dev",**row},"evaluation.jsonl")
203
+ validation = score(model,data/"dev.bin",device,microbatch,unigram=dist,progress=evaluation_progress)
204
  # A rerun after final-checkpoint interruption writes each documented sample exactly once.
205
  sample_path = output/"samples.jsonl"
206
  if sample_path.exists():
 
217
  dev_nll=validation["nll"],dev_accuracy=validation["accuracy"],dev_tokens=validation["tokens"],
218
  finished_at=time_now(),status="complete")
219
  write_json(summary_path,summary)
220
+ state_path.unlink(missing_ok=True)
221
  (output/"failure.json").unlink(missing_ok=True)
222
  print(f"Completed {config['id']} development NLL {summary['dev_nll']:.6f}",flush=True)
223
  return summary
research/tests/test_training.py CHANGED
@@ -79,6 +79,7 @@ def test_step_recovery_matches_uninterrupted_weights(tmp_path,monkeypatch):
79
  store2 = tmp_path/"store2"
80
  shutil.copytree(root/"data",store2/"data")
81
  normal = train.run_one(reference,store2,"stories","third","smoke",seed,0.03,torch.device("cpu"))
 
82
  rel = f"checkpoints/{normal['id']}/export/model.safetensors"
83
  first, second = load_file(str(root/rel)),load_file(str(store2/rel))
84
  for name in first:
 
79
  store2 = tmp_path/"store2"
80
  shutil.copytree(root/"data",store2/"data")
81
  normal = train.run_one(reference,store2,"stories","third","smoke",seed,0.03,torch.device("cpu"))
82
+ assert normal["initial_trainable_sha256"] == resumed["initial_trainable_sha256"]
83
  rel = f"checkpoints/{normal['id']}/export/model.safetensors"
84
  first, second = load_file(str(root/rel)),load_file(str(store2/rel))
85
  for name in first: