feat(spec): GF-T log2 primitive + cross-entropy (NLL) loss (Refs #1764) - #1805
Merged
Conversation
gft_log2.t27 (GftLog2): log2(x) for a positive GF-T16 -> signed GF-T16, inverse of exp2. log2(x) = (o-40) + log2(1+m/512); the fractional part is a Q Horner quartic, the integer+fraction value is normalized fixed->GF-T via a flat 31-step priority encoder (yosys-synthesizable). Accuracy <=0.008 abs vs true log2. iverilog 505/505 bit-exact. Bug found+fixed (broken-ruler class): the log2 poly has NEGATIVE coefficients, and t27 emits `>>` as a LOGICAL shift on signed regs -> filled 0 for negative intermediates instead of arithmetic floor. Fixed with an explicit asr9 helper using only non-negative shifts. (exp2's all-positive poly never hit this.) gft_nll.t27 (GftNll): cross-entropy / NLL loss for a one-hot label -- given the softmax probability p of the true class, returns -log2(p) (composes gft_log2 + sign flip). iverilog 403/403; p=1->0, p=0.5->1.0, p=0.25->2.0 (exact). Opens inference -> TRAINING on GF-T: forward softmax->prob, then NLL->loss, with the inverse pair exp2/log2 both verified. Fresh seals for GftLog2 + GftNll (seal --verify MATCH). No compiler change. Refs #1764 Co-Authored-By: Claude Opus 4.8 <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.
Stacked on #1804 (softmax branch). Base retargets to
masteras the stack merges.Deliverable C of "все три параллельно" (A = merge queue, infra-blocked; B = softmax synthesizability check, run separately).
gft_log2.t27— GF-T log2 primitive (inverse of exp2)log2(x)for a positive GF-T16 → signed GF-T16.log2(x) = (o−40) + log2(1+m/512); the fractional part is a Q Horner quartic, and the integer+fraction real value is normalized fixed→GF-T via a flat 31-step priority encoder (yosys-synthesizable, nowhile).Accuracy ≤0.008 abs vs true log2 (output-quantization limited). iverilog 505/505 bit-exact. Spot checks exact: log2(1)=0, log2(2)=1, log2(0.5)=−1, log2(4)=2.
gft_nll.t27— GF-T cross-entropy / NLL lossFor a one-hot label: given the softmax probability
pof the true class, returns the loss−log2(p)(composesgft_log2+ sign flip). iverilog 403/403;p=1→0,p=0.5→1.0,p=0.25→2.0(exact cross-entropy).This opens the path from inference to training on GF-T: forward
softmax → prob, thenNLL → loss, with the inverse pairexp2/log2both verified. Fresh seals (seal --verify→ MATCH). No compiler change.Refs #1764
🤖 Generated with Claude Code