Repository navigation
Quantize ICLabel with a frozen parity gate - #383
neuromechanist merged 13 commits into
Conversation
There was a problem hiding this comment.
An organization admin can add extra usage credits at claude.ai/admin-settings/usage.
Once credits are available, reopen this pull request to trigger a review.
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
|
🤖 Additional integration verification: I ran the Phase 5 Pyodide/ONNX Runtime Web runner with the Phase 6 packaged weight-only int8 artifact supplied directly. The browser output was shape [32, 7], with 100% top-1 label agreement and 100% keep/reject agreement against the float32 native reference under the existing thresholds. The probability values are intentionally not claimed float32-allclose after quantization (maximum absolute difference 0.0079035). |
ebab410 to
12955a3
Compare
Decision policy: int8 is eligible to become the default everywhere only if the fixed parity gate passes; otherwise float32 remains the default. The fixed gate is at least 95% top-1 agreement and at least 99% keep-or-reject agreement. Feature extraction, input normalization, softmax, the seven-class set, existing eeg_icflag thresholds, and tolerances are unchanged. The float32 network is not retrained; both weight-only int8 and calibrated int8 are required; low-rank and distillation are omitted; no browser-only claim is made.
Frozen provenance: evaluation was frozen before quantized evaluation from public NEMAR dataset on002680 v1.0.0, DOI 10.82901/nemar.on002680.v1.0.0, CC0, with OpenNeuro source ds002680 v1.2.0, DOI 10.18112/openneuro.ds002680.v1.2.0. Source identifiers are https://api.nemar.org/datasets/on002680, https://nemar.org/dataset/on002680, https://github.com/nemarDatasets/on002680, and the official OpenNeuro S3 mirror template https://s3.amazonaws.com/openneuro.org/ds002680/{source_path}. The immutable NEMAR mirror commit is 5cadd7d16423313a103ba24655e31245ffba8a4e and the NEMAR zarr source commit is a8ebb56c5a2c4ee91a30d0b0d29072b3271d4384e. Evaluation uses sub-002 through sub-008; calibration uses sub-009 through sub-015; each uses ses-01, run-1, one complete recording, and all 31 zero-based ICA components, giving 217 components per split. Selection was declared before quantized evaluation, retained every component, and used no float32 label, confidence, threshold, or quantization filtering. Seven subjects per split and subject-disjoint splits mitigate selection bias. A pre-freeze audit found sampled ses-01 and ses-02 signal matrices identical, so session identity was not treated as independence. Raw size and MD5 checksums are committed per recording in tools/iclabel/evaluation_manifest.json. Evaluation archive SHA256 is dbb2c0cc063d29ab2e8e59fafb0f474df780a458ac17be9d4732abc0233c8b44; calibration archive SHA256 is 6d5ee10f8c2a62a336e3f6372e686e00adad763b3d25f92728477a025e7d9c77.
Artifacts: preserved float32 reference tools/iclabel/artifacts/iclabel_float32.onnx is 11,626,631 bytes, SHA256 1f16c67ebdbd8e6a30759ab628b61b693a0c4011e35a20e538acbebc1d4ebce4. Weight-only int8 tools/iclabel/artifacts/iclabel_int8_weight_only.onnx is 2,932,897 bytes, SHA256 8c0537d299e8776eef418d4a697547ad0b317902d656f69f64440169c564d8e3. Calibrated int8 tools/iclabel/artifacts/iclabel_int8_calibrated.onnx is 2,970,375 bytes, SHA256 a98fdb146678daf74c588898e477ff3af234a682449a1712e4e96d3af01974b1. The package src/eegprep/plugins/ICLabel/iclabel.onnx is the weight-only artifact. The reproducible float32 export path remains tools/iclabel/export_iclabel_onnx.py. The wheel measured 16,049,522 bytes before promotion and 7,811,822 bytes after promotion; hashes are recorded in the implementation handoff.
Measured parity on the same frozen evaluation archive, n=217: the float32 self-reference is 217/217 top-1 and 217/217 keep-or-reject, both 1.0. Weight-only int8 is 217/217 top-1 and 217/217 keep-or-reject, both 1.0, and passes. Per teacher class: Brain 18/18 1.0, Muscle 1/1 1.0, Eye 5/5 1.0, Heart 0/0 not measurable, Line Noise 0/0 not measurable, Channel Noise 0/0 not measurable, Other 193/193 1.0. Calibrated int8 is 213/217 top-1, 0.9815668202764977, and 217/217 keep-or-reject, 1.0, and passes. Per teacher class: Brain 15/18 0.8333333333333334, Muscle 1/1 1.0, Eye 5/5 1.0, Heart 0/0 not measurable, Line Noise 0/0 not measurable, Channel Noise 0/0 not measurable, Other 192/193 0.9948186528497409. Weight-only is shipped because it is smaller and has exact agreement on this frozen set.
Tests and gates: UV_CACHE_DIR=/private/tmp/eegprep-phase6-uv-cache ./pre-commit.py passed on 15 staged files. uv run --no-sync ruff check . passed. uv run --no-sync ruff format --check . reported 695 files already formatted. uv run --no-sync ty check reported only the known unchanged optional oct2py unresolved import in src/eegprep/functions/adminfunc/eeglabcompat.py. The focused quantization test passed 8 tests. The combined command EEGPREP_SKIP_MATLAB=1 MNE_DONTWRITE_HOME=true MPLCONFIGDIR=/private/tmp/eegprep-phase6-mplconfig XDG_CACHE_HOME=/private/tmp/eegprep-phase6-cache UV_CACHE_DIR=/private/tmp/eegprep-phase6-uv-cache uv run --no-sync pytest -q tests/test_iclabel.py tests/test_iclabel_quantization.py tests/test_public_api_examples.py passed 26 tests and skipped 1 MATLAB test.
Limitations: MATLAB parity was not runnable locally, so its existing test was skipped without changing tolerances. Feature generation emitted existing divide-by-zero, overflow, and invalid matmul warnings for some recordings, but every saved feature array passed finite-value validation. The NEMAR object for calibration subject sub-015 returned HTTP 403; the official OpenNeuro S3 mirror supplied the object and its manifest size and MD5 matched. Phase 5 async API work is untouched.
Fixes #379