Use fused attention for SmolLM3#2849
Open
GargiGupta-io wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request integrates fused attention support into the SmolLM3Attention layer by utilizing ops.dot_product_attention when fused_attention_op_available() is true. It also adds comprehensive unit tests in smollm3_backbone_test.py to verify the fused attention execution, its fallback path, and numerical consistency between both implementations. There are no review comments to address, and the changes conform to the repository's guidelines.
GargiGupta-io
marked this pull request as ready for review
July 22, 2026 18:50
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.
Description of the change
SmolLM3's attention layer always uses the eager
einsumand softmax path evenwhen Keras provides a fused dot-product attention operation. This bypasses the
flash-attention path available on supported JAX and PyTorch configurations.
This change follows the existing Qwen3 and Phi3 pattern: use
ops.dot_product_attention()whenfused_attention_op_available()is true,normalize the attention mask for the fused operator, and retain the existing
implementation as the fallback.
Regression tests cover masked and unmasked dispatch, the eager fallback, and
numerical equivalence between both paths.
Reference
Colab Notebook
Not applicable. This change does not add a new API or model.
Validation
6 passed, 2 skipped, 2 subtests passed6 passed, 2 skipped, 2 subtests passed6 passed, 2 skipped, 2 subtests passedtensorflow-textfails thesame way on the unchanged master branch.
Checklist