Skip to content

feat(hpc): Codec8 — compile-time 8-bit codec (phase a, scalar) + ratified plan - #370

Merged
AdaWorldAPI merged 9 commits into
masterfrom
research/i8-rne-dual-range-20261024
Oct 24, 2026
Merged

AdaWorldAPI merged 9 commits into
masterfrom
research/i8-rne-dual-range-20261024

Conversation

@AdaWorldAPI

@AdaWorldAPI AdaWorldAPI commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

What

Phase (a) of .claude/plans/quantized-codec8-v2.md (content v3, ratified by a 5+3 council). The earlier runtime-scale prototype on this branch is gone (backed out in 62c43c9).

src/hpc/codec8.rs adds one codec, Codec8<Storage, CodeSpace, Rounding, NanPolicy>, built from sealed marker types. The calibration is a marker type passed to each call, and nothing is selected at run time.

parameter markers
storage I8, U8 (u8 = i8 ^ 0x80 for Asym/Sym, the raw code for UnitFull)
code space Asym (-128..127), Sym (-127..127), UnitFull (c/255)
rounding TiesAway, TiesEven, Floor
NaN policy NoNaN, NaNAtMin (only with Sym, where -128 means NaN)
  • Combinations that don't compile: Asym + NaNAtMin and I8 + UnitFull are E0277; doctests pin both.
  • Encode: a true division, because a precomputed reciprocal changes codes at half-ties. The zero point is added as an integer.
  • Calibration check: const assertions reject a non-positive or non-finite scale, or a zero point outside the code space. They run on encode and on decode, so code that only decodes is covered too; a compile_fail,E0080 doctest pins the decode-only path.
  • Integer rounding: div_round works from the quotient and remainder, so it does not overflow for any u128 operands.
  • Checking: the checked encode/decode validate once per slice. The unchecked bodies are pub(crate) and give a defined result for every input.
  • Aliases: TfliteAct, TfliteWeight, OnnxQ, SpoFcTruth. NativeLane is held back until its rounding is decided (plan §8 item 1).
  • Clippy: codec8.rs opts back into clippy::all, because pub mod hpc allows it.

Also in this PR:

  • examples/codec8_asm_probe.rs and scripts/codec8_asm_diff.sh, the assembly and timing probe.
  • The plan, and .claude/knowledge/coresearch-2026-10-24-i8-codec8-map.md.
  • A blackboard entry.

Tests and gates

  • cargo test --release --lib hpc::codec8: 16 passed.
  • cargo test --release --doc hpc::codec8: 11 passed. This includes two compile_fail,E0277 doctests and one compile_fail,E0080 doctest.
  • Codex findings: both are fixed and disable-checked. Removing the decode-path assertion makes the E0080 doctest compile, so it fails. Restoring (2n + d)/(2d) fails the large-operand test.
  • G2 byte identity: TfliteAct with the fitted scale bits equals quantize_f32_to_i8, including NaN and ±inf.
  • G13 spoFC: encode_ratio with Floor equals the spoFC encoder over the evidence grid.
  • Clippy (-D warnings) and cargo fmt --check are clean.
  • G5 assembly: on x86-64-v3 and -v4, the generic and hand-written kernels compile to identical code (vectorised, vdivps). The negative control differs.
  • G6 timing: not met as written. Repeated runs of identical machine code vary by up to 17% on this host, so a 2% band can't be resolved. G5 is the evidence that the parameters cost nothing.

Not in this PR

  • (b) The codegen check on every arm, which follows in its own PR.
  • (c) The certified tables and their generator.
  • (d) Code laws.
  • (e) Head-to-head probes.
  • (f) The lance-graph facades.

Plan §8 lists the decisions still open.

🤖 Generated with Claude Code

https://claude.ai/code/session_01G22yT6htkcdyXsihxxXdrg

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 02d03756-5dc7-48a0-9287-7435221ac82f
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@AdaWorldAPI AdaWorldAPI changed the title research(quantized): dual explicit-scale signed-i8 RNE range contracts research(quantized): U8 / i8-asym / i8-sym+NaN contracts and staged probe Oct 24, 2026
@AdaWorldAPI AdaWorldAPI changed the title research(quantized): U8 / i8-asym / i8-sym+NaN contracts and staged probe [BEING REFACTORED — do not merge] research(quantized): U8 / i8-asym / i8-sym+NaN contracts and staged probe Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Being refactored. Do not merge or review this version.

This branch was pushed without being compiled. CI fails because of a missing doc comment (src/hpc/quantized.rs:576, denied by -D missing-docs) and unformatted code. The design is also being replaced:

  • Scale and zero point are runtime arguments here. In the refactor, calibration is a compile-time marker. Runtime calibration exists only behind a lab-calibration Cargo feature.
  • Every element is checked and the result is collected into a Result<Vec<_>, _>. Validation moves to the boundary, so the hot path is a hoisted, vectorisable loop.
  • Each mode has its own function. The refactor has a single Codec8<Storage, CodeSpace, Rounding, NaN> over marker types, with I8 and U8 storage.
  • There are no tanh tables. The refactor adds const 256-entry tables written by a certified offline generator, plus a test that regenerates them.
  • The refactor adds gates: generic and hand-written code must compile to identical assembly, plus timing checks.

The edge-case test inputs carry over: signed zero, both saturations, negative half-ties, and all 256 codes. Before the next push I will run cargo fmt, clippy -D warnings, the docs lint and cargo test --release locally.


Generated by Claude Code

…runtime-scale prototype

- .claude/plans/quantized-codec8-v2.md: one compile-time Codec8<Storage,
  CodeSpace, Rounding, NanPolicy>, calibration as a marker type, prepare vs
  execute, certified const tables, edge cases, measured results, checklist,
  open items, superseded designs named once. Goes through /5plus3 next.
- .claude/knowledge/coresearch-2026-10-24-i8-codec8-map.md: the /coresearch
  exploration map, banked so it survives the container.
- the staged prompt is marked superseded (kept for provenance).
- src/hpc/quantized.rs: back to master. The per-mode runtime-scale functions
  contradicted the compile-time ruling and never compiled under -D missing-docs;
  their edge-case inputs carry over into the v2 checklist.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G22yT6htkcdyXsihxxXdrg
The plan file keeps its name; its content is now v3. Changes from the
council: true division in encode (a precomputed reciprocal changes codes at
half-ties), exact scale bits for the byte-identity gate, a concrete
compile_fail with a compiling twin, a clippy opt-in in codec8 (pub mod hpc
allows clippy::all), the table generator in tools/ instead of a crate, SIMD
primitives landing first, XOR storage scoped to Asym/Sym, UnitOdd/UnitMidrise
test-only, NativeLane held until its rounding is decided, a per-mode table
inventory, separate data and table rounding gates, spoFC byte and three-mode
head-to-head gates, and restore conditions for parked arms.

Blackboard entry added in the same commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G22yT6htkcdyXsihxxXdrg
One `Codec8<Storage, CodeSpace, Rounding, NanPolicy>` over sealed marker
types, with calibration as a marker type (plan .claude/plans/quantized-codec8-v2.md,
ratified by a 5+3 council). Nothing is selected at run time.

- Storage I8 / U8 (u8 = i8 ^ 0x80 for Asym/Sym, raw for UnitFull); code spaces
  Asym, Sym, UnitFull; rounding TiesAway / TiesEven / Floor; NaNAtMin only for
  Sym (Asym + NaNAtMin and I8 + UnitFull are E0277, pinned by doctests).
- Encode uses a true division (a reciprocal changes codes at half-ties) and
  adds the zero point as an integer; const assertions reject a bad calibration.
- Checked encode/decode validate once per slice; the unchecked bodies are
  pub(crate) and total.
- Aliases: TfliteAct, TfliteWeight, OnnxQ, SpoFcTruth. NativeLane waits for
  the operator's rounding decision.
- codec8.rs opts back into clippy::all (pub mod hpc allows it).

Gates: 14 unit tests and 10 doctests pass; G2 byte identity with
quantize_f32_to_i8; G13 spoFC floor encoder equality; clippy -D warnings and
fmt clean. G5: generic and hand-written kernels compile to identical asm on
x86-64-v3 and -v4, negative control differs (scripts/codec8_asm_diff.sh,
examples/codec8_asm_probe.rs). G6's 2% timing band is not resolvable on this
host (identical code varies up to 17%) and is recorded as not met.

Blackboard and plan updated in the same commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G22yT6htkcdyXsihxxXdrg
@AdaWorldAPI AdaWorldAPI changed the title [BEING REFACTORED — do not merge] research(quantized): U8 / i8-asym / i8-sym+NaN contracts and staged probe feat(hpc): Codec8 — compile-time 8-bit codec (phase a, scalar) + ratified plan Oct 24, 2026
@AdaWorldAPI
AdaWorldAPI marked this pull request as ready for review October 24, 2026 13:37
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T13:39:43.978366Z 4c82adf Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4c82adf3a5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/hpc/codec8.rs
Comment thread src/hpc/codec8.rs Outdated
Codex review on #370:
- The SCALE/ZERO_POINT const asserts lived only in encode_one, so a
  consumer that only decoded never instantiated them; SCALE = -1.0
  compiled and decoded. Both directions now call assert_calibration,
  pinned by a compile_fail,E0080 doctest on the decode-only path.
- TiesAway::div_round computed 2n + d and 2d, TiesEven compared 2r
  with d; both wrap for large u128 operands. Both now use quotient and
  remainder with the half test as r vs d - r. Tests at 2^127 and
  u128::MAX, plus small-operand tie tables.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G22yT6htkcdyXsihxxXdrg
@AdaWorldAPI
AdaWorldAPI merged commit be18d17 into master Oct 24, 2026
30 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.

2 participants