Skip to content

Parameters (GPU)

The GPU-specific knobs. Everything else takes the bixverse.params bundles.

params

Parameter bundles for the GPU twins.

One frozen dataclass per parameter bundle the twins take, flat as Rust sees them; ScrubletGpuParams sits in its own module. Twins with no GPU-specific knobs (PCA, SEACells, Bonsai, NMF, SCENIC) take the CPU bundles from bixverse.params; bixverse.params.to_rust serialises both.

ScrubletGpuParams dataclass

ScrubletGpuParams(
    *,
    sim_doublet_ratio: float = 1.5,
    expected_doublet_rate: float = 0.1,
    stdev_doublet_rate: float = 0.02,
    n_bins_histogram: int = 100,
    manual_threshold: float | None = None,
    no_pcs: int = 30,
    normalisation: NormDoubletsDefaults = NormDoubletsDefaults(),
    hvg: HvgDefaults = HvgDefaults(),
    knn_backend: Literal["gpu", "cpu"] = "gpu",
    knn: KnnGpuDefaults | KnnDefaults | None = None,
)

GPU Scrublet doublet detection parameters.

The randomised SVD and the projection of the simulated doublets always run on the GPU; knn_backend picks where the kNN runs. There is no svd_solver: the GPU SVD is always randomised.

Attributes:

Name Type Description
sim_doublet_ratio float

Number of doublets to simulate relative to the observed cells.

expected_doublet_rate float

Expected doublet rate.

stdev_doublet_rate float

Uncertainty in the expected doublet rate.

n_bins_histogram int

Number of histogram bins for the Otsu threshold.

manual_threshold float | None

Manual doublet score threshold; None uses Otsu.

no_pcs int

Number of principal components.

normalisation NormDoubletsDefaults

The normalisation block.

hvg HvgDefaults

The HVG block.

knn_backend Literal['gpu', 'cpu']

"gpu" or "cpu".

knn KnnGpuDefaults | KnnDefaults | None

The kNN block, KnnGpuDefaults for "gpu" and KnnDefaults for "cpu". None is the backend's block with k = 0, which hands the choice of k to Rust.

KnnGpuDefaults dataclass

KnnGpuDefaults(
    *,
    k: int = 15,
    knn_method: Literal[
        "exhaustive", "ivf", "nndescent", "cagra"
    ] = "exhaustive",
    ann_dist: Literal["euclidean", "cosine"] = "euclidean",
    n_list: int | None = None,
    n_probe: int | None = None,
    graph_k: int | None = None,
    k_build: int | None = None,
    n_tree: int | None = None,
    delta: float = 0.001,
    rho: float | None = None,
    refine_knn: int | None = None,
    beam_width: int | None = None,
    max_beam_iters: int | None = None,
    n_entry_points: int | None = None,
)

Default parameters for the GPU nearest neighbour backends

GPU sibling of KnnDefaults. The GPU indices take a different knob set: there is no Annoy and no HNSW on the device, so what survives is exhaustive, IVF and NN-descent.

Attributes:

Name Type Description
k int

Number of neighbours. 0 hands the choice to Rust, which uses sqrt(n_cells) * 0.5 and then adjusts for the simulated doublets.

knn_method Literal['exhaustive', 'ivf', 'nndescent', 'cagra']

The GPU index to use.

ann_dist Literal['euclidean', 'cosine']

Manhattan is not supported by the GPU kernels.

n_list int | None

IVF only. Number of clusters. None gives sqrt(n).

n_probe int | None

IVF only. Clusters to probe. None gives sqrt(n_list).

graph_k int | None

CAGRA only. Node degree of the graph after pruning. None gives 30.

k_build int | None

NN-descent and CAGRA. Working degree of the descent. None gives max(k, floor(1.5 * k)).

n_tree int | None

NN-descent and CAGRA. Trees seeding the descent.

delta float

NN-descent and CAGRA. Termination criterium for the descent.

rho float | None

NN-descent and CAGRA. Sampling rate for the descent.

refine_knn int | None

NN-descent and CAGRA. 2-hop refinement sweeps after the descent. Buys graph quality at a linear cost. None gives 0.

beam_width int | None

CAGRA only, which includes NN-descent on a cross-query. Beam width when querying.

max_beam_iters int | None

CAGRA only, which includes NN-descent on a cross-query. Beam search iterations.

n_entry_points int | None

CAGRA only, which includes NN-descent on a cross-query. Entry points when querying.

NebulaGpuParams dataclass

NebulaGpuParams(
    *,
    nebula_method: Literal["ln", "hl"] = "ln",
    min_sigma: float = 0.0001,
    min_phi: float = 0.0001,
    max_sigma: float = 10.0,
    max_phi: float = 1000.0,
    cutoff_cell: float = 20.0,
    kappa: float = 800.0,
    cpc: float = 0.005,
    mincp: int = 5,
    min_subjects: int = 0,
    eps: float = 1e-06,
    gene_batch_size: int = 1000,
    shrink_dispersion: bool = True,
)

Wrapper function for parameters for GPU NEBULA

GPU counterpart to NebulaParams. Same knobs and defaults, minus reml: the device fit does not implement it. Stage two of NEBULA, the per-gene penalised fits, runs in f32 on the device and is finished on the host in f64, so the estimates sit close to the CPU ones rather than on them.

Attributes:

Name Type Description
nebula_method Literal['ln', 'hl']

Which variant to run. NEBULA downgrades "ln" to "hl" below 30 cells per subject.

min_sigma float

Lower bound on the subject-level overdispersion.

min_phi float

Lower bound on the cell-level overdispersion.

max_sigma float

Upper bound on the subject-level overdispersion.

max_phi float

Upper bound on the cell-level overdispersion.

cutoff_cell float

Refit both overdispersions when the product of the cells per subject and the estimated phi falls below this.

kappa float

Threshold on NEBULA's kappa_obs above which the subject-level overdispersion from stage one is trusted as is.

cpc float

Drop a gene whose mean count per cell is at most this.

mincp int

Drop a gene expressed in fewer than this many cells.

min_subjects int

Drop a gene that fewer than this many subjects express, a subject expressing it when its own mean count per cell is above cpc. cpc and mincp pool every cell, so one subject can carry a gene through on its own. 0 switches the check off, as in the nebula package.

eps float

Absolute stopping tolerance for the optimiser.

gene_batch_size int

Genes read and fitted per batch. Bounds how much of the store is resident at once and changes nothing about the answer, since NEBULA is gene-independent.

shrink_dispersion bool

Shrink the cell-level overdispersions towards an empirical Bayes prior once the sweep is done.

BbknnGpuParams dataclass

BbknnGpuParams(
    *,
    neighbours_within_batch: int = 3,
    set_op_mix_ratio: float = 1.0,
    local_connectivity: float = 1.0,
    trim: int | None = None,
    knn_method: Literal[
        "exhaustive", "ivf", "nndescent", "cagra"
    ] = "exhaustive",
    ann_dist: Literal["euclidean", "cosine"] = "euclidean",
    n_list: int | None = None,
    n_probe: int | None = None,
    graph_k: int | None = None,
    k_build: int | None = None,
    n_tree: int | None = None,
    delta: float = 0.001,
    rho: float | None = None,
    refine_knn: int | None = None,
    beam_width: int | None = None,
    max_beam_iters: int | None = None,
    n_entry_points: int | None = None,
)

Wrapper function for the GPU BBKNN parameters

GPU counterpart to BbknnParams. Same BBKNN knobs, but the kNN block is the GPU one, see KnnGpuDefaults.

Attributes:

Name Type Description
neighbours_within_batch int

Number of neighbours to consider per batch.

set_op_mix_ratio float

Mixing ratio between union (1.0) and intersection (0.0).

local_connectivity float

UMAP connectivity computation parameter, how many nearest neighbours of each cell are assumed to be fully connected.

trim int | None

Trim the neighbours of each cell to these many top connectivities. May help with population independence and improve the tidiness of clustering. If None, it defaults to 10 * neighbours_within_batch * n_batches, as in the reference implementation.

knn_method Literal['exhaustive', 'ivf', 'nndescent', 'cagra']

The GPU index to use.

ann_dist Literal['euclidean', 'cosine']

Manhattan is not supported by the GPU kernels.

n_list int | None

IVF only. Number of clusters. None gives sqrt(n).

n_probe int | None

IVF only. Clusters to probe. None gives sqrt(n_list).

graph_k int | None

CAGRA only. Node degree of the graph after pruning. None gives 30.

k_build int | None

NN-descent and CAGRA. Working degree of the descent. None gives max(k, floor(1.5 * k)).

n_tree int | None

NN-descent and CAGRA. Trees seeding the descent.

delta float

NN-descent and CAGRA. Termination criterium for the descent.

rho float | None

NN-descent and CAGRA. Sampling rate for the descent.

refine_knn int | None

NN-descent and CAGRA. 2-hop refinement sweeps after the descent. Buys graph quality at a linear cost. None gives 0.

beam_width int | None

CAGRA only, which includes NN-descent on a cross-query. Beam width when querying.

max_beam_iters int | None

CAGRA only, which includes NN-descent on a cross-query. Beam search iterations.

n_entry_points int | None

CAGRA only, which includes NN-descent on a cross-query. Entry points when querying.

FastClusterGpuParams dataclass

FastClusterGpuParams(
    *,
    n_centroids: int | None = None,
    k_means_algorithm: Literal[
        "emeans", "lloyd"
    ] = "emeans",
    e_means_epochs: float | None = None,
    k_means_iter: int = 50,
    k_means_init: str | None = None,
    fixed: bool = True,
    quantise: bool = False,
    dist: Literal["euclidean", "cosine"] = "euclidean",
    cell_mediated: bool = False,
    n_anchors: int = 5,
    centroid_k: int = 15,
    knn_sym: Literal["snn", "umap", "knn"] = "snn",
    snn_similarity: Literal["jaccard", "rank"] = "jaccard",
    pruning: float = 0.0625,
    rescue: bool = True,
    local_connectivity: float = 1.0,
    mix_ratio: float = 1.0,
    binary: bool = False,
    algorithm: Literal["louvain", "leiden"] = "louvain",
    n_iterations: int | None = None,
    beta: float = 0.01,
    min_gain: float = 0.0,
    local_moving: Literal["queue", "coloured"]
    | None = None,
    node_order: Literal["bfs", "shuffle"] | None = None,
    multi_level: bool = True,
    max_evals: int = 10,
)

Default parameters for GPU fast clustering

GPU counterpart to FastClusterParams. Fast clustering coarsens the cells with k-means, builds a graph over the centroids and runs Louvain or Leiden on it. The community of each centroid is handed back to its cells. Only the k-means (and the cell-mediated top-m search) run on the GPU. The mini-batch k-means knobs are gone: the GPU runs e-means or full-batch Lloyd's.

Attributes:

Name Type Description
n_centroids int | None

Number of k-means centroids. If None, defaults to floor(4 * sqrt(n_cells)).

k_means_algorithm Literal['emeans', 'lloyd']

"emeans" or "lloyd".

e_means_epochs float | None

e-means only. Passes over the data; None for the default.

k_means_iter int

Lloyd's only. Maximum number of k-means iterations.

k_means_init str | None

Lloyd's only. Initialisation method. One of "random", "parallel" or "plusplus". If None, picked on the Rust side based on the number of centroids.

fixed bool

Shall k-means run for a fixed number of iterations, without checking for convergence. wgpu only; MLX always runs every iteration.

quantise bool

Shall the data buffer be held at fp16 on the GPU. Halves the buffer and helps when the assignment kernels are memory bound. wgpu only.

dist Literal['euclidean', 'cosine']

Distance for the k-means and the centroid graph.

cell_mediated bool

Shall the cell-mediated centroid graph from Secuer be built instead of the kNN graph on the centroids. Centroids are then linked by the cells that sit near both, so two centroids that are close in space but have no cells between them stay apart. If True, centroid_k and centroid_graph are ignored.

n_anchors int

Number of nearest centroids each cell links to in the cell- mediated graph. Only used if cell_mediated = True.

centroid_k int

Neighbours per centroid in the exact centroid kNN. Only used if cell_mediated = False.

knn_sym Literal['snn', 'umap', 'knn']

How to symmetrise the kNN into a graph. Clustering resolutions do not carry over between the methods: the "umap" and "knn" graphs only hold kNN pairs, the sNN graph also links cells that share neighbours and prunes weak edges. The same resolution can give more or fewer communities depending on the data, so retune it when switching.

snn_similarity Literal['jaccard', 'rank']

"snn" only. "jaccard" weighs an edge by the Jaccard index of the two (self-inclusive) neighbour sets. "rank" takes the shared neighbour with the lowest combined rank, so closer shared neighbours give heavier edges. Both are scaled to [0, 1].

pruning float

"snn" only. Edges below this weight are dropped. For the Jaccard weight a threshold p keeps pairs that share at least a fraction 2p / (1 + p) of their (self-inclusive) neighbourhoods, rounded up to whole cells, so the same value means the same thing at any k. The default asks for about 12%, i.e. 2 of 16 shared cells at k = 15, in line with Seurat's 1/15. Avoid a threshold that equals one of the discrete weights exactly, or float rounding decides whether the edge survives.

rescue bool

"snn" only. Reconnect the small components that pruning cuts off via their strongest sNN edge, so they do not turn up as tiny clusters.

local_connectivity float

"umap" only. Number of nearest neighbours assumed to be fully connected, as in umap-learn.

mix_ratio float

"umap" only. 1 is the fuzzy union of the directed kNN memberships, 0 the fuzzy intersection (umap-learn's set_op_mix_ratio).

binary bool

"knn" only. If True, every edge weighs 1. Otherwise mutual neighbours weigh 2 and one-sided ones 1.

algorithm Literal['louvain', 'leiden']

Community detection on the centroid graph.

n_iterations int | None

Number of iterations of the community detection. A negative value iterates until stable. If None, the bixverse default for the chosen algorithm.

beta float

Leiden only. Randomness of the refinement step.

min_gain float

With a negative n_iterations, also stop once an iteration gains no more than this in modularity.

local_moving Literal['queue', 'coloured'] | None

"queue" is Traag's sequential queue. "coloured" moves the nodes of one colour class in parallel, which only kicks in on larger levels of the graph. None is "queue" for Leiden and "coloured" for Louvain.

node_order Literal['bfs', 'shuffle'] | None

Visit order of the queue, "bfs" (sweep in BFS order from a random start) or "shuffle" (as igraph). None is "bfs" for Leiden and "shuffle" for Louvain.

multi_level bool

Shall the communities be aggregated and refined in levels.

max_evals int

Cap on the node evaluations per local moving phase, in units of the number of nodes.

FastmnnGpuParams dataclass

FastmnnGpuParams(
    *,
    ndist: float = 3.0,
    cos_norm: bool = True,
    k: int = 20,
    knn_method: Literal[
        "exhaustive", "ivf", "nndescent", "cagra"
    ] = "exhaustive",
    ann_dist: Literal["euclidean", "cosine"] = "cosine",
    n_list: int | None = None,
    n_probe: int | None = None,
    graph_k: int | None = None,
    k_build: int | None = None,
    n_tree: int | None = None,
    delta: float = 0.001,
    rho: float | None = None,
    refine_knn: int | None = None,
    beam_width: int | None = None,
    max_beam_iters: int | None = None,
    n_entry_points: int | None = None,
)

Wrapper function for the GPU fastMNN parameters

GPU counterpart to FastmnnParams. Same fastMNN knobs minus the PCA ones, since the GPU path corrects the PCA already stored in the object. The kNN block is the GPU one, see KnnGpuDefaults, with k and ann_dist defaulting to the CPU values.

Attributes:

Name Type Description
ndist float

Number of median distances for the tricube kernel bandwidth.

cos_norm bool

Apply cosine normalisation before computing distances.

k int

Number of neighbours. 0 hands the choice to Rust, which uses sqrt(n_cells) * 0.5 and then adjusts for the simulated doublets.

knn_method Literal['exhaustive', 'ivf', 'nndescent', 'cagra']

The GPU index to use.

ann_dist Literal['euclidean', 'cosine']

Manhattan is not supported by the GPU kernels.

n_list int | None

IVF only. Number of clusters. None gives sqrt(n).

n_probe int | None

IVF only. Clusters to probe. None gives sqrt(n_list).

graph_k int | None

CAGRA only. Node degree of the graph after pruning. None gives 30.

k_build int | None

NN-descent and CAGRA. Working degree of the descent. None gives max(k, floor(1.5 * k)).

n_tree int | None

NN-descent and CAGRA. Trees seeding the descent.

delta float

NN-descent and CAGRA. Termination criterium for the descent.

rho float | None

NN-descent and CAGRA. Sampling rate for the descent.

refine_knn int | None

NN-descent and CAGRA. 2-hop refinement sweeps after the descent. Buys graph quality at a linear cost. None gives 0.

beam_width int | None

CAGRA only, which includes NN-descent on a cross-query. Beam width when querying.

max_beam_iters int | None

CAGRA only, which includes NN-descent on a cross-query. Beam search iterations.

n_entry_points int | None

CAGRA only, which includes NN-descent on a cross-query. Entry points when querying.

HarmonyV2GpuParams dataclass

HarmonyV2GpuParams(
    *,
    k: int | None = None,
    sigma: tuple[float, ...] = (0.1,),
    theta: tuple[float, ...] = (2.0,),
    lambda_: tuple[float, ...] = (1.0,),
    max_iter_kmeans: int = 4,
    max_iter_harmony: int = 10,
    epsilon_kmeans: float = 0.001,
    epsilon_harmony: float = 0.01,
    window_size: int = 3,
    alpha: float = 0.2,
    tau: float = 0.0,
    batch_proportion_cutoff: float = 1e-05,
    use_dynamic_lambda: bool = True,
    k_means_algorithm: Literal[
        "emeans", "lloyd"
    ] = "emeans",
    e_means_epochs: float | None = None,
    k_means_iter: int = 10,
    k_means_init: str | None = None,
    fixed: bool = True,
    quantise: bool = False,
)

Default parameters for Harmony v2 GPU batch correction

Attributes:

Name Type Description
k int | None

Number of clusters for k-means clustering. If not provided, it will be automatically determined as min(round(N / 30), 100).

sigma tuple[float, ...]

Per-cluster diversity weights. Either a single value (broadcast to all clusters) or a vector of length k.

theta tuple[float, ...]

Per-variable diversity penalty. Must be a single value; only one batch covariate is supported on the GPU path.

lambda_ tuple[float, ...]

Ridge regression penalty for the linear model. Typically a single value. Ignored when use_dynamic_lambda = True.

max_iter_kmeans int

Maximum number of k-means Jacobi sweeps per Harmony round.

max_iter_harmony int

Maximum number of Harmony outer iterations.

epsilon_kmeans float

Convergence threshold for k-means clustering.

epsilon_harmony float

Convergence threshold for Harmony.

window_size int

Number of previous iterations to consider when checking convergence.

alpha float

Scaling factor for dynamic lambda estimation. Must be in (0, 1). Only relevant when use_dynamic_lambda = True.

tau float

Scaling factor for theta based on batch size. A value of 0 disables batch-size scaling of theta.

batch_proportion_cutoff float

Cutoff for pruning batches with small proportions during ridge regression.

use_dynamic_lambda bool

If True, lambda is estimated dynamically per cluster instead of using the fixed lambda value.

k_means_algorithm Literal['emeans', 'lloyd']

"emeans" or "lloyd", for the initial centroids.

e_means_epochs float | None

e-means only. Passes over the data; None for the default.

k_means_iter int

Lloyd's only. Maximum number of k-means iterations for the initial centroid computation.

k_means_init str | None

Lloyd's only. Initialisation strategy for k-means.

fixed bool

Lloyd's only. If True, run all k_means_iter iterations without a convergence check, as harmony2's initial k-means does.

quantise bool

If True, quantises intermediate values to f16 during k-means.