Fast GLM-PCA (Townes et al. 2019) with Rust core and optional PyTorch GPU backend
Project description
glmpca-fast
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
With uv (recommended)
# 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
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file glmpca_fast-0.1.1.tar.gz.
File metadata
- Download URL: glmpca_fast-0.1.1.tar.gz
- Upload date:
- Size: 17.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cdae02c4d21aa4bfea3127319eedb1ff7b0dcdba53c303936eeb9be1c9967fc1
|
|
| MD5 |
11cdcae4f496ab294a9e5934a4b84655
|
|
| BLAKE2b-256 |
80f1ec52ca3fb9ae43e6737fdc7681b3dbd39f7b5c884da9af9e536ea69a8c14
|
File details
Details for the file glmpca_fast-0.1.1-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: glmpca_fast-0.1.1-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 208.1 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec6efe31240d54df557b27827d0f3cd98f505b372426f41eebfb2046cd096d99
|
|
| MD5 |
255434758721603dea67945e847620e2
|
|
| BLAKE2b-256 |
f86b3f8a47e925068ae9f5fc9370276ba9a9345c8a563bf08cdeafc9ace70d7c
|
File details
Details for the file glmpca_fast-0.1.1-cp313-cp313-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: glmpca_fast-0.1.1-cp313-cp313-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 333.4 kB
- Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1a8a1e5163267767b9e5a7ed3720168400bd1ec94196a1844cdde64fa437c2a
|
|
| MD5 |
22f1dd00557555af457865d892d0e414
|
|
| BLAKE2b-256 |
0d1f9136cd234b90464916bb15ac29301633dd9d1903190432872641041fb849
|
File details
Details for the file glmpca_fast-0.1.1-cp313-cp313-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: glmpca_fast-0.1.1-cp313-cp313-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 312.0 kB
- Tags: CPython 3.13, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c66a81e49944a55085b2e09a3386cc8cee30e0a578c05b9d56fa41b0efb8444b
|
|
| MD5 |
32265cb9f45d4d2f7e00b2acd21a8d93
|
|
| BLAKE2b-256 |
1a05b7ef3d57eb69f666b99ea227cf8778c20a7473e57fd81dac2e60b35c14c1
|
File details
Details for the file glmpca_fast-0.1.1-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: glmpca_fast-0.1.1-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 281.8 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0df67315610c697a3b61e279903c722f86ef552d1cc14d8beab80579e0bf9e2a
|
|
| MD5 |
c8cd39ae6f237fea70ed4b415631c8b9
|
|
| BLAKE2b-256 |
93b5877f85790b327059a27fcfff709e7229f8a17eb0cfe9b6b89e9a80958a46
|
File details
Details for the file glmpca_fast-0.1.1-cp313-cp313-macosx_10_12_x86_64.whl.
File metadata
- Download URL: glmpca_fast-0.1.1-cp313-cp313-macosx_10_12_x86_64.whl
- Upload date:
- Size: 303.2 kB
- Tags: CPython 3.13, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a301404c649bf0bc6ef6d443317a1b925038ad1a948c387b0bfff65f1e55ed98
|
|
| MD5 |
5e8b6523229964b343c3ff5a393b115e
|
|
| BLAKE2b-256 |
bf113b877ee68e8b84419ef3aadcf309678f8dcc488d404d7fd7fb3c0e49b9b7
|
File details
Details for the file glmpca_fast-0.1.1-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: glmpca_fast-0.1.1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 208.2 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a2be3f32271dc544ca279ca645ce744e6c1f8082df8f9afa9dfdbcfe57d149c
|
|
| MD5 |
0936acb28d8c697924e055db615e7c74
|
|
| BLAKE2b-256 |
af73c7c3500ba67a71206de309ba13fbe68d5f56134cd64278d3706bed747522
|
File details
Details for the file glmpca_fast-0.1.1-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: glmpca_fast-0.1.1-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 333.5 kB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84419ab555afbfef4452e497485a8b2298fd5019a6046525f8684616340768f5
|
|
| MD5 |
57e9c7da30be252f0773cdf0cd994d45
|
|
| BLAKE2b-256 |
3ec4d2a064016f3b82ae284f1d86515b0167c9dcce69b2faa29f92fdb7de2aca
|
File details
Details for the file glmpca_fast-0.1.1-cp312-cp312-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: glmpca_fast-0.1.1-cp312-cp312-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 312.1 kB
- Tags: CPython 3.12, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6866d365054e63e0d5e9129a084d5e683881ab15cd5e4d25c2b976081dc78b4
|
|
| MD5 |
c15bdb74ba7e34413a294598df11b253
|
|
| BLAKE2b-256 |
47e96215acf2bf236a5809ea653c7ccdf2df7414ebdafd7fd57a14f507ad4c38
|
File details
Details for the file glmpca_fast-0.1.1-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: glmpca_fast-0.1.1-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 281.9 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76ecf01ff4b5a5cd1a549057236113d43b56eec11717ba357005beaae665ec68
|
|
| MD5 |
fabc85ba746db0c307d5ee7213820d01
|
|
| BLAKE2b-256 |
0d033b7646331324d0acd82a20ea63f7e217a30351aa87b8448819fe05920506
|
File details
Details for the file glmpca_fast-0.1.1-cp312-cp312-macosx_10_12_x86_64.whl.
File metadata
- Download URL: glmpca_fast-0.1.1-cp312-cp312-macosx_10_12_x86_64.whl
- Upload date:
- Size: 303.3 kB
- Tags: CPython 3.12, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64a0d746c783edc6000d06cd65b4c5c555fdcd987869eae681aa56f3be358f0c
|
|
| MD5 |
894ce442c6a6a3615989e8b3f59cd6eb
|
|
| BLAKE2b-256 |
7619cc84a084210f02b2ca7f2a79dff69d1e8bee3e48b46497c939d278d8af79
|
File details
Details for the file glmpca_fast-0.1.1-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: glmpca_fast-0.1.1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 207.3 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b76b8acea85ebee7e4824bce27b55cf3c66785aa95b24269ff0df602c11bf57
|
|
| MD5 |
c682acbf540bd08836a6c358f54a0314
|
|
| BLAKE2b-256 |
b386c99331d4f5c3a43036beb5fa35e2b25c7c7dc7b7bf7ca34c773a86c8995d
|
File details
Details for the file glmpca_fast-0.1.1-cp311-cp311-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: glmpca_fast-0.1.1-cp311-cp311-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 332.5 kB
- Tags: CPython 3.11, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c5dc1f4e799a2cf652f04546803abccca5c20f5162e1c703c30ef0753c465b9
|
|
| MD5 |
a217837a8e778db116e8620e358c71ee
|
|
| BLAKE2b-256 |
ecc0a75a8303ce8da14e4584842b10c84381058626527c18efade967e803bb6c
|
File details
Details for the file glmpca_fast-0.1.1-cp311-cp311-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: glmpca_fast-0.1.1-cp311-cp311-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 312.1 kB
- Tags: CPython 3.11, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c82b070e96725b08cc5892cc53c5635e78df770e8955c140a0ffabceb80389b8
|
|
| MD5 |
a1b130560fd250ba96fa7a23a8eead23
|
|
| BLAKE2b-256 |
7becd7d9bb2d2c5a1dc997f8a2fbc1c8ac591c275b8da78ea016736c485df009
|
File details
Details for the file glmpca_fast-0.1.1-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: glmpca_fast-0.1.1-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 281.7 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0e3aebdfba0cd61993e8072a96afb9d4893d37c21f1f8a489761e2ad56e3cf0
|
|
| MD5 |
8c3ffbfb4a5f2a104e99cbc408319287
|
|
| BLAKE2b-256 |
cb6727a53d0bf0dc96bfc4a524227ee2693399ceaf223a3dcfa11061b15c0439
|
File details
Details for the file glmpca_fast-0.1.1-cp311-cp311-macosx_10_12_x86_64.whl.
File metadata
- Download URL: glmpca_fast-0.1.1-cp311-cp311-macosx_10_12_x86_64.whl
- Upload date:
- Size: 303.0 kB
- Tags: CPython 3.11, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4d8549a515d2cdbafa3272aed5f799922a204ffb4ca1d3b2824f5cbb457b3b2
|
|
| MD5 |
36c198f12068dc6825b3c1610b913deb
|
|
| BLAKE2b-256 |
32cb12bb3eb40ec00f3ef0449523b9fdc84d03a77fc1c419cb54049f349ee468
|
File details
Details for the file glmpca_fast-0.1.1-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: glmpca_fast-0.1.1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 207.4 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d78c010d0ed85d52c8d50785ed967751fd048cf1a90da505bab9b91a4101fc23
|
|
| MD5 |
de8ff233762569304ca7464fa05557bc
|
|
| BLAKE2b-256 |
fc5580ee385c9cbba1a473e2638f39aecb221ee6d93f66299889c004f7434161
|
File details
Details for the file glmpca_fast-0.1.1-cp310-cp310-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: glmpca_fast-0.1.1-cp310-cp310-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 332.6 kB
- Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5add8bf353a8b65d7be74e5a6fb24814f0ce67aa880c621266b67a1f82b76bc6
|
|
| MD5 |
22124c34663291414d3e109a96e86f14
|
|
| BLAKE2b-256 |
f7059d7a2893a42ea3307c873e4668341454c65e26ba0e35ae21203caf7fb88e
|
File details
Details for the file glmpca_fast-0.1.1-cp310-cp310-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: glmpca_fast-0.1.1-cp310-cp310-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 312.2 kB
- Tags: CPython 3.10, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf1693ce86ceffe744be29c072da998818c31022e5d971935beb7307a2d1fb33
|
|
| MD5 |
eeac97b1eb3196d670c8cdbb314725a8
|
|
| BLAKE2b-256 |
9bdc171f3d4cc22d86d8555f715b2b6a5d73257ba05100943a20e210d87473fa
|
File details
Details for the file glmpca_fast-0.1.1-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: glmpca_fast-0.1.1-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 281.6 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76851e43aeff096da57ab51e9dc2aed20c7ca07fb6d0bd3efbea2e96a070dd4b
|
|
| MD5 |
ed5d209d78a3eb89ba49358dc70042a3
|
|
| BLAKE2b-256 |
e7f19b574d817909300bb5631964d34e62c0436856fd076e6211c3153b557289
|
File details
Details for the file glmpca_fast-0.1.1-cp310-cp310-macosx_10_12_x86_64.whl.
File metadata
- Download URL: glmpca_fast-0.1.1-cp310-cp310-macosx_10_12_x86_64.whl
- Upload date:
- Size: 303.2 kB
- Tags: CPython 3.10, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9b76fabc4db556e1bf4fc124c7bd379f26767d08f9c1d20864112d7d4e69134
|
|
| MD5 |
f7a94eeaf6532108ad457cec180e1d25
|
|
| BLAKE2b-256 |
561e1335c4121dc32f045ab9550f98a358877628d741e00c1971e7433ad22fb0
|