Skip to content

Embeddings (GPU)

The CPU twin is bixverse.embed.

embed

GPU UMAP, densMAP, t-SNE and PHATE.

The work runs in the manifolds_rs GPU estimators (UMAPGpu, DensMAPGpu, TSNEGpu, PHATEGpu); inputs, slots and stamps are handled exactly as in bixverse.embed, which runs the same code with the CPU estimators. The *_defaults() builders return an estimator set to the defaults the functions here use. There is no GPU den-SNE.

>>> bixverse_gpu.graph.find_neighbours(sc)
>>> umap(sc)

umap_defaults

umap_defaults() -> UMAPGpu

GPU UMAP set to the defaults of umap.

n_epochs=None is 500 under the default "adam_gpu".

densmap_defaults

densmap_defaults() -> DensMAPGpu

GPU densMAP set to the defaults of densmap.

tsne_defaults

tsne_defaults() -> TSNEGpu

GPU t-SNE set to the defaults of tsne: perplexity 20, the GPU three-kernel FFT optimiser and an IVF kNN.

phate_defaults

phate_defaults() -> PHATEGpu

GPU PHATE set to the defaults of phate: the CPU settings with an NN-Descent GPU kNN. The diffusion and the MDS stay on the CPU.

umap

umap(
    sc: ScOrMc,
    *,
    use_knn: bool = True,
    embd_to_use: str = "pca",
    slot_name: str = "umap",
    no_embd_to_use: int | None = None,
    modality: Modality = "rna",
    params: UMAPGpu | None = None,
) -> None

GPU UMAP.

With use_knn the cached kNN is reused and only the optimisation runs on the GPU; without one cached, a warning and a GPU search.

Parameters:

Name Type Description Default
sc ScOrMc

The experiment.

required
use_knn bool

Reuse the cached kNN.

True
embd_to_use str

The input embedding, "pca" or a name in sc.cache.embeddings.

'pca'
slot_name str

The name in sc.cache.embeddings to write.

'umap'
no_embd_to_use int | None

Number of leading dimensions to use. None for all.

None
modality Modality

The kNN and the slot: "rna", or "adt" / "atac" / "wnn" on a SingleCellsMultiModal.

'rna'
params UMAPGpu | None

The estimator. None is umap_defaults().

None

Raises:

Type Description
ValueError

If the embedding or the kNN is stale, the embedding is absent, or slot_name is reserved.

tsne

tsne(
    sc: ScOrMc,
    *,
    use_knn: bool = False,
    embd_to_use: str = "pca",
    slot_name: str = "tsne",
    no_embd_to_use: int | None = None,
    modality: Modality = "rna",
    params: TSNEGpu | None = None,
) -> None

GPU t-SNE.

approx="fft_3k_gpu" (the default) runs the optimiser on the GPU in fp32; the CPU approximations keep it on the CPU with only the kNN on the GPU.

Parameters:

Name Type Description Default
sc ScOrMc

The experiment.

required
use_knn bool

Reuse the cached kNN.

False
embd_to_use str

The input embedding.

'pca'
slot_name str

The name in sc.cache.embeddings to write.

'tsne'
no_embd_to_use int | None

Number of leading dimensions to use. None for all.

None
modality Modality

The kNN and the slot: "rna", or "adt" / "atac" / "wnn" on a SingleCellsMultiModal.

'rna'
params TSNEGpu | None

The estimator. None is tsne_defaults().

None

Raises:

Type Description
ValueError

As umap.

densmap

densmap(
    sc: ScOrMc,
    *,
    use_knn: bool = True,
    embd_to_use: str = "pca",
    slot_name: str = "densmap",
    no_embd_to_use: int | None = None,
    modality: Modality = "rna",
    params: DensMAPGpu | None = None,
) -> None

GPU densMAP.

Inputs are handled as in umap; with "adam_gpu" the density term runs on the device alongside the rest of the update.

Parameters:

Name Type Description Default
sc ScOrMc

The experiment.

required
use_knn bool

Reuse the cached kNN.

True
embd_to_use str

The input embedding.

'pca'
slot_name str

The name in sc.cache.embeddings to write.

'densmap'
no_embd_to_use int | None

Number of leading dimensions to use. None for all.

None
modality Modality

The kNN and the slot: "rna", or "adt" / "atac" / "wnn" on a SingleCellsMultiModal.

'rna'
params DensMAPGpu | None

The estimator. None is densmap_defaults().

None

Raises:

Type Description
ValueError

As umap.

References

Narayan, Berger & Cho, Nat Biotechnol, 2021.

phate

phate(
    sc: ScOrMc,
    *,
    use_knn: bool = False,
    embd_to_use: str = "pca",
    slot_name: str = "phate",
    no_embd_to_use: int | None = None,
    modality: Modality = "rna",
    params: PHATEGpu | None = None,
) -> None

GPU PHATE.

The kNN search and, for spectral landmarks, the randomised SVD and k-means run on the device; the diffusion and the MDS on the CPU. Off by default, use_knn reuses the cached kNN, which should then be 6k + 5 wide, as in bixverse.embed.phate.

Parameters:

Name Type Description Default
sc ScOrMc

The experiment.

required
use_knn bool

Reuse the cached kNN.

False
embd_to_use str

The input embedding.

'pca'
slot_name str

The name in sc.cache.embeddings to write.

'phate'
no_embd_to_use int | None

Number of leading dimensions to use. None for all.

None
modality Modality

The kNN and the slot: "rna", or "adt" / "atac" / "wnn" on a SingleCellsMultiModal.

'rna'
params PHATEGpu | None

The estimator. None is phate_defaults().

None

Raises:

Type Description
ValueError

As umap.

References

Moon, et al., Nat Biotechnol, 2019.