Skip to content

[Feature Request] cdist: pairwise distances between two sets of tensors with batch mode #15253

@KovenYu

Description

@KovenYu

Now we've already had F.pdist, which computes pairwise distances between each pair in a single set of vectors.

However, in retrieval problems, we often need to compute the pairwise distances between each pair consisting one sample from a probe/query set and another sample from a gallery/database set, in order to evaluate the performances of a retrieval model.

Specifically, if the database tensor has size N-by-D and the query M-by-D, the tensor returned by a cdist function should have size N-by-M where the (i, j)-th element is the distance between the i-th sample from the database and the j-th sample from the query.

Currently, a plausible way (ok, I use this method because I had no idea about GPU programming to achieve better performance) to do this evaluation is:

  1. transform the tensor to a numpy array: query_np = query.cpu().numpy(), database_np = database.cpu().numpy()
  2. using cdist provided by scipy: dist_matrix = cdist(query_np, database_np)

which is really far from elegent and could not utilize GPU power and thus inefficient. So, could we develop some efficient cdist function which can use GPU, and hopefully act like cdist in scipy?

Metadata

Metadata

Assignees

No one assigned

    Labels

    function requestA request for a new function or the addition of new arguments/modes to an existing function.module: batchingmodule: distance functionstriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions