Repository navigation
feat(ml): thread primitive + train_hslm windows on N threads, bit-identical at any count (#10876) - #10896
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nds (#10850) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…now std.os.linux.timespec (#10850) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… threads (#10876) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 19, 2026
This was referenced Oct 19, 2026
This was referenced Oct 19, 2026
Merged
Contributor
7 of 8 tasks
…in_hslm.t27 and its seal kept at the thread version) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Contributor
PR DashboardGenerated at: 2026-10-19 07:57:04 UTC
Summary
Seal Status
|
Contributor
PR DashboardGenerated at: 2026-10-19 08:08:19 UTC
Summary
Seal Status
|
This was referenced Oct 19, 2026
gHashTag
added a commit
that referenced
this pull request
Oct 19, 2026
…d, move the seal (Closes #10957) #10896 dropped Node::with_child, Parser::check_peek, icarus_lowerability_reason, align_address, reset_end_cycle, path_delay and worst_path_delay to keep the foreign-line budget net-negative, but eight test lines still called five of them, so the unit tests no longer compiled. Delete those tests; nothing else changes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
gHashTag
added a commit
that referenced
this pull request
Oct 19, 2026
…identical at 1 and 3 threads (#10875) Master's thread primitive (#10896) makes window scratch threadlocal; the speed-4 buffers b4_q, b4_s and b4_wt follow. New test checks the step digest at 1 and 3 threads at speed 4, and that it differs from speed 2. Re-sealed on the lab (37 tests, 0 vacuous, all hashes MATCH). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
gHashTag
added a commit
that referenced
this pull request
Oct 19, 2026
…_cores does not get the thread runtime appended (Closes #10957) #10896 appended the thread runtime to any Zig output that calls thread_spawn, thread_join or thread_cores, so compiler/runtime/runtime.t27 (which defines and calls its own thread_spawn) changed its gen_hash_zig and the triruntime and runtime_triruntime seals drifted (coverage red). Guard the detection with declared_fns, as the call rewrite already is. One line changed, none added. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
gHashTag
added a commit
that referenced
this pull request
Oct 19, 2026
…nst speed=2 (Closes #10875) (#10908) * spec(ml): train_hslm speed=4 -- int8 trit forward, one scale per row, error bounded against speed=2 (Closes #10875) speed=4 is speed 3's window with every forward ternary matmul in integers: activations rounded to int8 with one scale per row, trits transposed once per call, sixteen independent i32 accumulators, output = acc * scale. The backward stays speed 3's f64 code. Tests bound the kernel error (proved per-output bound), logits, k-position loss and gradients against speed 2, and re-derive the lab loss-curve gap and tok/s from recorded constants. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * seal(ml): restore master's train_hslm seal so the master merge is conflict-free (#10875) The seal is regenerated on the lab in the next commit, after the merge. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * spec(ml): speed=4 scratch is threadlocal and the speed-4 step is bit-identical at 1 and 3 threads (#10875) Master's thread primitive (#10896) makes window scratch threadlocal; the speed-4 buffers b4_q, b4_s and b4_wt follow. New test checks the step digest at 1 and 3 threads at speed 4, and that it differs from speed 2. Re-sealed on the lab (37 tests, 0 vacuous, all hashes MATCH). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
gHashTag
added a commit
that referenced
this pull request
Oct 19, 2026
…loses #10957) (#10958) * compiler.rs: delete the tests that call the seven items #10896 removed, move the seal (Closes #10957) #10896 dropped Node::with_child, Parser::check_peek, icarus_lowerability_reason, align_address, reset_end_cycle, path_delay and worst_path_delay to keep the foreign-line budget net-negative, but eight test lines still called five of them, so the unit tests no longer compiled. Delete those tests; nothing else changes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * zig emit: a spec that defines its own thread_spawn/thread_join/thread_cores does not get the thread runtime appended (Closes #10957) #10896 appended the thread runtime to any Zig output that calls thread_spawn, thread_join or thread_cores, so compiler/runtime/runtime.t27 (which defines and calls its own thread_spawn) changed its gen_hash_zig and the triruntime and runtime_triruntime seals drifted (coverage red). Guard the detection with declared_fns, as the call rewrite already is. One line changed, none added. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #10876
What
Lever (a) of #10850: the 66 windows of one
tr_train_step_kstep run on N worker threads instead of one.threadlocal varform andthread_spawn/thread_join/thread_coresbuiltins for--backend ml(bootstrap/src/compiler.rs, +40/-47, dead code deleted;FROZEN_HASHmoved).specs/ml/thread_model.t27(6 tests; parts on N threads sum bit-identically to the fixed-order sum, per-thread state starts at its initializer and does not leak).specs/ml/train_hslm.t27: cfg keythreads(default = cores,threads=1is the serial path). Each window writes its own gradient slot inwin_g; slots are summed in window order, so the result does not depend on the thread count. nn/hslm state and theb3_*scratch arrays arethreadlocal. New testone_two_and_three_threads_give_one_step_the_same_bits_at_speed_2_and_3.Association change (stated, not hidden)
The old step kept one running sum over windows. The new step sums per-window slots in fixed window order. Floating-point addition is not associative, so:
240eb9893ad8eba1(old) vsa9f594b18f9fc17e(new). Loss agrees to 4 digits (train 6.5916, valid 6.5637) and the.binhash is the same.The new value is the same for every thread count, which is the point: determinism no longer depends on the machine.
Lab proof (Railway lab, 48 cores, 8 steps, seed 1729, loaded: load average 55-72 during the runs, so these are floors)
State hash after 8 steps,
sha256(ckpt_8.state)[:16]:a9f594b18f9fc17eat threads = 1, 2, 4, 8, 16, 24, 48, at speed 2 and at speed 3. Loss identical at every count.Speed-up at 16 threads: 5.4x at speed 2, 4.1x vs the old speed-3 binary. Past 24 threads the lab is oversubscribed (load > 48) and throughput falls.
Known costs
threads=1at speed=3 is about 16% slower than the old binary (407 vs 484 tok/s): thread-local access on theb3_*scratch. At speed 2 it is level (238-246 vs 245). Not fixed here; a follow-up.undefinedas 0xaa into.data, 1.1 GB forwin_g.win_gnow starts from a zero initializer (.bss),.datais 178 MB.specs/ml/eval_hslm.t27is BLOCKED (use of undeclared identifier 'b3_q'). Inherited from spec(ml): train_hslm speed=3 -- one matrix over the 27 positions, bit-identical to speed=2 (Closes #10849) #10866 (it fails at this PR's base too), not caused here; follow-up.Stack
This branch contains the commits of #10857 (issue #10850) until that merges; the diff of this PR alone is the thread work.
Tests on the lab:
thread_model6/6,train_hslm30/30,t27t17/17,ngram_hslm8/8, all with 0 vacuous passes. Seals saved forml_train_hslmandml_thread_model.🤖 Generated with Claude Code