fix(index): return zero balance factor when no vector is assigned - #9407
Open
LuciferYang wants to merge 3 commits into
Open
LuciferYang wants to merge 3 commits into
LuciferYang wants to merge 3 commits into
Conversation
compute_cluster_sizes returned 0/0 = NaN when every membership was None, and correctness of the next iteration silently depended on Rust's f32::min returning the non-NaN operand. Guard explicitly. Assisted-by: GLM-5.3
…an-balance-factor
Contributor
Author
|
The rustdoc job is failing on main as well, not because of this change: run 35372502724 on main (83d0084) fails with 'error: could not document lance' from rust/lance/src/io/exec/knn.rs:563, a private intra-doc link to Self::try_new_batch under -D rustdoc::private-intra-doc-links. This PR touches rust/lance-index/src/vector/kmeans.rs only. |
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.
Closes #9406
compute_cluster_sizesdivided the largest cluster's loss by that cluster's size, which is zero when every membership isNone, so it returned NaN. The caller'sadjusted_balance_factor.min(params.balance_factor)then dropped the NaN because that is whatf32::mindoes, leaving the next iteration's factor decided by an accident rather than by the code. It now returns 0.0 for that case, which says what the situation is: nothing was assigned, so there is nothing to balance.The only inputs that reach it are batches where every vector is non-finite, which the index build path filters out before training; direct
KMeansusers can still hit it.How was this patch tested?
test_compute_cluster_sizes_without_any_assignmentcalls the function with an all-Nonemembership and asserts the factor is 0.0 and finite, and that the cluster sizes were reset. Removing the guard returns NaN and fails the assertion.