bittensor-subnet-template
bittensor-subnet-template copied to clipboard
process_weights_for_netuid breaks when there is only 1 non-zero weight
Edge case in weight setting that only occurs when there's a single non-zero weight:
- In
weight_utils.process_weights_for_netuid
, non-zero weight indices are extracted by callingnp.argwhere(weights > 0).squeeze()
. (line 142)- In the case where there is only a single weight with a non-zero value, this returns an array scalar (which is an unsized object, i.e. you cannot call
len
on it).
- In the case where there is only a single weight with a non-zero value, this returns an array scalar (which is an unsized object, i.e. you cannot call
- The resulting variable
non_zero_weight_idx
is used to index intouids
andweights
, which again produces an array scaler (lines 143-144) - Downstream code calls
len
onnon_zero_weights
, which fails in the case of it being an array scaler (line 168)
Toy recreation of the issue: