Open aakash-saboo opened 2 years ago
Hi
This error will come when "sort" function is used. "sort" function (in its current definition), will only work when there are NO two elements which are greater than SAME number of elements i.e all the elements in any row of the input matrix is different.
def sort(x):
"""Returns the matrix x where each row is sorted (ascending)."""
xshape = tf.shape(x)
rank = tf.reduce_sum(
tf.cast(tf.expand_dims(x, 2) > tf.expand_dims(x, 1), tf.int32), axis=2)
The sort function was written this way so it runs on TPU. If you just use GPU, you should be able to do with it tf.sort
, which probably doesn't have this problem.
@chentingpc Thank you so much for your response. Yes, tf.sort is working just fine.
But I liked the implementation of the sort
function. Is there any way you can tell me whether this exact implementation was used for TPU or not? If yes, then I am wondering how come this problem did not come on TPU.
Also the function works fine when we work in float64 instead of float32.
Thanks Aakash
This is the code that would run on TPU, and we didn't experience this issue. I wonder if there's any collapsing in the input features that lead to the same numbers in output. If that's the case, you can try to add a tiny bit of random noises in the input that breaks the tie.
@chentingpc Thanks a lot! will try that out.
Hi. Thank you so much for your work and its implementation. I have been trying to evaluate generalized contrastive loss between random normal vectors. The code works for small batches but gives error for large batches (say 100), the last line of the "sort" function (gather function) gives an error saying the index used by the "gather" function is out of bounds
x = tf.gather(x, tf.cast(rank_inv, tf.int32), axis=-1, batch_dims=-1)
the command I use is the followingtraceback: