Skip to main content

tsne-h2pack: High-Performance t-SNE with H2Pack Acceleration

Python 3.8+ License: MIT

A high-performance, sklearn-compatible implementation of t-SNE with H2Pack acceleration for large-scale dimensionality reduction.


Features

  • Drop-in sklearn replacement: Same API as sklearn.manifold.TSNE
  • Fast on large datasets: the repulsive forces are computed in O(N) with an H² matrix (H2Pack). On the same k-NN graph and P matrix, and at matched embedding quality, the optimization phase is 2.0–3.4× faster than FIt-SNE on one thread and 4.3–8.8× faster on eight (Zheng 10x, 50K–1M points; see benchmarks/results/REPORT.md)
  • Multiple k-NN methods: PyNNDescent (default), exact, ball tree, FAISS, and Annoy; or pass your own k-NN graph with metric='precomputed'
  • Validated at scale: 1M points in 2.5 minutes end-to-end (k-NN included) on an 8-core laptop
  • Native performance: OpenMP parallelization on Linux and macOS

Quick Start

Installation

pip install tsne-h2pack

Binary wheels are published for Linux x86-64 (manylinux) and macOS Apple Silicon (macOS 14+), CPython 3.9–3.13. On other platforms pip builds from the source distribution, which needs a C compiler and OpenBLAS — see Prerequisites.

The GitHub repository is not public yet; the complete C and Python source is in the source distribution (pip download --no-binary :all: --no-deps tsne-h2pack). To install from a source checkout:

git clone --recursive https://github.com/xinxing02/tsne-h2pack-python.git
cd tsne-h2pack-python
pip install .

Basic Usage

from tsne_h2pack import TSNE
import numpy as np

# Generate sample data
X = np.random.randn(1000, 50)

# Same API as sklearn
tsne = TSNE(n_components=2, perplexity=30, random_state=42)
Y = tsne.fit_transform(X)

print(f"Embedding shape: {Y.shape}")

Advanced Usage

Large Datasets

from tsne_h2pack import TSNE

# For large datasets (>50K samples)
tsne = TSNE(
    n_components=2,
    perplexity=30,
    method='h2pack',         # Use H2Pack acceleration
    knn_method='pynndescent', # Fast approximate k-NN
    n_jobs=8,                # Use 8 CPU cores
    verbose=1
)

Y = tsne.fit_transform(X_large)

k-NN Methods

Choose the best k-NN method for your dataset size:

# Small datasets (<5K): exact k-NN
tsne = TSNE(knn_method='exact', n_jobs=4)

# Medium datasets (5K-50K): PyNNDescent (default)
tsne = TSNE(knn_method='pynndescent')

# Large datasets (>50K): FAISS
tsne = TSNE(knn_method='faiss')

Available k-NN methods:

  • 'pynndescent' - Fast approximate (default, ~96% accuracy)
  • 'exact' - sklearn brute-force (100% accurate, slow)
  • 'balltree' - sklearn ball tree (100% accurate, medium speed)
  • 'faiss' - Facebook FAISS (very fast approximate)
  • 'annoy' - Spotify Annoy (memory-efficient approximate)

Install optional k-NN methods as extras:

pip install 'tsne-h2pack[knn]'           # All methods
pip install 'tsne-h2pack[pynndescent]'   # Or a single method
pip install 'tsne-h2pack[faiss]'
pip install 'tsne-h2pack[annoy]'

(From a source checkout, replace tsne-h2pack with ..) Below 10,000 samples the default 'pynndescent' falls back to exact brute-force search automatically.


Parameters

All sklearn.manifold.TSNE parameters are supported:

TSNE(
    n_components=2,          # Output dimensions
    perplexity=30.0,         # Balance local/global structure
    early_exaggeration=12.0, # Exaggeration factor for the first 250 iterations
    learning_rate='auto',    # 'auto' = max(n_samples / 12, 200), or a float
    max_iter=1000,           # Maximum iterations
    random_state=None,       # Random seed
    init='random',           # Initialization ('random' only)
    metric='euclidean',      # 'euclidean', or 'precomputed' (sparse k-NN distances)
    method='h2pack',         # 'h2pack' or 'exact'
    n_jobs=None,             # Number of parallel jobs
    knn_method='pynndescent', # k-NN method (see above)
    verbose=0                # Verbosity level
)

metric='precomputed' takes a SciPy sparse matrix of k-NN distances (as sklearn.manifold.TSNE does) and skips the neighbor search, so several runs or several libraries can share one graph. Each row needs more than perplexity neighbors; 3 * perplexity is the usual choice.

H2Pack-specific parameters:

  • h2_tol (float, default=1e-2): relative accuracy of the H² approximation of the repulsive kernel. The default matches FIt-SNE's embedding quality (KL divergence, neighbor preservation); tighter tolerances cost time without measurable gain.
  • h2_rebuild_freq (int, default=3): the H² matrix is rebuilt every this many iterations after early exaggeration; the repulsive force is reused in between. 2 is slightly more accurate and slower; 6 and above is visibly less accurate.
  • h2_rebuild_freq_early (int, default=10): rebuild frequency during early exaggeration.
  • h2_leaf_size (int, default=100): points per leaf of the H² tree. Only for tuning experiments; the default was chosen for the low rank (~10) of the kernel at h2_tol=1e-2.

Installation Details

Prerequisites

macOS (Apple Silicon):

brew install gcc openblas

Linux:

# Ubuntu/Debian
sudo apt-get install gcc libopenblas-dev liblapack-dev liblapacke-dev

# RHEL/CentOS
sudo yum install gcc openblas-devel lapack-devel

Windows: Not supported. Use WSL2 (Windows Subsystem for Linux).

Building from Source

git clone --recursive https://github.com/xinxing02/tsne-h2pack-python.git
cd tsne-h2pack-python
pip install .

If you cloned without --recursive, fetch the H2Pack submodule:

git submodule update --init --recursive

Platform Support

Platform Status Notes
Linux ✅ Fully supported Recommended for production
macOS (Apple Silicon) ✅ Fully supported Requires Homebrew GCC
macOS (Intel) ❌ Not supported Use v2.x or build on Linux
Windows ❌ Not supported Use WSL2

Troubleshooting

Common Issues

ImportError: No module named 'pynndescent'

pip install pynndescent
# or use exact k-NN: TSNE(knn_method='exact')

macOS: Build fails

brew install gcc openblas

Backend not available

pip install --force-reinstall --no-deps .

For more issues, see docs/TROUBLESHOOTING.md.


Documentation


For Package Maintainers

Building Distribution Packages

# Using automated build script
./build_package.sh

# Or manual build
python -m build

Publishing to PyPI

See docs/PACKAGING_GUIDE.md for the full release workflow.


Examples

See the examples/ directory:

# Basic demo (configurable via --n-samples)
python examples/basic_example.py

# Full MNIST (60K samples)
python examples/basic_example.py --n-samples 60000

# Benchmark suite (tsne-h2pack vs FIt-SNE vs openTSNE vs UMAP): see benchmarks/README.md
python benchmarks/sweep.py --dry-run

Citation & License

Citation

If you use tsne-h2pack in your research, please cite:

@software{tsne_h2pack,
  title = {tsne-h2pack: High-Performance t-SNE with H2Pack Acceleration},
  author = {Xing, Xin},
  year = {2026},
  url = {https://github.com/xinxing02/tsne-h2pack-python}
}

And the H2Pack library:

@article{huang2020toms,
    title = { {H2Pack}: High-performance \textit{{H}} $^{\textrm{2}}$ Matrix Package for Kernel Matrices Using the Proxy Point Method },
    journal = {ACM Transactions on Mathematical Software},
    author = {Huang, Hua and Xing, Xin and Chow, Edmond},
    year = {2020},
    month = {Dec},
    volume = {47},
    pages = {1--29},
    doi = {10.1145/3412850},
    issn = {0098-3500, 1557-7295},
    number = {1},
}

License

MIT License - see LICENSE file for details.


Version: 3.1.0 Status: Production-ready (PyPI release pending)

Release files for tsne-h2pack 3.1.0

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

Source distribution (sdist)

Source distribution for tsne-h2pack 3.1.0
File Size Uploaded
tsne_h2pack-3.1.0.tar.gz 269.2 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for tsne-h2pack 3.1.0
File
tsne_h2pack-3.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
tsne_h2pack-3.1.0-cp313-cp313-macosx_14_0_arm64.whl CPython 3.13 CPython 3.13 macOS 14.0+ ARM64 Details
tsne_h2pack-3.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
tsne_h2pack-3.1.0-cp312-cp312-macosx_14_0_arm64.whl CPython 3.12 CPython 3.12 macOS 14.0+ ARM64 Details
tsne_h2pack-3.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
tsne_h2pack-3.1.0-cp311-cp311-macosx_14_0_arm64.whl CPython 3.11 CPython 3.11 macOS 14.0+ ARM64 Details
tsne_h2pack-3.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
tsne_h2pack-3.1.0-cp310-cp310-macosx_14_0_arm64.whl CPython 3.10 CPython 3.10 macOS 14.0+ ARM64 Details
tsne_h2pack-3.1.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
tsne_h2pack-3.1.0-cp39-cp39-macosx_14_0_arm64.whl CPython 3.9 CPython 3.9 macOS 14.0+ ARM64 Details

Total release size: 131.1 MB

Release files / tsne_h2pack-3.1.0.tar.gz

Download URL tsne_h2pack-3.1.0.tar.gz
Size 269.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c3327c987485964a124f4be1798eb1799b5c61e137ed2680486244d848c4b15c
BLAKE2b-256 checksum
How to use checksums
95b888b537da1727e91b7799a2de306b7d06042ebcecaafbcaaaee60bc1ec38c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / tsne_h2pack-3.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL tsne_h2pack-3.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 17.4 MB
Tags CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
29a3d5055bcf4b330cb252ca07a0490940e403c9aaadeccd6d059cae4b0e0b2b
BLAKE2b-256 checksum
How to use checksums
27228dc1e3a4ba576557347b15fdef65ec96e1771e753167ffb5e977905a6193
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / tsne_h2pack-3.1.0-cp313-cp313-macosx_14_0_arm64.whl

Download URL tsne_h2pack-3.1.0-cp313-cp313-macosx_14_0_arm64.whl
Size 8.8 MB
Tags CPython 3.13 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
9f8a9b7c4e2db29c5c23c2e32e06c5399f306c0808442262a8c997f2d03b6531
BLAKE2b-256 checksum
How to use checksums
836a9925b3fb48a8141c33371e1a34bb04e6ca7562497916f60b3b647fec922f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / tsne_h2pack-3.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL tsne_h2pack-3.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 17.4 MB
Tags CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
b4b3f9ca22d1aa906916dc676d4e0b54316d59fc43822288252bc295bcea27e0
BLAKE2b-256 checksum
How to use checksums
2ea312222677b81ebf39204856a7e036fd9d9f820e20c20e23b397554e2f77c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / tsne_h2pack-3.1.0-cp312-cp312-macosx_14_0_arm64.whl

Download URL tsne_h2pack-3.1.0-cp312-cp312-macosx_14_0_arm64.whl
Size 8.8 MB
Tags CPython 3.12 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
439af5acdda26276014da4d20cee6f5d1cd51902ba94a0f86887760467179550
BLAKE2b-256 checksum
How to use checksums
d7e50c81ce971f5aa48cdcc789d643d9100e0631938d20f7f9afd422265ea020
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / tsne_h2pack-3.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL tsne_h2pack-3.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 17.4 MB
Tags CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
1c50d6f83867f18792dda685a25ce4061cde9c9894bff67a63e01e6d8481d033
BLAKE2b-256 checksum
How to use checksums
0a781408f490d5c3e84186a067c4bc162c4b5ed8844cf0dd1aa5911da19fddec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / tsne_h2pack-3.1.0-cp311-cp311-macosx_14_0_arm64.whl

Download URL tsne_h2pack-3.1.0-cp311-cp311-macosx_14_0_arm64.whl
Size 8.8 MB
Tags CPython 3.11 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
7f7020fd05713f4127e1bc1210f6c96e4d3232f3bf6e468ea7462dc3883484cc
BLAKE2b-256 checksum
How to use checksums
ae78ea31baaddbaf7c69d415bcf85a6e1e20b225028ff4677521038b007a31b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / tsne_h2pack-3.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL tsne_h2pack-3.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 17.4 MB
Tags CPython 3.10 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
3cd9b31097311fe937e551091c6fc354e041a04808fd4da70a8d2d79e4c809bf
BLAKE2b-256 checksum
How to use checksums
433426ae4712467a1240385e4544c2bfc1019cee52edbbd43625d042eabf5b91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / tsne_h2pack-3.1.0-cp310-cp310-macosx_14_0_arm64.whl

Download URL tsne_h2pack-3.1.0-cp310-cp310-macosx_14_0_arm64.whl
Size 8.8 MB
Tags CPython 3.10 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
b37f5360b8d404af5bfab23eb15d3202a7e240e2eb7b594fa6ec12d668bfcc88
BLAKE2b-256 checksum
How to use checksums
adade4aec4ae681e097f75b7ad59a65ae4a8ee0e69ef30c2de1e034b123cb628
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / tsne_h2pack-3.1.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL tsne_h2pack-3.1.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 17.4 MB
Tags CPython 3.9 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
dbe80938c0fa4fea2c904d4f226b687ec362dd90691223e990d1c596b6e1c171
BLAKE2b-256 checksum
How to use checksums
52a7cc705e6ee95135d05cf6a139ebd9f8fb8e488ca011a905ff78e9339358a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / tsne_h2pack-3.1.0-cp39-cp39-macosx_14_0_arm64.whl

Download URL tsne_h2pack-3.1.0-cp39-cp39-macosx_14_0_arm64.whl
Size 8.8 MB
Tags CPython 3.9 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
0c17f06509fa7c6646cb93e431316e1f14e0e19cddc6c032a5a6b2ad1d9ddf2a
BLAKE2b-256 checksum
How to use checksums
9fea387e708cf6215d8921427ed3f41ef4b297b57aae0045051e0fab91b3f604
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release history Release notifications | RSS feed

3.1.1

11 release files

This release

3.1.0 This release

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