Skip to content

uorc: ncm v2, 3.9% smaller on Canterbury (--best 355,559 B vs xz -9e 493,080) - #119

Merged
afflom merged 20 commits into
mainfrom
claude/project-thread-84bxra
Nov 10, 2026
Merged

afflom merged 20 commits into
mainfrom
claude/project-thread-84bxra

Conversation

@afflom

@afflom afflom commented Nov 10, 2026

Copy link
Copy Markdown
Member

Requested by Alex · project thread

A follow-up to #116, aimed at the highest ratio. This must land before the v0.2.0 tag, because it replaces the standard basis identity. No released archive uses the old one: v0.1.0 predates the basis.

Result (Canterbury, release binary, scripts/bench.mjs --steps 0)

file uorc --best before uorc --best now xz -9e
alice29.txt 38462 37321 48528
asyoulik.txt 35491 34701 44592
cp.html 6580 6485 7652
fields.c 2552 2531 3032
grammar.lsp 1114 1098 1292
kennedy.xls 17165 14838 51868
lcet10.txt 94469 90869 119488
plrabn12.txt 132637 128152 165456
ptt5 30605 28972 39860
sum 9243 9046 9500
xargs.1 1560 1546 1812
total 369878 355559 493080

--best is 3.9% smaller than before and 27.9% smaller than xz -9e. The default mode is unchanged.

What changes in the model (client/gen/ncm_model.py)

  • Two adaptive probability maps refine the mixed probability: 33 interpolated points per row over the stretch domain, one selected by the partial byte and one by an order-3 hash (2^16 rows). They are stored as offsets from their initial curve, so a fresh table is the start state and setup is unchanged.
  • A third mixer, selected by the byte before the previous one and the bit position. The three are averaged in the stretch domain.
  • Decaying plasticity: the Hebbian rate is 24 + 104·4096/(4096 + pos) per 2^16 per unit of x·err, fast while the model is fresh and steady later.
  • Checked hash buckets: each 16-slot bucket keeps its context's check byte in its unused slot 0. A context uses whichever bucket of a neighbouring pair carries its tag. Otherwise it recycles the less used of the two (by slot 1's count), so colliding contexts stop sharing statistics.

Tried and left out because they gained too little or nothing:

  • extra probability-domain inputs;
  • order-5 and word-trigram contexts;
  • a learned final mixer;
  • counter caps;
  • a third map;
  • order-confidence mixer selection;
  • per-context run inputs.

Larger tables (2^25 or 2^26 slots) would take another 0.4 to 0.5% at 2x to 4x memory, so they are not in this PR.

Checks

  • The model IR (Python interpreter), the LexLean model (Lean-native build, on 5 inputs including Canterbury's grammar.lsp and fields.c), the kernel graph (reference-semantics mirror, gen_basis.py --check) and crates/uorc/src/ncm.rs (all 11 Canterbury files) are each byte-identical to the C spec.
  • The ncm library grows, so gen_basis.py regenerates basis-id.hex, basis-library.hex and the linked ulz, ulz1 and ulz2 suffix templates (block indices move). generated/rust is re-exported (node scripts/client-export.mjs). The encoder's rust-std certificate passes, and the exact axiom lists are unchanged.
  • native_archives_are_the_model_archives (both levels) passes against the new export. cargo test --release -p uorc, cargo clippy -p uorc -p uorc-wasm --all-targets -D warnings and cargo fmt --check pass locally on top of uorc: window frames, so matches cross 8 MiB frame boundaries #117.
  • scripts/bench.mjs now passes --force. Since uorc client: inspect, verify, safe writes, multi-file archives #110 the client refuses to overwrite, and every uorc row came out as an error.


Generated by Claude Code

claude and others added 19 commits November 9, 2026 16:13
Throughput (#105): crates/uorc now carries native Rust ports of the
model's hot paths, byte-identical to it:
- ulz.rs: the LZ + range coder of Uorc.Codec.LzEncode/LzDecode.
- archive.rs: the archive layout, kernel prefix/suffix and the
  UORC-SHA256-CHAIN-v1 seal (sha2), mirroring Uorc.Codec.Archive.
compress writes exactly the archive the exported model writes (tested
against it). The native decoder only accepts payloads on which every
reading agrees (code < range throughout, match sources inside the
output, no overrun, payload consumed exactly) and so needs no canonical
re-encode check; anything else goes to the exported reference decoder,
and a differential test checks agreement on damaged payloads.

Streaming (#106): a uorc stream is standard self-contained archives laid
end to end, one per 8 MiB frame; a one-frame stream is the model's
archive byte for byte. compress_stream/decompress_stream keep memory
bounded by frames in flight, frames run in parallel (--threads), and the
native paths need no large stack (the 1 GiB reservation now applies only
to the exported reference code). The wasm page streams files through
frames too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Asa3NkSq1MUwK7keT67Uk
…P, export pending)

The ncm coder (client/gen/ncm_model.py, one IR compiled to LexLean, to the
UORC kernel graph and ported natively) and the standard kernel basis: the
ulz and ncm decoder libraries bound by one UORC-BASIS-V1 identity, named by
linked (scope 1) archives so small files carry no kernel. Compress gains a
level (--best tries ncm). The exported client is not regenerated yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Asa3NtwZjtFZ8oFtv7gMs
Throughput (#105): crates/uorc now carries native Rust ports of the
model's hot paths, byte-identical to it:
- ulz.rs: the LZ + range coder of Uorc.Codec.LzEncode/LzDecode.
- archive.rs: the archive layout, kernel prefix/suffix and the
  UORC-SHA256-CHAIN-v1 seal (sha2), mirroring Uorc.Codec.Archive.
compress writes exactly the archive the exported model writes (tested
against it). The native decoder only accepts payloads on which every
reading agrees (code < range throughout, match sources inside the
output, no overrun, payload consumed exactly) and so needs no canonical
re-encode check; anything else goes to the exported reference decoder,
and a differential test checks agreement on damaged payloads.

Streaming (#106): a uorc stream is standard self-contained archives laid
end to end, one per 8 MiB frame; a one-frame stream is the model's
archive byte for byte. compress_stream/decompress_stream keep memory
bounded by frames in flight, frames run in parallel (--threads), and the
native paths need no large stack (the 1 GiB reservation now applies only
to the exported reference code). The wasm page streams files through
frames too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Asa3NkSq1MUwK7keT67Uk
…ntial tests, ulz history window

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Asa3NkSq1MUwK7keT67Uk
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Asa3NkSq1MUwK7keT67Uk
Scalars live in a small table instead of a rebuilt record, long statement
lists are split into functions, literals go first in additions, and literal
loop counts name the state, so the preservation certificate does not unroll
the model's setup. Output is byte-identical to before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Asa3NtwZjtFZ8oFtv7gMs
A frame can name the outputs of the K preceding frames (K = 1 or 2) as
basis roots 1..K after the kernel library (root 0), so its ulz payload is
coded against that window and matches reach across frame boundaries.

- LzDecode.decodeWith / LzEncode.encodeWith: the codec against a history
  window (decode/encode are the empty-history case, byte for byte as before).
- ulz library block runWith(payload, history); window entries apply it to
  basisGet 1 (++ basisGet 2). Graph mirror gains basisGet; gen_basis --check
  decodes K=1 and K=2 window frames on the mirror.
- Archive: windowIdentity (UORC-BASIS-V1 chain over [library, window..]),
  windowArchive, ulzWindowArchive, windowDecode, fastDecodeWith,
  windowMaterialize (keeps scope 1 and the identity; inlines the library).
- Client: compress(input, window, steps, level); decompress(archive, window,
  work) passes scope conditional + basis [library, window..] to the
  reference trial for window frames.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Asa3NkSq1MUwK7keT67Uk
The differential tests run the exported decoder graph; unoptimized, the uorc
unit tests took 30 min of the 60 min acceptance leg (main is over budget
too). At opt-level 1 they take 4.5 min for about 6 min more compile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Asa3NkSq1MUwK7keT67Uk
ncm, a context-mixing coder extrapolated from the neuromorphic model, is
written once as an IR and compiled to LexLean, to a UORC kernel graph and
natively. The ulz and ncm decoder libraries form root 0 of a UORC-BASIS-V1
basis; archives are linked to it by identity, so small files no longer
carry a 2.6 KB kernel. Level::Best (--best) also tries ncm and keeps the
smaller archive; on Canterbury it is smaller than xz -9e on every file.

inspect names linked archives' representation (ulz or ncm).

Closes #62. Closes #107.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Asa3NtwZjtFZ8oFtv7gMs
…-84bxra

# Conflicts:
#	crates/uorc-wasm/src/lib.rs
#	crates/uorc/src/archive.rs
#	crates/uorc/src/bin/uorc.rs
#	crates/uorc/src/lib.rs
The context-mixing coder gains:
- two adaptive probability maps (selected by the partial byte and by an
  order-3 hash) that refine the mixed probability;
- a third mixer, selected by the byte before the previous one and the
  bit position;
- a plasticity that decays from 128/65536 to 24/65536 per unit of
  x * err as the input is seen;
- a check byte in each 16-slot bucket's unused slot 0, with a neighbour
  pair and recycling by use, so colliding contexts stop sharing counts.

Model IR, LexLean, kernel graph and the native port are byte-identical
to the C spec on Canterbury. The ncm library grows, so the basis
identity and the linked templates are regenerated, and generated/rust
is re-exported. No released archive uses the previous identity.

Canterbury, uorc --best: 355,559 B (was 369,878; xz -9e 493,080).

bench.mjs passes --force, since the client refuses to overwrite.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Asa3NtwZjtFZ8oFtv7gMs
@afflom afflom self-assigned this Nov 10, 2026
@afflom
afflom merged commit 6ff6d51 into main Nov 10, 2026
14 checks passed
afflom pushed a commit that referenced this pull request Nov 10, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Asa3NkSq1MUwK7keT67Uk
afflom pushed a commit that referenced this pull request Nov 10, 2026
… arrived through the branch history)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Asa3NpWuTWFrL9kYU72Rv
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