Repository navigation
spec(port): port specs/port/trios/crates/trios-ternary/src/lib.t27 (Closes #9311) - #9874
Conversation
…loses gHashTag#9311) Port gHashTag/trios:crates/trios-ternary/src/lib.rs (at 8b229e9489ee, 175+ lines) as specs/port/trios/crates/trios-ternary/src/lib.t27 - Roadmap Stage 6, goal gHashTag#4548, target t27c gen-rust. The Ternary BitLinear engine's decisions are ported as pure functions and tested (8 tests, 8 pass, 0 vacuous, 28 runtime asserts, 100% function coverage): the {-1, 0, +1} thresholding (strictly above 0.5 -> +1, strictly below -0.5 -> -1, else 0), the value mapping back, bits_per_param = log2(3) - computed without the log2 builtin by a Newton square-root ladder assembling 2^y for any y, then a bisection on 2^x = 3 converging into the 1.584-1.586 window - the quantize scale-and-threshold decision with its dequantize division, max-abs scaling (1/max_abs, 1.0 for the all-zero tensor, 1.0 for the empty one), the sparsity zero-share, and the ffn module's scale default with the params/5 memory pricing (conservative integer division of the 1.58-bit estimate). The growable weight vectors are the callers' plumbing. Verified: parse OK, spec-status IMPLEMENTED, typecheck 0 errors, coverage 14/14, test-report 8/8 pass, 0 BLOCKED, gen 169 lines with 0 'not yet implemented', boundary exactly this one file, dupe_scan: all 7 introduced names unique across 2040 specs (checked before the commit), bare body scan adds no duplicate group (752/221 unchanged). Dmitrii Fedorov ([@dmitrii-f-t27](https://github.com/dmitrii-f-t27))
gHashTag#9311) dupe_scan found sqrt_newton and pow2_frac already carried by other specs - neither name is mandated by the issue. Renamed to ternary_sqrt_newton and ternary_pow2_frac so every introduced name is unique across the 2040 specs; the earlier commit message's uniqueness claim was checked too late and was wrong for these two names. All oracles re-verified after the rename. Dmitrii Fedorov ([@dmitrii-f-t27](https://github.com/dmitrii-f-t27))
|
@gHashTag Please merge this PR into master via the golden chain — rights on gHashTag/t27 are read-only for me (403), so the merge itself needs your action. What this is: the #9311 port — What is verified:
CI (head 6c3324d): required trio green — The 3 reds are the base-red trio, not this change: After the merge I will: verify the spec file live on the merge SHA, confirm #9311 auto-closed, and file the 14-step report. Dmitrii Fedorov (@dmitrii-f-t27) |
Summary
Port
gHashTag/trios:crates/trios-ternary/src/lib.rs(at8b229e9489ee, 175+ lines) asspecs/port/trios/crates/trios-ternary/src/lib.t27— Roadmap Stage 6 (goal #4548), target t27c gen-rust. Closes #9311.The original is the Ternary BitLinear engine: the {-1, 0, +1} quantization for the bulk compute layers (zero-DSP on the XC7A100T), per the STATIC_ROUTING_TABLE.
Per the issue's rule ("Port the decision, not the plumbing"), all seven listed functions are ported under their names as pure functions (no transports — the growable weight vectors are the callers' plumbing) with 8 tests (28 runtime asserts, 0 vacuous, 100% function coverage):
Ternary_from_f32/Ternary_to_f32— the thresholding decision: strictly above 0.5 → +1, strictly below -0.5 → -1, else 0; and the mapping back (original lines 43-56);Ternary_bits_per_param— log2(3), computed without the log2 builtin: a Newton square-root ladder assembles 2^y for any fractional y, and a bisection on 2^x = 3 converges into the 1.584–1.586 window (line 59);quantize/dequantize— the scale-then-threshold decision and its division back (lines 76-93);compute_scale— max-abs scaling: 1/max_abs, with 1.0 for the all-zero tensor and the empty one (lines 104-115);compute_sparsity— the zero share of the quantized tensor (lines 124-127);A note on the second commit
A post-commit
dupe_scanfound two helper names (sqrt_newton,pow2_frac) already carried by other specs — neither is mandated by the issue — so they are renamed toternary_sqrt_newtonandternary_pow2_frac, making every introduced name unique across the 2040 specs. Both commits carry theirCloses #9311reference, satisfying the per-commit L1 TRACEABILITY rule.Verification (all run live from the worktree root, zig 0.16.0, after the rename)
t27c parse: OK.t27c spec-status: IMPLEMENTED.t27c typecheck: 0 errors, 0 warnings.t27c coverage: 14/14 tested (100%) — no transports in this port.t27c test-report: 8 tests / 8 pass / 0 FAIL / 0 BLOCKED, 0 vacuous passes — the threshold boundaries (0.5 and -0.5 stay 0), the log2(3) window, the sqrt ladder windows (√2, ⁴√2), the quantize/dequantize round trip, both scale fallbacks, the sparsity shares, and the params/5 pricing with its conservative truncation.t27c gen | grep -c 'not yet implemented': 0;gen | wc -l: 169 (> 12).grep -cE '^\s*(pub )?fn (Ternary_from_f32|Ternary_to_f32|Ternary_bits_per_param|quantize|dequantize|compute_scale|compute_sparsity)\(': 7.grep -cE '^\s*test\s+(["|[A-Za-z_])': 8 (≥ 7).git status --short— exactly this one file. The repo's lefthook pre-commit passed on both commits.dupe_scan: all introduced names unique across 2040 specs (after the rename); the bare body scan adds no duplicate group (752 bodies / 221 groups on base, identical with this spec present).Dmitrii Fedorov (@dmitrii-f-t27)