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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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 torchid-0.5.1.tar.gz.
File metadata
- Download URL: torchid-0.5.1.tar.gz
- Upload date:
- Size: 31.8 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
921674c2577fb8b029a1cfc6786cd1c034ad06b57d0401691c0f7de37dc6cde0
|
|
| MD5 |
2fd3e9621870151469f692c131330f83
|
|
| BLAKE2b-256 |
4873eaadf9cb4e58ad0d99051ef82cfd92ba0d8fa1e99053eb262ee166040959
|
File details
Details for the file torchid-0.5.1-py3-none-any.whl.
File metadata
- Download URL: torchid-0.5.1-py3-none-any.whl
- Upload date:
- Size: 40.6 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c1f44fc1775bf893e4995defdc870b11f70c66faa9ddb1f9ef51733d28c7b0f
|
|
| MD5 |
fab983ff660af6806b8b98b252e333f9
|
|
| BLAKE2b-256 |
75c756cf78a3a5f0fa6a0022c5c9c0b8e50660d49bb61e5bbe07e9e1e39e1ecb
|