Skip to main content
Loss of provenance

A previous release had provenance metadata, but this release does not. View details.

glmpca-fast

PyPI License: GPL v3+

Fast GLM-PCA (Generalised Linear Model PCA) for non-Gaussian count data — Rust core with optional PyTorch GPU backend.

Implements the algorithm of:

Townes, F. W., Hicks, S. C., Aryee, M. J., & Irizarry, R. A. (2019). "Feature selection and dimension reduction for single-cell RNA-Seq based on a multinomial model." Genome Biology, 20:295. doi:10.1186/s13059-019-1861-6

Why

Standard PCA assumes Gaussian + homoscedastic noise — wrong likelihood for count data (RNA-seq UMIs, genotype dosages, etc.). GLM-PCA fits the proper Poisson / Multinomial / Bernoulli / NB likelihood, capturing the mean–variance relationship inside the model.

The reference implementation (willtownes/glmpca-py) is CPU-only Python. glmpca-fast ports the algorithm to:

  • Rust (rayon-parallel coordinate-block Newton) — ~13× faster than glmpca-py on a single CPU.
  • PyTorch with batched torch.linalg.solve — ~290× faster on a modern GPU (RTX A6000) per fit.

Install

# Add to a project (preferred)
uv add glmpca-fast                    # CPU (Rust + numpy)
uv add "glmpca-fast[torch]"           # + GPU (PyTorch)

# Or install into the active environment
uv pip install glmpca-fast
uv pip install "glmpca-fast[torch]"

# Or run a one-shot script
uv tool run --from glmpca-fast python -c "from glmpca_fast import fit_poisson; ..."

With pip

pip install glmpca-fast              # CPU
pip install "glmpca-fast[torch]"     # + GPU

Quick start

import numpy as np
from glmpca_fast import fit_poisson

# Synthetic Binomial(2, p) genotype dosage matrix
rng = np.random.default_rng(0)
N, M, L = 2504, 200, 8
p = rng.uniform(0.05, 0.5, M)
Y = rng.binomial(2, p, size=(N, M)).astype(np.float32)

# Rust backend (default, CPU)
res = fit_poisson(Y, L=L, max_iter=100)
print(res["factors"].shape)         # (2504, 8)
print(res["loadings"].shape)        # (200, 8)
print(res["deviance"][-1])          # final deviance
print(res["backend"])               # 'rust'

# Auto backend — picks GPU if CUDA is available
res = fit_poisson(Y, L=L, backend="auto")
print(res["backend"])               # 'torch' if CUDA, else 'rust'

# Explicit GPU device
res = fit_poisson(Y, L=L, backend="torch", device="cuda:0")

API

fit_poisson(
    Y,                   # (n_samples, n_features) non-negative counts
    L,                   # latent dim, >= 2
    max_iter=100,
    tol=1e-4,            # relative deviance tolerance
    penalty=1.0,         # L2 ridge on factors and loadings
    seed=42,
    backend="rust",      # 'rust' | 'torch' | 'auto'
    device=None,         # torch device override (e.g. 'cuda:1')
) -> dict
# returns: factors, loadings, intercept, deviance, n_iter, backend

project_ols(X_held, train_mean, loadings) -> ndarray
# Approximate OLS projection of held-out samples (Pearson-residual approx).

Benchmark

Single gene, 2,504 samples × 200 variants, L=8:

Backend Time / fit Speedup vs glmpca-py
glmpca-py (reference, NumPy) 7.58 s 1×
glmpca-fast (Rust, 11 cores) 0.56 s 13.5×
glmpca-fast (PyTorch, RTX A6000) 0.026 s 290×

Both backends converge to within ~1 % of the reference final deviance (non-convex objective, different random init).

Limitations / scope

  • Currently Poisson family only. Multinomial / NB / Bernoulli branches are planned for v0.2.
  • Newton step uses full update without line-search damping. For degenerate Hessians the implementation falls back to a small gradient step.
  • Held-out projection uses the OLS approximation (not full per-sample IRLS).
  • Built and tested on Linux x86-64 + CUDA 12. Other platforms via source build.

Citation

If you use this package, please cite both the original paper and this software:

@article{Townes2019GLMPCA,
  title   = {Feature selection and dimension reduction for single-cell
             RNA-Seq based on a multinomial model},
  author  = {Townes, F. William and Hicks, Stephanie C. and Aryee,
             Martin J. and Irizarry, Rafael A.},
  journal = {Genome Biology},
  volume  = {20},
  number  = {1},
  pages   = {295},
  year    = {2019},
  doi     = {10.1186/s13059-019-1861-6}
}

@software{glmpca_fast,
  title  = {glmpca-fast: Fast GLM-PCA with Rust and GPU backends},
  author = {zongseung},
  year   = {2026},
  url    = {https://github.com/zongseung/glmpca-fast}
}

License

GPL-3.0-or-later — see LICENSE.

Metadata

Release files for glmpca-fast 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Loss of provenance

These files do not have provenance metadata, despite files in a prior release including this data.

We recommend further investigation before installing these files. View details.

Source distribution (sdist)

Source distribution for glmpca-fast 0.1.2
File Size Uploaded Provenance Actions
glmpca_fast-0.1.2.tar.gz 29.8 kB Without provenance Details for glmpca_fast-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for glmpca-fast 0.1.2
File Interpreter ABI Platform Actions
glmpca_fast-0.1.2-cp313-cp313-manylinux_2_34_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.34+ x86-64 Details for glmpca_fast-0.1.2-cp313-cp313-manylinux_2_34_x86_64.whl

Total release size: 375.0 kB

Release files / glmpca_fast-0.1.2.tar.gz

Loss of provenance

This file belongs to a release without provenance metadata, despite a prior release including this data.

We recommend further investigation before installing this file. View details.

Download URL glmpca_fast-0.1.2.tar.gz
Size 29.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0e69c7b9cbee45d0a69936fa878f38fd6a50303f27b0211644a987a864282ccb
BLAKE2b-256 checksum
How to use checksums
c57094390af06db06165a0311739aff21cb4c0155737aa7acaff77dedefa7642
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.11

Release files / glmpca_fast-0.1.2-cp313-cp313-manylinux_2_34_x86_64.whl

Loss of provenance

This file belongs to a release without provenance metadata, despite a prior release including this data.

We recommend further investigation before installing this file. View details.

Download URL glmpca_fast-0.1.2-cp313-cp313-manylinux_2_34_x86_64.whl
Size 345.2 kB
Tags CPython 3.13 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
ae2d99cbc559dada1d5a6fd305d26c41f46d0dc0f499439c2362a086b4c361c5
BLAKE2b-256 checksum
How to use checksums
db0225e25908e267cdec410cc8c101f202cc2bff71fe45bda42696d82876fcad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.11

Security for glmpca-fast 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Loss of provenance

A previous release of these files had provenance metadata, but this release does not.

While this could reflect a routine change by the project maintainers, it may also indicate that the release files have been compromised.

Release comparison

  • Removed 0.1.0 20 files Partial provenance
  • Added 0.1.2 2 files Without provenance

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page