Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedding Projector: perform consistent knn calculation #6274

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions tensorboard/plugins/projector/vz_projector/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export interface DataPoint {
[key: string]: number;
};
}
const IS_FIREFOX = navigator.userAgent.toLowerCase().indexOf('firefox') >= 0;

/** Maximum sample size for each projection type. */
export const TSNE_SAMPLE_SIZE = 10000;
export const UMAP_SAMPLE_SIZE = 5000;
Expand Down Expand Up @@ -470,23 +470,15 @@ export class DataSet {
.map((neighbors) => neighbors.slice(0, nNeighbors))
);
} else {
const knnGpuEnabled = (await util.hasWebGLSupport()) && !IS_FIREFOX;
const numKnnNeighborsToCompute = Math.max(
nNeighbors,
MIN_NUM_KNN_NEIGHBORS
);
const result = await (knnGpuEnabled
? knn.findKNNGPUCosDistNorm(
data,
numKnnNeighborsToCompute,
(d) => d.vector
)
: knn.findKNN(
data,
numKnnNeighborsToCompute,
(d) => d.vector,
(a, b) => vector.cosDistNorm(a, b)
));
const result = await knn.findKNNGPUCosDistNorm(
data,
numKnnNeighborsToCompute,
(d) => d.vector
);
this.nearest = result;
return Promise.resolve(
result.map((neighbors) => neighbors.slice(0, nNeighbors))
Expand Down