tsne-h2pack: High-Performance t-SNE with H2Pack Acceleration
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 ath2_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
- CHANGELOG.md - Version history
- CLAUDE.md - Development guide (technical details)
- docs/TROUBLESHOOTING.md - Detailed troubleshooting guide
- docs/PACKAGING_GUIDE.md - Package maintainer guide
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.1 Status: Production-ready (PyPI release pending)
Release files for tsne-h2pack 3.1.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 | |
|---|---|---|---|
| tsne_h2pack-3.1.1.tar.gz | 271.2 kB | Details |
Built distributions (wheels)
Total release size: 131.1 MB
Release files / tsne_h2pack-3.1.1.tar.gz
| Download URL | tsne_h2pack-3.1.1.tar.gz |
|---|---|
| Size | 271.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
24b45055221ddfbc8cf43b769a61d611e07f9ed5c1fbae672e0c57b9298cd119
|
|
BLAKE2b-256 checksum How to use checksums |
2c51445fc401c7b41880c5dbeccba11f548d285c7ebbdb69559ff6483e676bb6
|
| 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 21, 2026.
Transparency logRelease files / tsne_h2pack-3.1.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | tsne_h2pack-3.1.1-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 |
e221b1a8a909c9352b3c2af5b9ce789150c51f097685c09fbc758f2c8bd2d653
|
|
BLAKE2b-256 checksum How to use checksums |
eb70ebc660156735c44616fbab7802cf226845644208ca91d24074e747644b14
|
| 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 21, 2026.
Transparency logRelease files / tsne_h2pack-3.1.1-cp313-cp313-macosx_14_0_arm64.whl
| Download URL | tsne_h2pack-3.1.1-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 |
bf518c6cabdd3549416083ea1be83d93484a82f722c8d3cc11630087e042be72
|
|
BLAKE2b-256 checksum How to use checksums |
5735f065c9726d75f4cb06b12699ed689f4bf7f27e565e1afe254843b55bb084
|
| 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 21, 2026.
Transparency logRelease files / tsne_h2pack-3.1.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | tsne_h2pack-3.1.1-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 |
ea5ab4da6a8f7bfc723a1a9812d0921c244e3c34e9218c9a097a611146d0f9ad
|
|
BLAKE2b-256 checksum How to use checksums |
a4ec39c8b07d518754b27f52e14e13e5f94af9ad899d1ec0dfe5ab451193296f
|
| 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 21, 2026.
Transparency logRelease files / tsne_h2pack-3.1.1-cp312-cp312-macosx_14_0_arm64.whl
| Download URL | tsne_h2pack-3.1.1-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 |
2a656275138e596b99124c75e4ca36190b7ae7e240bce81d6de91f482593e012
|
|
BLAKE2b-256 checksum How to use checksums |
773e953c274ea1ded6cf98ca3b7f7f01f507ca07557ffef7117c1fa24c35d638
|
| 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 21, 2026.
Transparency logRelease files / tsne_h2pack-3.1.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | tsne_h2pack-3.1.1-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 |
9085e2c4128504d0141e4334ebe1d8d75ca1dcb205fd8e8c1f4f2b3eb551c158
|
|
BLAKE2b-256 checksum How to use checksums |
3b3ebb322909c36525655ee97eba3e841f7725736d3f9d714b587ed99f57c2f4
|
| 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 21, 2026.
Transparency logRelease files / tsne_h2pack-3.1.1-cp311-cp311-macosx_14_0_arm64.whl
| Download URL | tsne_h2pack-3.1.1-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 |
17a60cc3d9e4a68de56219df3dd0002b491263c4891fecffe4bf4a0a5e227814
|
|
BLAKE2b-256 checksum How to use checksums |
616386488d8aac2799fd98921dfed6f72c16799ad6f0fb9d9aa574f87400ebe0
|
| 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 21, 2026.
Transparency logRelease files / tsne_h2pack-3.1.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | tsne_h2pack-3.1.1-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 |
109fbfacaa28a0ae6d3b0482d747d0427fc102519154d2e0e6b060327727c5b6
|
|
BLAKE2b-256 checksum How to use checksums |
417c184cde5adfa368362df4089754fcdda9a5390435481551ef18caf0af85d4
|
| 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 21, 2026.
Transparency logRelease files / tsne_h2pack-3.1.1-cp310-cp310-macosx_14_0_arm64.whl
| Download URL | tsne_h2pack-3.1.1-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 |
fdd3a7a9fc09e6e3e624f2ff93a23b14ab9175c794b3b4f867f78e8800e7864e
|
|
BLAKE2b-256 checksum How to use checksums |
5996f4f8111e0e3a3f3f0f84e35569b152aa84c205c0dfd19ff6b0ee4937f664
|
| 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 21, 2026.
Transparency logRelease files / tsne_h2pack-3.1.1-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | tsne_h2pack-3.1.1-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 |
6b2a79e45d926d2809b84616a5b835d2b587f72070e93eb57e2ebf390f9103b3
|
|
BLAKE2b-256 checksum How to use checksums |
af3853c87ca0d4b22f479797c4675f84cee9dc306905011d64922de6878d3807
|
| 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 21, 2026.
Transparency logRelease files / tsne_h2pack-3.1.1-cp39-cp39-macosx_14_0_arm64.whl
| Download URL | tsne_h2pack-3.1.1-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 |
27182950c7fb9a7bc888ecf95e90102232dcfd9bef2a472facbe49d324190813
|
|
BLAKE2b-256 checksum How to use checksums |
d5d4ddb721dc1d9fc91a075d2bc7a5fdd39071e00fa38111807ecda923eae997
|
| 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 21, 2026.
Transparency log