Repository navigation
Fix sparse embedding normalization for non-default dtypes - #4045
Merged
tomaarsen merged 3 commits intoOct 15, 2026
Merged
Conversation
Member
|
Hello! This fixes a real dtype mismatch. I've merged I've added regression coverage for those numerical errors and the interaction with single-vector normalization. Should be good to go now!
|
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.
Sparse
normalize_embeddingsallocates its row-norm accumulator with the global default dtype, whilevalues**2retains the input dtype.index_add_raises when these differ. For example, this fails with the default float32 setting:Allocate the accumulator from
valuesso its dtype and device match the input. The example then returns sparse rows equivalent to[[0.6, 0.8], [0.0, 0.0]]. This also covers float16/bfloat16 inputs and float32 inputs when the global default is float64.Tests cover four input dtypes with both float32 and float64 defaults, zero rows, and backward gradients. Before the fix, 7 of the 9 new cases failed; afterward, all 28 tests in
tests/util/test_tensor.pypass.Validation (CPU):
python -m pytest tests/util/test_tensor.py -q— 28 passed.The full model and GPU test suites were not run.