Skip to content

Batch TONN running-sum circuits into one scan - #67

Merged
AvnehSBhatia merged 1 commit into
exea-labs:mainfrom
man-coding-j:codex/pr-batched-running-sum-scan
Nov 22, 2026
Merged

AvnehSBhatia merged 1 commit into
exea-labs:mainfrom
man-coding-j:codex/pr-batched-running-sum-scan

Conversation

@man-coding-j

Copy link
Copy Markdown
Contributor

Summary

  • Pack I, MI, MIM, EP, GI and SM into one scan per TONN layer. Fixed-only layers keep the FFT, and layers with token-dependent gates run one prefix scan across all six types present.
  • Restore outputs in the original slot order, including EP normalization and MIM/SM output gates. Preserve the existing parameters, checkpoints, and per-type circuit API.
  • Add tests for one-kernel dispatch and forward and backward parity, including signed and near-zero decays, masked slots, and non-power-of-two lengths.

Experiment result

The speed harness timed forward, backward, and optimizer steps on arm64 CPU with one PyTorch thread. Both versions used the same tiny TONN model (127,432 parameters), seed-0 initialization and input, batch size 8, 25 warm-up steps, and 150 timed steps. Each context used three interleaved baseline and batched runs. Retrieval and generation were disabled.

Context Baseline tokens/s, runs 1–3 Batched tokens/s, runs 1–3 Median gain
128 90,796.4 / 87,576.3 / 91,180.8 98,600.5 / 100,599.8 / 95,848.5 8.6%
512 108,847.8 / 103,317.1 / 108,780.7 112,845.2 / 114,195.5 / 113,147.3 4.0%

A separate parity check against the archived implementation used seeds 0 and 1 with all six running-sum types in a single layer. Maximum absolute differences were 4.77e-7 for outputs and 1.16e-9 for input and parameter gradients.

Reproduction

Run with the PR code checked out and the same Python environment for both versions.

export OMP_NUM_THREADS=1
scan_bench=$(mktemp -d)
scan_feature=$PWD
mkdir -p "$scan_bench/baseline"
git fetch https://github.com/man-coding-j/ExeaLM.git main
git archive 335e24c exealm | tar -x -C "$scan_bench/baseline"
for scan_seq in 128 512; do
  for scan_run in 1 2 3; do
    for scan_dir in "$scan_bench/baseline" "$scan_feature"; do
      (
        cd "$scan_dir" || exit
        python -m exealm.eval.speed --preset tiny --models tonn --batch 8 --seq "$scan_seq" --steps 150 --warmup 25 --device cpu --no_generation
      ) || exit
    done
  done
done

Validation

The full local suite reported 259 passed in 78.28 seconds with no failures or skips.

OMP_NUM_THREADS=1 python -m pytest -q -ra

@AvnehSBhatia
AvnehSBhatia merged commit c452de8 into exea-labs:main Nov 22, 2026
1 check 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