Repository navigation
feat(spec): 2-layer BitNet×GF-T MLP + fix negative-zero cancellation in signed add (Refs #1764) - #1797
Merged
Conversation
…ed add
specs/ternary/gft_mlp2.t27: a spec-first 2-layer BitNet x GF-T MLP --
GF-T16 activations -> layer 1 (2 neurons, trit weights) -> hidden trits
re-embedded as GF-T -> layer 2 -> output trit. End-to-end multi-layer
inference, bit-exact to the oracle composition over 3000 vectors.
Correctness fix (latent in 4 merged signed specs): sadd(-1.0, +1.0)
returned 0x10000 (a wrong negative zero) instead of 0 on exact
cancellation when the larger operand is negative. Root cause: gen-verilog
does not lower a `return` nested inside an `if` block as an early
return, so `if(ma>=mb){...; if(r==0)return 0; return (sa<<16)|r;}` fell
through to (sa<<16)|0 when r==0. Restructured sadd to a single top-level
r==0 guard in gft_signed_mac/signed_dot4/bitnet_neuron/neuron_full/mlp2;
re-verified all (signed_mac now with cancellation-heavy vectors). The
MLP was the first design to hit it (inter-layer +-1.0 cancel exactly).
No compiler change; 1535 unit tests pass. gen-verilog nested-early-
return is a compiler limitation to fix separately.
Refs #1764
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
|
📓 NotebookLM Notebook linked to this PR
This notebook contains session context, decisions, and artifacts for this work. |
Contributor
PR DashboardGenerated at: 2026-08-06 14:51:45 UTC
Summary
Seal Status
|
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.
Refs #1764
2-layer BitNet×GF-T MLP —
specs/ternary/gft_mlp2.t27End-to-end multi-layer inference: GF-T16 activations → layer 1 (2 neurons, trit weights) → 2 hidden trits → re-embedded as GF-T activations {N→-1,Z→0,P→+1} → layer 2 (1 neuron) → output trit. Bit-exact to the ideal oracle composition over 3000 vectors.
Correctness fix — latent bug in 4 merged signed specs
While bringing up the MLP, found that
sadd(-1.0, +1.0)returned0x10000(a wrong negative zero) instead of0on exact cancellation when the larger operand is negative. Root cause: gen-verilog does not lower areturnnested inside anifblock as an early return — soif(ma>=mb){...; if(r==0)return 0; return (sa<<16)|r;}fell through to(sa<<16)|0whenr==0. Restructuredsaddto a single top-levelif(r==0)return 0guard ingft_signed_mac,gft_signed_dot4,gft_bitnet_neuron,gft_neuron_full,gft_mlp2; re-verified all (signed_mac now with cancellation-heavy vectors that catch the bug). The MLP was the first design to hit it (inter-layer ±1.0 activations cancel exactly).No compiler change; 1535 unit tests pass. The gen-verilog nested-early-return limitation is a separate compiler fix.
🤖 Generated with Claude Code