Skip to main content

torchid — intrinsic dimension estimation

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 --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

torchid-0.5.0.tar.gz (29.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torchid-0.5.0-py3-none-any.whl (38.4 kB view details)

Uploaded Python 3

File details

Details for the file torchid-0.5.0.tar.gz.

File metadata

  • Download URL: torchid-0.5.0.tar.gz
  • Upload date:
  • Size: 29.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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

Hashes for torchid-0.5.0.tar.gz
Algorithm Hash digest
SHA256 23b71156bf47350977fa00b50a6bc58a475844507c6e71028d1b5bd15f7d79d2
MD5 9f53d3429c2dae41863dc61fd73c4d70
BLAKE2b-256 4196da49369b0f38155e6e132d9a632f39b380fb478c8341cda152d0520c7699

See more details on using hashes here.

File details

Details for the file torchid-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: torchid-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 38.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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

Hashes for torchid-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7d025796f337467f1ca672864d6bd0201f417ccfcc08632ae65fcb0c697f5676
MD5 58975ab5333435dc656805870703673f
BLAKE2b-256 e7cbebd04b5e6701eeab44152a9dbc9b774474ff556bd7759769f566b8ac7944

See more details on using hashes here.

Release history Release notifications | RSS feed

0.5.1

2 files

This release

0.5.0 This release

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

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