This error might be raised, if you are trying to select the top k values, while the size of the specified dimension is smaller than k.
Check the shape of losses and make sure it contains more than bs-self.k values.