Repository navigation
Conversation
EmbeddingLayer.seq_len only counted numerical and categorical features, so the shuffle_embeddings permutation of Mambular and MambAttention dropped external-embedding tokens and a feature or the CLS token, and learned_flatten pooling was sized without the CLS token. seq_len now counts external-embedding features too, the new n_tokens attribute matches the length returned by forward(), feature_permutation() shuffles only feature tokens and keeps the CLS token in place, and the pooling architectures size their pooling layers from n_tokens. Fixes #483
With cls_position=0 the old permutation dropped the last feature token and moved the CLS token, not the CLS token itself. EmbeddingLayer now documents seq_len and n_tokens, and the custom-model guide sizes its head from n_tokens. Refs #483
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #483
Problem
EmbeddingLayer.seq_lencounted only numerical and categorical features, and the pooling architectures sizedlearned_flattenfrom their numerical, categorical and external-embedding features. Neither count included the CLS token, andseq_lenalso missed the external-embedding tokens. Two bugs followed:shuffle_embeddings=True(Mambular, MambAttention):x[:, perm, :]used a permutation that was too short. It always dropped the external-embedding tokens, so the model ignoredfit(embeddings=...). Withuse_cls=Trueit dropped the last feature token and moved the CLS token away from position 0 (cls_position=0), or dropped the CLS token itself (cls_position=1).pooling_method="learned_flatten"withuse_cls=True(FTTransformer, Mambular, MambAttention; TabTransformer and TabulaRNN share the sizing code but have nouse_clsconfig field): the pooling layer was sized without the CLS token, so the first forward pass crashed with a shape mismatch.Fix
The token count now has one source of truth in
EmbeddingLayer:seq_lencounts external-embedding features as well, since there is one token per feature.n_tokensattribute equalsseq_lenplus one when a CLS token is used, which is the sequence lengthforward()returns. Both are documented in theEmbeddingLayerdocstring, and the custom-model guide sizes its example head fromn_tokens.feature_permutation()draws the shuffle permutation over all feature tokens and keeps the CLS token at its configured position, so"cls"pooling still reads it.The architectures use them as follows:
embedding_layer.feature_permutation()as theirpermbuffer.embedding_layer.n_tokens. SAINT and AutoInt already counted the CLS token and are unchanged.Compatibility
Models without a CLS token or external embeddings get exactly the same permutation size and pooling layers as before, so their saved artifacts still load. A shuffled Mambular/MambAttention model saved by ≤ 2.1.0 with
use_cls=Trueor external embeddings had a shorterpermbuffer and silently dropped a token. Such a model now fails strict loading and has to be retrained. The model-zoo pages say so.Tests
In
tests/architectures/test_architecture_contracts.py:test_shuffled_embeddings_keep_every_token(Mambular, MambAttention; CLS first, CLS last, external embeddings):permcovers every token returned by the embedding layer and leaves the CLS token in place.test_shuffled_embeddings_use_external_embeddings: the output now changes when the external embeddings change.test_learned_flatten_pooling_counts_cls_token: the five architectures above run a forward pass withuse_cls=Trueandlearned_flattenpooling, with the CLS token in either position. TabTransformer and TabulaRNN getuse_clsset on the config object, since their config classes have no such field.18 of the 20 selected tests fail on
main; the 2 that pass are the existing checkpoint tests. All 20 pass with this change.Docs
docs/model_zoo/stable/mambular.mdandmambattention.mddescribe what the shuffle permutes and add the compatibility note above.shuffle_embeddingsdocstrings inMambularConfigandMambAttentionConfigare updated.feature_permutation()has a NumPy-style docstring, and theEmbeddingLayerdocstring documentsemb_feature_info,seq_lenandn_tokens.docs/core_concepts/custom_models.mdsizes the example head fromembedding_layer.n_tokens, so the example keeps working with a CLS token.Checks
just test: 3254 passed, 46 skipped, 28 xfailed; coverage 91.29%just docs: build succeeded (warnings treated as errors)just check: all hooks passed (ruff, prettier, pyright)