Skip to main content

TorchGMM

Tests Documentation

TorchGMM allows to run Gaussian Mixture Models on single or multiple CPUs/GPUs. The repository is a fork from PyCave and LightKit, two amazing packages developed by Oliver Borchert that are not being maintained anymore. While PyCave implements additional models such as Markov Chains, TorchGMM focuses only on Gaussian Mixture Models.

The models are implemented in PyTorch and PyTorch Lightning, and provide an Estimator API that is fully compatible with scikit-learn.

For Gaussian mixture model, TorchGMM allows for 100x speed ups when using a GPU and enables to train on markedly larger datasets via mini-batch training. The full suite of benchmarks run to compare TorchGMM models against scikit-learn models is available on the documentation website.

Features

  • Support for GPU and multi-node training by implementing models in PyTorch and relying on PyTorch Lightning
  • Mini-batch training for all models such that they can be used on huge datasets
  • Well-structured implementation of models
    • High-level Estimator API allows for easy usage such that models feel and behave like in scikit-learn
    • Medium-level LightingModule implements the training algorithm
    • Low-level PyTorch Module manages the model parameters

Getting started

Please refer to the documentation. In particular, the API documentation

Requirements

TorchGMM requires PyTorch to be installed. The installation instructions can be found on the PyTorch website.

TorchGMM is available via pip:

pip install torchgmm

Usage

If you've ever used scikit-learn, you'll feel right at home when using TorchGMM. First, let's create some artificial data to work with:

import torch

X = torch.cat([
    torch.randn(10000, 8) - 5,
    torch.randn(10000, 8),
    torch.randn(10000, 8) + 5,
])

This dataset consists of three clusters with 8-dimensional datapoints. If you want to fit a K-Means model, to find the clusters' centroids, it's as easy as:

from torchgmm.clustering import KMeans

estimator = KMeans(3)
estimator.fit(X)

# Once the estimator is fitted, it provides various properties. One of them is
# the `model_` property which yields the PyTorch module with the fitted parameters.
print("Centroids are:")
print(estimator.model_.centroids)

Due to the high-level estimator API, the usage for all machine learning models is similar. The API documentation provides more detailed information about parameters that can be passed to estimators and which methods are available.

GPU and Multi-Node training

For GPU- and multi-node training, TorchGMM leverages PyTorch Lightning. The hardware that training runs on is determined by the Trainer class. It's init method provides various configuration options.

If you want to run K-Means with a GPU, you can pass the options accelerator='gpu' and devices=1 to the estimator's initializer:

estimator = KMeans(3, trainer_params=dict(accelerator='gpu', devices=1))

Similarly, if you want to train on 4 nodes simultaneously where each node has one GPU available, you can specify this as follows:

estimator = KMeans(3, trainer_params=dict(num_nodes=4, accelerator='gpu', devices=1))

In fact, you do not need to change anything else in your code.

Implemented Models

Currently, TorchGMM implements two different models:

Contribution

If you found a bug or you want to propose a new feature, please use the issue tracker.

License

TorchGMM is licensed under the MIT License.

Metadata

Release files for torchgmm 0.1.5

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

Source distribution (sdist)

Source distribution for torchgmm 0.1.5
File Size Uploaded Provenance Actions
torchgmm-0.1.5.tar.gz 56.1 kB With provenance Details for torchgmm-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for torchgmm 0.1.5
File Interpreter ABI Platform Actions
torchgmm-0.1.5-py3-none-any.whl Python 3 none any Details for torchgmm-0.1.5-py3-none-any.whl

Total release size: 103.9 kB

Release files / torchgmm-0.1.5.tar.gz

Download URL torchgmm-0.1.5.tar.gz
Size 56.1 kB
Tags Source
SHA-256 checksum
How to use checksums
67627fdad0e08b27b3d4722f81087e55b57d3194478b2e0678a3a5ae2f13f056
BLAKE2b-256 checksum
How to use checksums
e8b7a9f413d71a89560a8acaff4cf043e270d2e98e607d5e7aa5269e006d0b11
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 Nov 4, 2026.

Transparency log

Release files / torchgmm-0.1.5-py3-none-any.whl

Download URL torchgmm-0.1.5-py3-none-any.whl
Size 47.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1077a1a22f3436ef691c5daf020c6e15ae30fb87b485d815c5ba7f548e76739b
BLAKE2b-256 checksum
How to use checksums
e7aec7228286ebcfbe7487c906a5b9c514635657ce14ef5dddc0f646f245cd8d
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 Nov 4, 2026.

Transparency log

Security for torchgmm 0.1.5

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for torchgmm-0.1.5.tar.gz

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 Nov 4, 2026.

Transparency log

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.

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