Fix ValueError in _divide_sub_cluster_jobs with numpy >= 1.24#314
Open
yashparekh261 wants to merge 1 commit intoamzn:mainlinefrom
Open
Fix ValueError in _divide_sub_cluster_jobs with numpy >= 1.24#314yashparekh261 wants to merge 1 commit intoamzn:mainlinefrom
yashparekh261 wants to merge 1 commit intoamzn:mainlinefrom
Conversation
…ays in _divide_sub_cluster_jobs np.array_split fails on numpy>=1.24 when given a list of arrays with different lengths (ragged/inhomogeneous sequences). The internal call to np.asarray raises ValueError because it cannot create a regular ndarray from arrays of different sizes. Replace with plain Python list partitioning (divmod-based splitting) which naturally handles variable-length sub-tree assignment arrays and preserves the same split semantics including empty-group padding when num_machines > num_sub_trees.
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.
Fix
ValueErrorin_divide_sub_cluster_jobswith numpy >= 1.24Issue
DistClustering._divide_sub_cluster_jobsinpecos/distributed/xmc/base.pycrashes during distributed training with numpy >= 1.24:sub_tree_assign_arr_listis a list of arrays with different lengths (one per meta-tree leaf cluster, where each cluster has a different number of labels).np.array_splitinternally callsnp.asarray()on this list, which in numpy < 1.24 silently created an object array, but in numpy >= 1.24 raisesValueErrorfor ragged/inhomogeneous sequences.This is triggered in distributed XMC training when
nr_splitsproduces leaf clusters of unequal size, which is the common case for real-world data.Description of changes
Replaced
np.array_split(sub_tree_assign_arr_list, num_machine)with a pure Python divmod-based list partitioning that:nitems intonum_machinegroups as evenly as possible, with the firstmgroups getting one extra item (wheren = k * num_machine + m)len(sub_tree_assign_arr_list) < num_machinelist[list]directly instead of converting through numpy arrays and back via.tolist()Testing
No test changes required — existing
test_dist_clusteringpasses with the fix.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.