import tensorflow as tf

        return (loss, i + 1)

    # def sample_compute(i):
    #     batch1 = tf.gather(batch, tf.random.shuffle(index))
    #     batch2 = tf.gather(batch, tf.random.shuffle(index))
    #     pred1 = tf.slice(batch1, [0, 0], [num_sam, 1])
    #     pred2 = tf.slice(batch2, [0, 0], [num_sam, 1])
    #     tgt1 = tf.slice(batch1, [0, 1], [num_sam, 1])
    #     tgt2 = tf.slice(batch2, [0, 1], [num_sam, 1])
    #     loss = compute_contra_loss(pred1, pred2, tgt1, tgt2)
    #     print(loss)
    #     return loss

    i = tf.constant(0)
    loss = tf.constant(0.)
    final_loss = tf.while_loop(lambda l, i: i < resample, sample_compute, [loss, i])[0]
    # final_loss = tf.scan(sample_compute, tf.range(resample), loss)[-1]
    # final_loss = tf.map_fn(fn=lambda inp: sample_compute(inp), elems= tf.range(resample), dtype=tf.float32, parallel_iterations=1)
    # print('final', final_loss)
    # final_loss = loss
    avg_loss = tf.reduce_mean(final_loss) / divider
    # p = tf.print('cur_loss', [final_loss, avg_loss])
    # with tf.control_dependencies([p]):
    #     avg_loss = tf.identity(avg_loss)
    # print(final_loss, avg_loss)
    # p = tf.print('debug loss ', [final_loss, avg_loss])
    # with tf.control_dependencies([p]):
    #     avg_loss = 1. * avg_loss
    # print(avg_loss)
    # exit()
