Skip to content

voronoi

Functions:

Name Description
compute_voronoi_l2_distance

Compute the Voronoi l2 distance is defined as half the distance between the embedding and the nearest neighbor in the embedding table.

compute_voronoi_l2_distance_percentile

Compute the Voronoi l2 distance is defined as the distance between the embedding and the nearest neighbor in the embedding table.

compute_voronoi_l2_distance

compute_voronoi_l2_distance(
    embeddings_table_matrix: Tensor,
) -> torch.Tensor

Compute the Voronoi l2 distance is defined as half the distance between the embedding and the nearest neighbor in the embedding table.

Parameters:

Name Type Description Default

embeddings_table_matrix

Tensor

The weight of the embedding table.

required

Returns:

Type Description
torch.Tensor

The Voronoi l2 distance matrix.

Added in version v1.4.0. To facilitate the computation of the Voronoi l2 distance.

compute_voronoi_l2_distance_percentile

compute_voronoi_l2_distance_percentile(
    embeddings_table_matrix: Tensor, percentile: float
) -> torch.Tensor

Compute the Voronoi l2 distance is defined as the distance between the embedding and the nearest neighbor in the embedding table.

Due to the memory intensive nature of calculating the quantiles of all the embeddings, we compute the distances on the GPU and

then transfer the distances to the CPU for quantile calculation.

Parameters:

Name Type Description Default

embeddings_table_matrix

Tensor

The weight of the embedding table.

required

percentile

float

The percentile to compute.

required

Returns:

Type Description
torch.Tensor

The Voronoi l2 distance at the given percentile.

Added in version v1.4.0. To facilitate the computation of the Voronoi l2 distance.