import tensorflow as tf

    # with tf.control_dependencies([p]):
    pred_flat = tf.reshape(pred, [-1])
    tgt_flat = tf.reshape(tgt, [-1])
    batch = tf.stack([pred_flat, tgt_flat], 1)
    num_sam = tools.shape(batch)[0]
    index = tf.range(num_sam)
    divider = tf.constant(resample, dtype=tf.float32)

    def sample_compute(cur_loss, 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 = cur_loss + compute_contra_loss(pred1, pred2, tgt1, tgt2)
        print(loss)
        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])
