Repository navigation
[models] Add TFMTokenizer - #1202
bruAristimunha merged 28 commits into
Conversation
|
CI blocker follow-up on the current head:
These changes address the four failures from the last upstream run without adding integration-test skips. Could the workflow be re-run on the current head when convenient? |
|
Reference-fidelity correction on current head
No architecture dimensions or reconstruction path changed; this is a correctness/fidelity cleanup before maintainer review. |
|
EMA robustness follow-up on the current head
This deliberately improves numerical robustness rather than claiming checkpoint parity with the research repository; the tokenizer architecture, VQ objective, straight-through estimator, and checkpoint state schema are unchanged. |
|
VQ gradient audit on the current head: with the straight-through tensor used in both VQ terms, the EMA-only port sent equal-and-opposite gradients into the encoder when |
|
One more VQ-gradient invariant is now explicit on head The released code applies the straight-through estimator before evaluating both VQ MSE terms. If
At the released/default The current port keeps the same scalar objective value but evaluates the codebook term from the detached EMA codebook vector itself. The codebook term is therefore value-only (the codebook stays EMA-only), while the commitment term supplies the encoder gradient. A focused regression now requires nonzero frequency- and temporal-encoder gradients at This is a deliberate library-level correctness fix rather than a checkpoint-parity claim; reconstruction architecture and EMA state remain unchanged. |
|
Pinned official-checkpoint parity is now available for the current PR head Reference: CPU assay results:
Run: https://github.com/lindicaphxag-tech/lindicaphxag-tech/actions/runs/37114458814 The EMA-VQ objective-gradient correction remains an explicitly documented library-level deviation and is intentionally excluded from the reference-parity oracle rather than presented as reference behavior. |
|
@bruAristimunha @julien-gadonneix — this is now at the point where I would value a maintainer pass on the model/API contract rather than further self-hardening. The current head keeps the default |
|
Follow-up on the EMA regression: the failure exposed a real update bug rather than a flaky test. |
d81b940 to
700c3cd
Compare
|
Review-history cleanup only: I squashed the branch to a single commit before maintainer review. The Git tree is unchanged ( |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1202 +/- ##
==========================================
+ Coverage 89.16% 89.19% +0.02%
==========================================
Files 158 159 +1
Lines 19641 19741 +100
==========================================
+ Hits 17513 17607 +94
- Misses 2128 2134 +6 🚀 New features to boost your workflow:
|
Resolved NOTICE.txt docs/whats_new.rst by keeping both entries.
…ts; add pretrained box; outputs unchanged
Conflict in docs/whats_new.rst: rebuilt from master's file plus the TFMTokenizer entry.
The private _EMAVectorQuantizer duplicated EMACodebook. With epsilon=1e-5, no dead-code expiry and no k-means init, EMACodebook is the reference EMA update; the uniform init is kept. Never-selected codes now follow the reference update again. Buffers are renamed (embed, embed_avg, inited); the loading snippet maps the released keys. EMACodebook skips the inited host read when k-means init is off.
bfloat16 and HPU inputs now get their spectrogram in float32 on the CPU. The model ships released weights, so the braindecode#1252 coverage test needs a COMPAT entry (channel-agnostic, 200 Hz).
bruAristimunha
left a comment
There was a problem hiding this comment.
Verified: TFMTokenizer passes master's model contract, integration and pretrained-compat suites, including the new CPU accelerator and low-precision checks, in our CPU test jobs, and its tokens match the authors' code and released checkpoint exactly. Thanks @lindicaphxag-tech for the careful TFM-Tokenizer port!
Reviewer map
Fast path:
braindecode/models/tfm_tokenizer.py— architecture, EMA VQ semantics, STFT/masking/token API;test/unit_tests/models/test_models.py— shape, gradient, EMA-state, config/state and edge-case contracts;Two things are intentionally separated in the implementation:
No paper benchmark reproduction is claimed.
Summary
Adds TFMTokenizer, the self-supervised time-frequency motif tokenizer from Tokenizing Single-Channel EEG with Time-Frequency Motif Learning (ICLR 2026).
Part of #1201.
API contract
forward(X)remains Tensor-valued and returns the reconstructed magnitude spectrogram.tokenize(...)exposes the full SSL payload: reconstruction, token IDs, straight-through quantized embeddings, pre-quantization embeddings, VQ loss, and target spectrogram.Reference and checkpoint fidelity
Reference:
Jathurshan0330/TFM-Tokenizer@2d6da482b16dabbb2ebec808fa9f505fc6f367c4(MIT).Released checkpoint SHA-256:
f7929eed0f8275d08a7e18743fdd188c7ba5b4722151333b4d386ca05b84d6d9.Pinned CPU parity assay:
Evidence:
Deliberate library-level corrections
Two training-state issues are intentionally not presented as reference parity:
commitment_cost=1.0. This port keeps the same scalar objective value, but makes the EMA codebook term value-only and leaves the commitment term responsible for the encoder gradient. The codebook remains EMA-only.Both behaviors have focused regressions.
Braindecode integration
EEGModuleMixinintegration and model registry entry;torch.compileintegration coverage.TorchScript is not claimed because the existing third-party
LinearAttentionTransformerdependency uses a variadic forward signature that is not scriptable; the integration suite skips that check for this model only.Claim boundary
This PR claims released-checkpoint parity for the tokenizer's mapped state, forward/token outputs, internal audited representations, and reconstruction gradients. It does not claim reproduction of the paper's pretraining/downstream benchmark metrics. Upstream workflows currently require maintainer approval for this fork, so no current-head upstream CI pass is claimed.