From 6353a85f16f90013af56734c10d04e5f9a818411 Mon Sep 17 00:00:00 2001 From: Dmitrii Vasilev Date: Mon, 19 Oct 2026 11:14:19 +0700 Subject: [PATCH 1/3] spec(hslm): train_hslm header counts 1948617 trits in 19 ternary matrices, with a test summed from the segment table (Closes #10839) Co-Authored-By: Claude Opus 5.5 --- specs/ml/train_hslm.t27 | 44 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/specs/ml/train_hslm.t27 b/specs/ml/train_hslm.t27 index d400e20080..a23d717e14 100644 --- a/specs/ml/train_hslm.t27 +++ b/specs/ml/train_hslm.t27 @@ -9,7 +9,8 @@ ; quantizer (nn/ternary_ste quantize_twn) and the checkpoint header and layout (nn/hslm_data ; write_header, parse_header, the section offsets). They are reached through `use`. ; THE MODEL: ctx 27, vocab 729, embed 243, ff 729, 3 blocks, 3 heads of 81. Every ternary matrix -; (Q, K, V, O, up, down per block, and the output head: 19 matrices, 1771470 trits) has an f64 +; (Q, K, V, O, up, down per block, and the output head: 19 matrices; 18 block matrices hold 1771470 +; trits and the 243 x 729 output head adds 177147, 1948617 trits in all) has an f64 ; shadow; after every update the shadow is requantized with TWN (delta = 0.7 mean |w|, alpha = mean ; |w| over the kept entries), one alpha per matrix. The float parameters (embedding table 729 x 243, ; RMSNorm gains, FFN biases, output bias) are trained directly. NPARAM = 2130138 f64 in one flat @@ -2137,6 +2138,40 @@ fn tr_param_count() -> usize { return tr_build_segments(); } +/// The trits in the ternary matrices, summed from the segment table (0 when the table does not add up to NPARAM) +fn tr_ternary_count() -> usize { + const total : usize = tr_build_segments(); + var n : usize = 0; + var s : usize = 0; + while (s < NSEG) { + if (tr_kind_ternary(seg_kind[s])) { + n = n + seg_len[s]; + } + s = s + 1; + } + if (total != NPARAM) { + return 0; + } + return n; +} + +/// How many segments are ternary matrices (0 when the table does not add up to NPARAM) +fn tr_ternary_matrices() -> usize { + const total : usize = tr_build_segments(); + var m : usize = 0; + var s : usize = 0; + while (s < NSEG) { + if (tr_kind_ternary(seg_kind[s])) { + m = m + 1; + } + s = s + 1; + } + if (total != NPARAM) { + return 0; + } + return m; +} + ; THE K-POSITION OBJECTIVE, CHECKED. The kinds a gradient check can move: nn/hslm's MAT_* (a ternary ; matrix entry, moved through the nudge as a real weight before the alpha scale, which is the ; quantity gw_* is the gradient of), one embedding table entry, one output bias entry. Central @@ -2524,6 +2559,13 @@ test the_parameter_vector_is_the_whole_model given n = tr_param_count() then n == 2130138 +test the_ternary_matrices_hold_1948617_trits + given m = tr_ternary_matrices() + and n = tr_ternary_count() + then m == 19 + and n == 1948617 + and n == NUM_BLOCKS * (4 * EMBED_DIM * EMBED_DIM + 2 * EMBED_DIM * FF_DIM) + EMBED_DIM * VOCAB_SIZE + test a_checkpoint_round_trip_on_a_buffer_is_byte_equal given diff = tr_mslh_roundtrip_diff() and status = tr_mslh_header_status() From 6cd4882e203fbc8c47cae9ac883724d9b587b5a6 Mon Sep 17 00:00:00 2001 From: Dmitrii Vasilev Date: Mon, 19 Oct 2026 11:17:52 +0700 Subject: [PATCH 2/3] seal(hslm): reseal ml/train_hslm on the lab after the ternary-count test (Refs #10839) Co-Authored-By: Claude Opus 5.5 --- .trinity/seals/ml_train_hslm.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.trinity/seals/ml_train_hslm.json b/.trinity/seals/ml_train_hslm.json index f90217532b..c32d22b906 100644 --- a/.trinity/seals/ml_train_hslm.json +++ b/.trinity/seals/ml_train_hslm.json @@ -19,27 +19,27 @@ } ], "config": "gen=c,rust,verilog,zig;tests=zig", - "gen_hash_c": "sha256:055ae0cc492ffb8d93ec1efb9108717dab776629eac9cf998486dd8e0953303a", - "gen_hash_rust": "sha256:bcfac5e60672f7727a3fb664998569f3d968e383fbbf05bbd13250f1e96ac27f", - "gen_hash_verilog": "sha256:5ee39b8e538963f19568406f921cf018166b44dd9e0cdaf3c5b4b10c0f9ac3c6", - "gen_hash_zig": "sha256:b394cdfcac1611c453707b7eba40039d1daddbf9d17a336b7a28979cb0a076fa", + "gen_hash_c": "sha256:9261d24381b2c2b5506fad987fc13fbfd5e7142a00c5e67fb878e56862102c7f", + "gen_hash_rust": "sha256:9a74375d2aae9aa6a71992aa96ee569812253a4e3ba32c41d29b4600d09829fd", + "gen_hash_verilog": "sha256:b9743c3e95cd4c48765383ea8c8d7a1ffc5551c925e23be9bbae74d7f30e0550", + "gen_hash_zig": "sha256:00a2ae9af248ea9bae037596bf77b759303d460f8eb283cef3b8d6284b879ea5", "module": "train_hslm", "ring": 12, "seal_schema": 2, - "sealed_at": "2026-10-18T13:48:46Z", + "sealed_at": "2026-10-19T04:17:33Z", "sealed_by": "t27c-bootstrap@0.5.2", - "spec_hash": "sha256:fa8490d815bde2815fe9bfa89cb9badab241f580977e59be52fc5902f6f8bb03", + "spec_hash": "sha256:8fd4733d3ff131fc85c947e7e6146666d0f06fdaf3a5e563d7ce2fa70eb61b8d", "spec_path": "specs/ml/train_hslm.t27", "tests": { "failed": 0, "failing": [], "forced": false, - "passed": 20, - "total": 20, + "passed": 21, + "total": 21, "vacuous": 0 }, "toolchain": { - "test_runner": "sha256:1982ae948e24d00c5d221ccec12dfce1eb01204b53e37b0f857f93b16d64629d", + "test_runner": "sha256:8512b80da533b79289110fca4a65f3336abd7a059ca4b72ea595d5e33ff8ad10", "zig": "0.16.0" } } \ No newline at end of file From b0015aa299b5a4957a24a0b2eeb621f7b01fed77 Mon Sep 17 00:00:00 2001 From: Dmitrii Vasilev Date: Mon, 19 Oct 2026 11:29:00 +0700 Subject: [PATCH 3/3] seal(hslm): reseal train_hslm, eval_hslm and ngram_hslm with a t27c built from master 78e57be99 (Refs #10839) Co-Authored-By: Claude Opus 5.5 --- .trinity/seals/ml_eval_hslm.json | 6 +++--- .trinity/seals/ml_ngram_hslm.json | 6 +++--- .trinity/seals/ml_train_hslm.json | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.trinity/seals/ml_eval_hslm.json b/.trinity/seals/ml_eval_hslm.json index 63c0f1320d..f502b57265 100644 --- a/.trinity/seals/ml_eval_hslm.json +++ b/.trinity/seals/ml_eval_hslm.json @@ -1,5 +1,5 @@ { - "built_by": "t27c-bootstrap@0.5.2+fd332dfd5", + "built_by": "t27c-bootstrap@0.5.2+78e57be99", "closure": [ { "spec": "specs/base/types.t27", @@ -7,7 +7,7 @@ }, { "spec": "specs/ml/train_hslm.t27", - "spec_hash": "sha256:fa8490d815bde2815fe9bfa89cb9badab241f580977e59be52fc5902f6f8bb03" + "spec_hash": "sha256:8fd4733d3ff131fc85c947e7e6146666d0f06fdaf3a5e563d7ce2fa70eb61b8d" } ], "config": "gen=c,rust,verilog,zig;tests=zig", @@ -18,7 +18,7 @@ "module": "eval_hslm", "ring": 12, "seal_schema": 2, - "sealed_at": "2026-10-19T03:39:21Z", + "sealed_at": "2026-10-19T04:28:30Z", "sealed_by": "t27c-bootstrap@0.5.2", "spec_hash": "sha256:09c6729a1509a6ec95616fd50fccf4eb6a3d65dfd22c9aec359e6079a52acec1", "spec_path": "specs/ml/eval_hslm.t27", diff --git a/.trinity/seals/ml_ngram_hslm.json b/.trinity/seals/ml_ngram_hslm.json index e5a01aca68..a41935c8dd 100644 --- a/.trinity/seals/ml_ngram_hslm.json +++ b/.trinity/seals/ml_ngram_hslm.json @@ -1,5 +1,5 @@ { - "built_by": "t27c-bootstrap@0.5.2+fd332dfd5", + "built_by": "t27c-bootstrap@0.5.2+78e57be99", "closure": [ { "spec": "specs/base/types.t27", @@ -7,7 +7,7 @@ }, { "spec": "specs/ml/train_hslm.t27", - "spec_hash": "sha256:fa8490d815bde2815fe9bfa89cb9badab241f580977e59be52fc5902f6f8bb03" + "spec_hash": "sha256:8fd4733d3ff131fc85c947e7e6146666d0f06fdaf3a5e563d7ce2fa70eb61b8d" } ], "config": "gen=c,rust,verilog,zig;tests=zig", @@ -18,7 +18,7 @@ "module": "ngram_hslm", "ring": 12, "seal_schema": 2, - "sealed_at": "2026-10-19T03:39:38Z", + "sealed_at": "2026-10-19T04:28:31Z", "sealed_by": "t27c-bootstrap@0.5.2", "spec_hash": "sha256:d3e31459bc0702d1b59357dad2b4d2ef679fbe95fcda2185adb612a2bdb6f6ed", "spec_path": "specs/ml/ngram_hslm.t27", diff --git a/.trinity/seals/ml_train_hslm.json b/.trinity/seals/ml_train_hslm.json index c32d22b906..1f6c0c9c8d 100644 --- a/.trinity/seals/ml_train_hslm.json +++ b/.trinity/seals/ml_train_hslm.json @@ -1,5 +1,5 @@ { - "built_by": "t27c-bootstrap@0.5.2+fd332dfd5", + "built_by": "t27c-bootstrap@0.5.2+78e57be99", "closure": [ { "spec": "specs/base/types.t27", @@ -20,13 +20,13 @@ ], "config": "gen=c,rust,verilog,zig;tests=zig", "gen_hash_c": "sha256:9261d24381b2c2b5506fad987fc13fbfd5e7142a00c5e67fb878e56862102c7f", - "gen_hash_rust": "sha256:9a74375d2aae9aa6a71992aa96ee569812253a4e3ba32c41d29b4600d09829fd", + "gen_hash_rust": "sha256:78d0634dbb7f15a4fb098e71779d47a69149fe776703d6a791632f608e3315f2", "gen_hash_verilog": "sha256:b9743c3e95cd4c48765383ea8c8d7a1ffc5551c925e23be9bbae74d7f30e0550", "gen_hash_zig": "sha256:00a2ae9af248ea9bae037596bf77b759303d460f8eb283cef3b8d6284b879ea5", "module": "train_hslm", "ring": 12, "seal_schema": 2, - "sealed_at": "2026-10-19T04:17:33Z", + "sealed_at": "2026-10-19T04:28:22Z", "sealed_by": "t27c-bootstrap@0.5.2", "spec_hash": "sha256:8fd4733d3ff131fc85c947e7e6146666d0f06fdaf3a5e563d7ce2fa70eb61b8d", "spec_path": "specs/ml/train_hslm.t27",