Skip to content

feat(spec): GF-T log2 primitive + cross-entropy (NLL) loss (Refs #1764) - #1805

Merged
gHashTag merged 1 commit into
feat/gft-recip-softmaxfrom
feat/gft-log2-nll
Aug 6, 2026
Merged

feat(spec): GF-T log2 primitive + cross-entropy (NLL) loss (Refs #1764)#1805
gHashTag merged 1 commit into
feat/gft-recip-softmaxfrom
feat/gft-log2-nll

Conversation

@gHashTag

@gHashTag gHashTag commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Stacked on #1804 (softmax branch). Base retargets to master as 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, no while).

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.

🐞 Bug found + fixed (broken-ruler class): the log2 poly has negative coefficients, and t27 emits >> as a logical shift on signed regs — it filled 0 for negative intermediates instead of arithmetic floor, so the generated Verilog diverged from the Python model. Fixed with an explicit asr9 helper using only non-negative shifts. (exp2's all-positive poly never triggered it.)

gft_nll.t27 — GF-T cross-entropy / NLL loss

For a one-hot label: given the softmax probability p of the true class, returns the loss −log2(p) (composes gft_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, then NLL → loss, with the inverse pair exp2/log2 both verified. Fresh seals (seal --verify → MATCH). No compiler change.

Refs #1764

⚠️ GitHub Actions infra incident ongoing. All verification is local (iverilog + seals).

🤖 Generated with Claude Code

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>
@gHashTag
gHashTag merged commit 2c3d254 into feat/gft-recip-softmax Aug 6, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant