Repository navigation
Conversation
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.
When an expert exceeds capacity,
SwitchFeedForwardcurrently writes the dropped token's input into its FFN output.SwitchTransformerLayerthen adds this branch to the original token through its residual connection. Dropped tokens therefore receive an extra normalized-input update (also weighted by the router whenis_scale_prob=True), instead of bypassing the expert computation.Leave capacity-overflow positions at zero in the FFN branch. The outer residual already preserves their representations. Count dropped token indices explicitly without changing pre-capacity routing counts, router probabilities, retained expert outputs or auxiliary load-balancing gradients.
This follows Switch Transformers, Section 2.2, where overflow bypasses expert computation through the residual. The official Mesh TensorFlow implementation also zeros the combine gate when capacity is exceeded.
Validation:
python -m pytest tests/test_switch.py -qgives 10 passed with native package imports and PyTorch 2.14.1 CPU. The original implementation gives 8 failed, 2 passed. Tests compare actual transformer-layer outputs and input/router/expert gradients to an explicit residual-plus-retained-expert reference across zero and partial capacity, both probability-scaling modes, and multiple overflowing experts. Disabling dropping or giving sufficient capacity remains equivalent, and auxiliary router gradients remain active.git diff --checkpasses.The standalone FFN's overflow outputs change from input copies to zeros, matching its role as a residual branch. GPU/distributed execution, model pretraining and the full repository suite were not run. Existing documentation escape-sequence warnings remain unchanged.