Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/guides/native_ngram_memory.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ straight to `meft_rows_gather`. On uncompressed tables it halves lookup time
compared with `rows`
([profile](../../evidence/host_query_profile_20261112/README.md)).

All-raw native tables now skip block sorting and copy directly after validating
original IDs and forwarding. On existing AG News/DBpedia seed-3 tables, paired
CPU gathers were 1.57–1.65× faster with unchanged bytes
([results](../../evidence/native_direct_gather_20261115/README.md)). Compressed
tables retain grouped reads. `NativeRows.last_xor_bytes` reports previous-row
XOR reconstruction separately from complete stream decompression; full-block
cache fills always reconstruct every row.

## Native layout and construction

`MEFTNAT1` is a little-endian binary file: a versioned header, an optional
Expand Down
1 change: 1 addition & 0 deletions evidence/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ here: links in locked READMEs still point to them, and they forward to
| [1.85M-row CPU capacity](cpu_capacity_evidence_20261030/README.md) · [sparse blocks](sparse_blocks_evidence_20261030/README.md) | Smaller blocks cut native miss latency 16–27×; raw mmap remains faster |
| [Large FP16/INT8 capacity](quantized_capacity_evidence_20261031/README.md) | FP16 native saves 52.29% vs raw FP32; INT8 native expands vs raw INT8 |
| [Host query profile on AG News](host_query_profile_20261112/README.md) | Time is block decompression. On the twelve original tables, dedup without compression saves 85.0–85.8% (vs 85.7–86.6% with Zstd) and the GPU host path runs 1.09–1.23× raw with identical logits; on uniform-init tables raw is best. `ngram-store plan` predicts these layout sizes exactly and reports how the duplicates are distributed |
| [Direct native gathers](native_direct_gather_20261115/README.md) | All-raw tables bypass query sorting: 1.57–1.65× faster paired CPU gathers on existing AG News/DBpedia seed-3 tables, with unchanged original code bytes. Conditional XOR prefix reconstruction reduces work, but the eight saved Qwen controls show about 1.00× speed |
| [Token-level n-grams do not transfer](token_ngram_duplicates_20261115/README.md) | WikiText-103 with the Qwen3 tokenizer, 124M tokens, 512-token windows: order 4 repeats 88.35%, but 85% of keys occur in one window and collapse there. Among keys seen in several windows deduplication saves 27.2%, and that falls to 10.5% at a count threshold of 3. Zero initialization only; no training involved |
| [Native query/cache controls](native_query_evidence_20261030/README.md) · [decoded-block cache](native_cache_20261022.md) ([data](native_cache_evidence_20261022/)) | Cache sizing and hit/miss behaviour |
| [XOR blocks](native_xor_compression_20261020.md) ([data](native_xor_evidence_20261020/)) · [streaming export](streaming_export_20261021.md) ([data](export_evidence_20261021/)) · [first native pilots](native_ngram_evidence_20261018/) | Codec and export-path development |
Expand Down
93 changes: 93 additions & 0 deletions evidence/native_direct_gather_20261115/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Direct native gathers on existing trained tables

All-raw native tables now bypass block sorting and copy directly from their
contiguous physical payload after validating every requested original ID and
forwarding entry. Distinct-block counters use a reusable query-sized hash;
ordered queries avoid that hash. Allocation failure falls back to the grouped
reader. Original IDs, aliases, row bytes, file formats and existing C ABI remain
compatible. Cache budgets do not cause raw payload copies into a decoded cache.

## Measured result

Paired CPU **row gathers**, not complete classification or LLM inference:

| Trained table | Original rows | Baseline p50 (µs) | Direct p50 (µs) | Paired geometric speed ratio |
| --- | ---: | ---: | ---: | ---: |
| AG News, uniform, seed 3 | 6,989,612 | 35.34 | 22.28 | 1.59× |
| AG News, zero, seed 3 | 6,989,612 | 32.90 | 21.02 | 1.57× |
| DBpedia, uniform, seed 3 | 34,050,161 | 45.68 | 27.17 | 1.65× |
| DBpedia, zero, seed 3 | 34,050,161 | 43.30 | 26.05 | 1.63× |

Each arm reads the **same existing deduplicated, uncompressed artifact**; every
warmup and timed output is compared byte-for-byte with the original FP32 codes.
This reduces query overhead without changing stored capacity or model weights.
The previously measured [table savings and GPU host path](../host_query_profile_20261112/README.md)
remain separate measurements. Uniform-init byte dedup does not save capacity;
including that layout here tests the reader and does not recommend it over raw.

- Source implementation: `4a89d3c55b77ce36830872271cdf726324ab2e49`.
- Data/models: existing registered AG News and DBpedia classifiers, zero and
uniform initialization, seed 3. 256 official test documents per dataset,
sampled without replacement with seed 20261112; OOV ID zero removed as in
`StagedClassifier`. The request IDs are never reordered or replicated.
- Measurement: 2 warmup passes, 10 timed passes, 3 paired rounds; baseline and
candidate alternate per request. Independent handles, preallocated inputs and
outputs, zero native cache, one pinned CPU core per model. Both use the same
optional-codec build. p50 columns are medians of the three round p50s.
- Environment: AMD EPYC 7713, Linux 5.4, Python 3.11.15, NumPy 2.2.6,
PyTorch 2.11.0, GCC 11.4.0. No GPU, retraining or paid API was used.
Energy and monetary costs are unmeasured.
- Scope: warm file-cache row lookup after addressing. Four jobs ran in parallel
on distinct cores; ratios are descriptive, not confidence intervals. This
does not measure quantizer decoding, reductions, transfer or full requests.

## Conditional XOR optimization and negative control

Previous-row XOR stream queries now reconstruct through the highest requested
physical row when a full decoded block will not enter the cache. Complete stream
decompression and validation still run; full-block cache fills reconstruct the
entire block. `NativeRows.last_xor_bytes` / `meft_rows_last_xor_bytes()` distinguish
this work from full decoded bytes. Chunked gathers and embedding bags aggregate
both counters.

The first controlled run (`1e82e5e`) reused the saved 32 official MultiCounterFact
query traces of two trained Qwen memory tables (seed 3), at block sizes
16/64/256/1024. Across all eight cases, the speed ratio stayed **about 1.00×**.
Only two cases reconstructed any previous-row XOR at all; their XOR work fell
by 13% and 33%, but stream decompression dominated. This is a conditional work
reduction, not a demonstrated Qwen speedup. Plain/raw and independent row-packet
codecs are unaffected by this predictor change.

## Checks and reproduction

[Tests](tests/): local suite 379 tests passed (149 optional skips); local native
suite 43 passed (5 optional skips); remote native suite 43 passed without skips,
including PyTorch and optional LZ4/Zstd/libdeflate. ASan/UBSan passed locally and
remotely, including raw direct reads, malformed streams and cache growth.

[summary.json](summary.json) indexes all twelve original timing records in
[raw/](raw/), compressed with gzip to keep the checkout small. Records include
commands, file and library SHA256s, source commit, environment, raw per-request
timings and logical-work counts. [build.json](build.json) records compiler,
headers, library hashes and baseline flags. Weights, tables, query arrays and
corpora are retained in the user's experiment workspace and are not added here.

On the existing registered experiment workspace, compile both libraries using
`build.json`. The later baseline disables both optimizations with
`-DMEFT_DISABLE_RAW_GATHER -DMEFT_DISABLE_XOR_PREFIX`; the first Qwen control
disables only XOR prefixes. Run:

```sh
PYTHONPATH=/llm-align/duyimin/ngram-sparse-xor-20261115/runtime \
/llm-align/duyimin/ngram-counterfact-capacity-20261106/env/bin/python \
evidence/native_direct_gather_20261115/scripts/run_raw.py \
--work /llm-align/duyimin/ngram-sparse-xor-20261115 \
--commit 4a89d3c55b77ce36830872271cdf726324ab2e49
```

The general measurement entry point is
[`tools/benchmark_native_gather.py`](../../tools/benchmark_native_gather.py).
It rejects changed trace hashes, invalid IDs, table/code dimensions, byte
mismatches or changed decode work between the two arms. Rebuilding the trained
artifacts requires the original training protocol and data; these saved results
alone do not reproduce a new model-quality experiment.
67 changes: 67 additions & 0 deletions evidence/native_direct_gather_20261115/build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"source_commit": "4a89d3c55b77ce36830872271cdf726324ab2e49",
"compiler": "cc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0\nCopyright (C) 2021 Free Software Foundation, Inc.\nThis is free software; see the source for copying conditions. There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n",
"headers": {
"lz4.h": "https://raw.githubusercontent.com/lz4/lz4/v1.9.3/lib/lz4.h",
"zstd.h": "https://raw.githubusercontent.com/facebook/zstd/v1.4.8/lib/zstd.h",
"libdeflate.h": "https://raw.githubusercontent.com/ebiggers/libdeflate/v1.10/libdeflate.h"
},
"files": {
"/llm-align/duyimin/ngram-sparse-xor-20261115/include/libdeflate.h": {
"sha256": "5ead6b5be40c415a11429e711480c6dbde1dee6508391f23b31f95bb1c5d87d8",
"bytes": 15154
},
"/llm-align/duyimin/ngram-sparse-xor-20261115/include/._libdeflate.h": {
"sha256": "08201127903639e30c8a3f1e75fcd92a11151e04683c2f884fd7098392413817",
"bytes": 163
},
"/llm-align/duyimin/ngram-sparse-xor-20261115/include/zstd.h": {
"sha256": "e5dd7935c6c7655dcafd868c265ecb97008a338c51286562ef093f43969c7b46",
"bytes": 138334
},
"/llm-align/duyimin/ngram-sparse-xor-20261115/include/lz4.h": {
"sha256": "c9b52a14c2c93fe5c435a09054cc8f1bf5d94a3ce1a38dc51296a92ce409f8e4",
"bytes": 40861
},
"/llm-align/duyimin/ngram-sparse-xor-20261115/include/._zstd.h": {
"sha256": "08201127903639e30c8a3f1e75fcd92a11151e04683c2f884fd7098392413817",
"bytes": 163
},
"/llm-align/duyimin/ngram-sparse-xor-20261115/include/._lz4.h": {
"sha256": "08201127903639e30c8a3f1e75fcd92a11151e04683c2f884fd7098392413817",
"bytes": 163
},
"/llm-align/duyimin/ngram-sparse-xor-20261115/lib/candidate-codecs.so": {
"sha256": "0fa6bc8604c6c20031a252ebf1a2d9c9cea148a6cdd38f9c860ad603a9504ec0",
"bytes": 34472
},
"/llm-align/duyimin/ngram-sparse-xor-20261115/lib/baseline-codecs.so": {
"sha256": "edb6e93484e90994c76288e31295d0ac59cfa791ff23e084218382f84367f036",
"bytes": 34472
},
"/llm-align/duyimin/ngram-sparse-xor-20261115/lib/candidate.so": {
"sha256": "4e41e56e80ab3244a1d6b3d4999a1f522ff9406952a938f478e5b0f0f323804b",
"bytes": 34048
},
"/llm-align/duyimin/ngram-sparse-xor-20261115/lib/baseline.so": {
"sha256": "ede1b2d6657cbaed7949f8d44b0956702c1fd956262b9fb1e1eb30f2335dcd76",
"bytes": 34048
},
"/llm-align/duyimin/ngram-sparse-xor-20261115/runtime/native/meft_rows.c": {
"sha256": "6a2908eb2e998fa0b2579739f80051b953c2093edc2eb70451bbd3c27cfc763c",
"bytes": 44978
},
"/llm-align/duyimin/ngram-sparse-xor-20261115/runtime/native/meft_rows.h": {
"sha256": "48198f4bc84777d35091e1ee86886324d7bffa011c5ef71a870c501100da2da5",
"bytes": 8675
},
"/llm-align/duyimin/ngram-sparse-xor-20261115/runtime/tools/benchmark_native_gather.py": {
"sha256": "c2d756f46d5a39c2e0512d869e6a8485e86e5a10fda0dbf11755b0016d2111f0",
"bytes": 8045
}
},
"codecs_flags": "-I/llm-align/duyimin/ngram-sparse-xor-20261115/include -DMEFT_USE_LZ4 -DMEFT_USE_ZSTD -DMEFT_USE_LIBDEFLATE -l:liblz4.so.1 -l:libzstd.so.1 -l:libdeflate.so.0",
"compile": "cc -std=c11 -O3 -fPIC -shared native/meft_rows.c -lz FLAGS -o LIBRARY",
"baseline_extra_flags": "-DMEFT_DISABLE_XOR_PREFIX -DMEFT_DISABLE_RAW_GATHER",
"first_xor_run": "1e82e5e, cc -std=c11 -O3 -fPIC -shared native/meft_rows.c -lz, baseline extra -DMEFT_DISABLE_XOR_PREFIX; baseline.so and candidate.so refer to this first run."
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
110 changes: 110 additions & 0 deletions evidence/native_direct_gather_20261115/run-raw-status.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
[
{
"model": "ag_news-exact-zero-s3-lr10",
"returncode": 0,
"command": [
"/llm-align/duyimin/ngram-counterfact-capacity-20261106/env/bin/python",
"-m",
"tools.benchmark_native_gather",
"--table",
"/llm-align/duyimin/ngram-host-profile-20261112/bundles/ag_news-exact-zero-s3-lr10/dedup-raw/rows.meft",
"--codes",
"/llm-align/duyimin/ngram-controlled-deployment-20261111/training-registered/ag_news-exact-zero-s3-lr10/rows.npy",
"--traces",
"/llm-align/duyimin/ngram-sparse-xor-20261115/traces/ag_news.npz",
"--baseline-library",
"/llm-align/duyimin/ngram-sparse-xor-20261115/lib/baseline-codecs.so",
"--library",
"/llm-align/duyimin/ngram-sparse-xor-20261115/lib/candidate-codecs.so",
"--output",
"/llm-align/duyimin/ngram-sparse-xor-20261115/results/ag_news-exact-zero-s3-lr10-raw.json",
"--commit",
"4a89d3c55b77ce36830872271cdf726324ab2e49",
"--core",
"40",
"--cache-bytes",
"0"
]
},
{
"model": "ag_news-exact-uniform-s3-lr10",
"returncode": 0,
"command": [
"/llm-align/duyimin/ngram-counterfact-capacity-20261106/env/bin/python",
"-m",
"tools.benchmark_native_gather",
"--table",
"/llm-align/duyimin/ngram-host-profile-20261112/bundles/ag_news-exact-uniform-s3-lr10/dedup-raw/rows.meft",
"--codes",
"/llm-align/duyimin/ngram-controlled-deployment-20261111/training-registered/ag_news-exact-uniform-s3-lr10/rows.npy",
"--traces",
"/llm-align/duyimin/ngram-sparse-xor-20261115/traces/ag_news.npz",
"--baseline-library",
"/llm-align/duyimin/ngram-sparse-xor-20261115/lib/baseline-codecs.so",
"--library",
"/llm-align/duyimin/ngram-sparse-xor-20261115/lib/candidate-codecs.so",
"--output",
"/llm-align/duyimin/ngram-sparse-xor-20261115/results/ag_news-exact-uniform-s3-lr10-raw.json",
"--commit",
"4a89d3c55b77ce36830872271cdf726324ab2e49",
"--core",
"42",
"--cache-bytes",
"0"
]
},
{
"model": "dbpedia_14-exact-zero-s3-lr10",
"returncode": 0,
"command": [
"/llm-align/duyimin/ngram-counterfact-capacity-20261106/env/bin/python",
"-m",
"tools.benchmark_native_gather",
"--table",
"/llm-align/duyimin/ngram-host-profile-20261112/bundles/dbpedia_14-exact-zero-s3-lr10/dedup-raw/rows.meft",
"--codes",
"/llm-align/duyimin/ngram-controlled-deployment-20261111/training-registered/dbpedia_14-exact-zero-s3-lr10/rows.npy",
"--traces",
"/llm-align/duyimin/ngram-sparse-xor-20261115/traces/dbpedia_14.npz",
"--baseline-library",
"/llm-align/duyimin/ngram-sparse-xor-20261115/lib/baseline-codecs.so",
"--library",
"/llm-align/duyimin/ngram-sparse-xor-20261115/lib/candidate-codecs.so",
"--output",
"/llm-align/duyimin/ngram-sparse-xor-20261115/results/dbpedia_14-exact-zero-s3-lr10-raw.json",
"--commit",
"4a89d3c55b77ce36830872271cdf726324ab2e49",
"--core",
"44",
"--cache-bytes",
"0"
]
},
{
"model": "dbpedia_14-exact-uniform-s3-lr3",
"returncode": 0,
"command": [
"/llm-align/duyimin/ngram-counterfact-capacity-20261106/env/bin/python",
"-m",
"tools.benchmark_native_gather",
"--table",
"/llm-align/duyimin/ngram-host-profile-20261112/bundles/dbpedia_14-exact-uniform-s3-lr3/dedup-raw/rows.meft",
"--codes",
"/llm-align/duyimin/ngram-controlled-deployment-20261111/training-registered/dbpedia_14-exact-uniform-s3-lr3/rows.npy",
"--traces",
"/llm-align/duyimin/ngram-sparse-xor-20261115/traces/dbpedia_14.npz",
"--baseline-library",
"/llm-align/duyimin/ngram-sparse-xor-20261115/lib/baseline-codecs.so",
"--library",
"/llm-align/duyimin/ngram-sparse-xor-20261115/lib/candidate-codecs.so",
"--output",
"/llm-align/duyimin/ngram-sparse-xor-20261115/results/dbpedia_14-exact-uniform-s3-lr3-raw.json",
"--commit",
"4a89d3c55b77ce36830872271cdf726324ab2e49",
"--core",
"46",
"--cache-bytes",
"0"
]
}
]
Loading
Loading