def shard_xattn_t2i(images, captions, caplens, **kwargs):
            """
            Computer pairwise t2i image-caption distance with locality sharding
            """
            shard_size = kwargs.get('shard_size', 1000)
            n_im_shard = int((len(images) - 1) / shard_size + 1)
            n_cap_shard = int((len(captions) - 1) / shard_size + 1)

            d = np.zeros((len(images), len(captions)))
            for i in range(n_im_shard):
                im_start, im_end = shard_size * i, min(shard_size * (i + 1), len(images))
                for j in range(n_cap_shard):
                    cap_start, cap_end = shard_size * j, min(shard_size * (j + 1), len(captions))
                    im = torch.FloatTensor(images[im_start:im_end])
                    s = torch.FloatTensor(captions[cap_start:cap_end])
                    l = caplens[cap_start:cap_end].tolist()

                    if torch.cuda.is_available():
                        im = im.cuda()
                        s = s.cuda()

                    sim = xattn_score_t2i(im, s, l, **kwargs)
                    d[im_start:im_end, cap_start:cap_end] = sim.cpu().detach().numpy()
            return d

            Computer pairwise t2i image-caption distance with locality sharding
            
torchmm/models/retrieval/scan.py