Skip to content

Measure ICLabel at 4 bits and keep int8 as the default - #398

Closed
neuromechanist wants to merge 4 commits into
epic/324-pyodide-browserfrom
feature/iclabel-int4-feasibility
Closed

neuromechanist wants to merge 4 commits into
epic/324-pyodide-browserfrom
feature/iclabel-int4-feasibility

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Sep 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Answers whether ICLabel is worth shipping at 4 bits, on measurements rather than
arithmetic. The short version: 4-bit works end to end, including in the browser,
and it should still not replace int8.

This does not change the packaged artifact. iclabel.onnx is still the
weight-only int8 network from #383, and a test now pins that.

Can ONNX Runtime Web execute 4-bit ICLabel today

Yes. This was the leg most likely to fail, so it was checked first.

The network is 10 Conv nodes and nothing else: no MatMul, no Gemm. So
MatMulNBits, which is where most 4-bit ONNX tooling lives, has nothing to
attach to. The portable representation is a uint4 initializer behind a blocked
DequantizeLinear feeding the existing float Conv, and the pinned
onnxruntime-web 1.30.0 WebAssembly build runs exactly that:

  • runs with graphOptimizationLevel: "disabled", so the 4-bit kernel really
    executes rather than being constant-folded away at session load
  • runs in headless Chrome 153 on the frozen evaluation set, and the output is
    byte-identical to the Node WebAssembly run of the same artifact
  • tools/iclabel/check_iclabel_ort_web.mjs reproduces the check

Measured sizes, and the 3-4 MB target

artifact wheel
float32 11,626,631 B 16,053,342 B
int8 weight-only (shipped) 2,932,897 B 7,815,630 B
int4 blocked (this PR) 1,931,262 B 7,077,996 B

Naive arithmetic was right and the 3-4 MB target was not. All 2,903,817
parameters are Conv weights, with no biases of consequence, no embeddings and no
unquantizable layers to dilute the ratio, so int8 lands at a clean 3.96x and
int4 at 6.02x. int8 already sits under the 3-4 MB target; 4 bits overshoots
it to 1.9 MB rather than reaching it.

ICLabel is no longer what makes the wheel big

Worth knowing before anyone reaches for 4 bits again. Compressed members of the
current int8 wheel:

group compressed
eegprep/resources/dipfit 3,840,620 B
eegprep/plugins/ICLabel 2,579,065 B
everything else ~1,295,000 B

int8 already moved ICLabel below the DIPFIT resources. If the goal is a smaller
browser payload rather than a smaller ICLabel, the 3.8 MB of DIPFIT head-model
data is the larger lever, and 4-bit ICLabel cannot reach a 3-4 MB wheel on its
own from either side.

Parity

On the frozen 217-component subject-disjoint set from #379, int4 matches the
float32 teacher on 100% of top-1 labels and 100% of keep-or-reject decisions,
clearing the same gate int8 clears.

Pooled over every real component available (466: both frozen splits plus the
EEGLAB tutorial recording), int4 and int8 are identical at the label level,
per class:

class n int8 int4
Brain 48 0.9792 0.9792
Muscle 6 1.0000 1.0000
Eye 11 1.0000 1.0000
Line Noise 6 1.0000 1.0000
Other 395 1.0000 1.0000
Heart 0 not measured not measured
Channel Noise 0 not measured not measured

Heart and Channel Noise do not occur in any component of the available
recordings, so neither int8 nor int4 has ever been measured on them. That gap
predates this PR and is stated rather than papered over.

int4 does perturb the probabilities about 3.4x more than int8: maximum absolute
change of 4.5e-2 against 1.3e-2. The float32 teacher's top-1-to-top-2 margin has
a 1st percentile of 0.0218, so int4's worst case could in principle reach 16 of
466 components where int8 could reach 6. One component actually flips, the same
one, for both.

Recommendation: keep int8

  • the size target is already met, and 4 bits buys 0.74 MB of a 7.8 MB wheel
  • it costs compatibility: int4 needs opset 21, and onnxruntime 1.18 refuses the
    graph with MLDataType for: tensor(uint4) is not currently registered, so the
    floor in pyproject.toml would have to move to 1.19
  • it buys no speed: 868 augmented rows took 3,214 ms at int4 against 3,043 ms at
    float32 under ONNX Runtime Web, because weight-only 4-bit dequantizes to float
    before the same float Conv

It is worth revisiting if the browser download budget ever forces the ICLabel
artifact below 2.5 MB, since that is a threshold int8 cannot reach and int4 can.

Testing

tests/test_iclabel_int4.py, six tests, all passing alongside the existing
tests/test_iclabel_quantization.py suite (16 passing together). The parity gate
was verified to actually fail on a deliberately 2-bit-damaged model (90.78%
top-1), so a pass means something.

Pre-existing unrelated failures on this machine: the three test_iclabel.py and
test_iclabel_features.py cases that need a MATLAB runtime.

Builds a blocked uint4 Conv-weight artifact from the frozen float32 export
and scores it against the same frozen evaluation set the int8 path uses.
The check script exercises an artifact under the pinned onnxruntime-web
build, since native onnxruntime support is not evidence for the browser.
1,931,262 bytes against 2,932,897 for the shipped int8 artifact, passing
the same frozen gate at 100% top-1 and 100% keep-or-reject agreement.
Kept beside the int8 candidates so the report's hashes stay checkable.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, reopen this pull request to trigger a review.

@claude

claude Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 0s —— View job


I'll analyze this and get back to you.

@neuromechanist

Copy link
Copy Markdown
Member Author

On the two classes nobody has measured

Recording this so the gap is documented rather than rediscovered.

Heart and Channel Noise have zero components in every recording this repository
can reach: both frozen splits of ds002680 (31 channels, 434 components) and the
EEGLAB tutorial set (32 components). So the per-class table above has five real
rows and two empty ones, and that is true of the int8 artifact that already
ships, not just of int4.

I tried to close it inside this task and did not. I pulled four 63-channel
resting-state recordings from the public ds008768 (Parkinson's rest, CC0) on the
theory that higher density and eyes-open rest would surface cardiac and
single-channel components. eeg_runica did not converge on 63 channels in a
reasonable time even cut to 120 s at 250 Hz and 128 steps, so no components came
out of it. That is an ICA cost problem, not a quantization result, and it is
orthogonal to this PR.

What can be said without those components is a bound rather than a measurement.
Across the 466 real components that do exist, int4 moves the probability mass
assigned to Heart by at most 2.6e-2 and to Channel Noise by at most 8.6e-3
(int8: 5.2e-3 and 3.9e-3). A component of either class would therefore have to
sit within roughly twice that of its runner-up for int4 to relabel it. That is a
bound, not evidence, and it should not be quoted as parity.

What would make 4 bits worth revisiting

A single checkable threshold: if the ICLabel artifact ever has to fit under
2.5 MB.
int8 is 2,932,897 bytes and cannot get there without a different
method; int4 is 1,931,262 bytes and clears it with room. Short of that trigger,
the 1.0 MB saving does not pay for an opset-21 floor, an onnxruntime 1.19
minimum, and a 3.4x larger probability perturbation.

The second thing that would change the answer is a real Heart or Channel Noise
component appearing in the evaluation set and int8 passing on it while int4
fails. Until such components exist, neither artifact has been tested there.

Skips where onnxruntime predates 1.19, which refuses uint4 tensors
outright, so an older runtime names the floor instead of failing obscurely.
@neuromechanist
neuromechanist force-pushed the feature/iclabel-int4-feasibility branch from d620ce1 to d89a2fc Compare September 20, 2026 23:43
@neuromechanist
neuromechanist force-pushed the feature/iclabel-int4-feasibility branch from d89a2fc to ec39ce6 Compare September 20, 2026 23:44
@neuromechanist

Copy link
Copy Markdown
Member Author

Closing: 4-bit is shelved. It works, and there is not enough to gain.

The full verdict, the size table, the parity numbers and a checkable threshold for revisiting are recorded on #379 (#379 (comment)) rather than here, so they outlive this branch. Short version: int8 at 2,932,897 B already meets the size target this was aimed at, int4 reaches 1,931,262 B but costs an opset-21 floor and an onnxruntime 1.19 minimum and buys no speed. Revisit if the artifact ever has to fit under 2.5 MB.

Nothing shipped changed here: src/eegprep/plugins/ICLabel/iclabel.onnx is byte-identical to the base branch and this PR was additive throughout.

One piece of this may be worth salvaging separately from 4-bit. tools/iclabel/check_iclabel_ort_web.mjs verifies that ONNX Runtime Web produces byte-identical output to the native Node run for a given artifact. That is browser-parity infrastructure for whatever ICLabel ships, not a 4-bit tool, and it is the only thing here that demonstrates the shipped int8 model behaves identically in a browser. If Phase 5's browser path wants a standing check, that script is the start of one. Say so and it can be reopened as its own small pull request against the epic branch, without any of the quantization code.

The branch feature/iclabel-int4-feasibility is left in place rather than deleted, so the report JSON and the quantization script remain reachable if the 2.5 MB threshold is ever crossed.

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