GPU-accelerated intrinsic dimension estimators in PyTorch. A port of scikit-dimension with batched/vectorized implementations and CUDA support.
Why
scikit-dimension is the reference library for intrinsic dimension (ID) estimation but
is CPU-only and relies heavily on per-point Python loops. torchid re-implements every
estimator using batched torch ops so the same methods run 100–2700× faster on GPU
(measured on an NVIDIA H100, see BENCHMARKS.md) while producing outputs
that match the reference library within documented tolerances.
Install
pip install "torchid[cpu]" # CPU-only (faiss-cpu)
pip install "torchid[cuda]" # GPU-enabled (faiss-cuda-cu128, manylinux_2_28+)
For a CUDA-capable install, also pick the PyTorch wheel that matches your driver, e.g.:
pip install torch --index-url https://download.pytorch.org/whl/cu128
pip install "torchid[cuda]"
For running parity tests against scikit-dimension from a clone:
uv sync --extra cpu --group validation
Usage
import torch
from torchid.estimators import lPCA
X = torch.randn(10_000, 50, device="cuda")
est = lPCA().fit(X)
print(est.dimension_)
Differentiable ID as a loss
The estimator classes are fit-only; torchid.functional provides differentiable
functional forms (mle_id, twonn_id, mom_id, mada_id, pr_id) and
torchid.losses wraps them into a minimizable objective — maximizing ID becomes
minimizing the ratio 1 - id/D:
from torchid import IntrinsicDimensionLoss
id_loss = IntrinsicDimensionLoss(method="twonn", mode="maximize")
feats = encoder(batch) # (B, D), requires_grad
loss = task_loss + 0.1 * id_loss(feats) # regularize toward higher ID
loss.backward()
Neighbor selection comes from a no-grad kNN; distances are recomputed differentiably from the gathered coordinates, so gradients are exact away from neighbor-order ties. See the API reference for details.
Metadata
Release files for torchid 0.5.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| torchid-0.5.1.tar.gz | 31.8 kB | Without provenance | Details for torchid-0.5.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| torchid-0.5.1-py3-none-any.whl | Python 3 | none | any | Details for torchid-0.5.1-py3-none-any.whl |
Total release size: 72.5 kB
Release files / torchid-0.5.1.tar.gz
| Download URL | torchid-0.5.1.tar.gz |
|---|---|
| Size | 31.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
921674c2577fb8b029a1cfc6786cd1c034ad06b57d0401691c0f7de37dc6cde0
|
|
BLAKE2b-256 checksum How to use checksums |
4873eaadf9cb4e58ad0d99051ef82cfd92ba0d8fa1e99053eb262ee166040959
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.8 {"installer":{"name":"uv","version":"0.12.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / torchid-0.5.1-py3-none-any.whl
| Download URL | torchid-0.5.1-py3-none-any.whl |
|---|---|
| Size | 40.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0c1f44fc1775bf893e4995defdc870b11f70c66faa9ddb1f9ef51733d28c7b0f
|
|
BLAKE2b-256 checksum How to use checksums |
75c756cf78a3a5f0fa6a0022c5c9c0b8e50660d49bb61e5bbe07e9e1e39e1ecb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.8 {"installer":{"name":"uv","version":"0.12.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for torchid 0.5.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.