Skip to main content
Change of provenance

The repository or configuration that created this release differ from a previous release. View details.

MLX-Cluster

High-performance graph algorithms optimized for Apple's MLX framework, featuring random walks, biased random walks, neighbor sampling, and fused sparse × dense matrix multiplication (SpMM) for GNN message passing.

PyPI version License: MIT Python 3.10+

Documentation | Quickstart |

Features

  • MLX Optimized: Built specifically for Apple's MLX framework with GPU acceleration
  • High Performance: Optimized C++ implementations with Metal shaders for Apple Silicon
  • Graph Algorithms:
    • Uniform random walks
    • Biased random walks (Node2Vec style with p/q parameters)
    • Multi-hop neighbor sampling (GraphSAGE style)
    • Sparse × dense matrix multiplication (SpMM) for message passing: sum, mean, max, min, with gradients (COO and CSR, Metal kernels)

Installation

pip install mlx-cluster

From Source

git clone https://github.com/vinayhpandya/mlx_cluster.git
cd mlx_cluster
pip install -e .

Development Installation

git clone https://github.com/vinayhpandya/mlx_cluster.git
cd mlx_cluster
pip install -e . --verbose

Dependencies

Required:

  • Python 3.10+
  • MLX framework
  • NumPy

Optional (for examples and testing):

  • MLX-Graphs
  • PyTorch (for dataset utilities)
  • pytest

Quick Start

Random Walks

import mlx.core as mx
import numpy as np
from mlx_cluster import random_walk
from mlx_graphs.datasets import PlanetoidDataset
from mlx_graphs.utils.sorting import sort_edge_index

# Load dataset
cora = PlanetoidDataset(name="cora")
edge_index = cora.graphs[0].edge_index.astype(mx.int64)

# Convert to CSR format
sorted_edge_index = sort_edge_index(edge_index=edge_index)
row = sorted_edge_index[0][0]
col = sorted_edge_index[0][1]
_, counts = np.unique(np.array(row, copy=False), return_counts=True)
row_ptr = mx.concatenate([mx.array([0]), mx.array(counts.cumsum())])

# Generate random walks
num_walks = 1000
walk_length = 10
start_nodes = mx.array(np.random.randint(0, cora.graphs[0].num_nodes, num_walks))
rand_values = mx.random.uniform(shape=[num_walks, walk_length])

mx.eval(rowptr,col, start_nodes, rand_values)
# Perform walks
node_sequences, edge_sequences = random_walk(
    row_ptr, col, start_nodes, rand_values, walk_length, stream=mx.gpu
)

print(f"Generated {num_walks} walks of length {walk_length + 1}")
print(f"Shape: {node_sequences.shape}")

Biased Random Walks (Node2Vec)

from mlx_cluster import rejection_sampling

# Biased random walks with p/q parameters
node_sequences, edge_sequences = rejection_sampling(
    row_ptr, col, start_nodes, walk_length,
    p=1.0,  # Return parameter
    q=2.0,  # In-out parameter
    stream=mx.gpu
)

Neighbor Sampling

from mlx_cluster import neighbor_sample

# Convert to CSC format (required for neighbor sampling)
def create_csc_format(edge_index, num_nodes):
    sources, targets = edge_index[0].tolist(), edge_index[1].tolist()
    edges = sorted(zip(sources, targets), key=lambda x: x[1])
    
    colptr = np.zeros(num_nodes + 1, dtype=np.int64)
    for _, target in edges:
        colptr[target + 1] += 1
    colptr = np.cumsum(colptr)
    
    sorted_sources = [source for source, _ in edges]
    return mx.array(colptr), mx.array(sorted_sources, dtype=mx.int64)

colptr, row = create_csc_format(edge_index, cora.graphs[0].num_nodes)

# Multi-hop neighbor sampling
input_nodes = mx.array([0, 1, 2], dtype=mx.int64)
num_neighbors = [10, 5]  # 10 neighbors in first hop, 5 in second
mx.eval(colptr, row, input_nodes)
samples, rows, cols, edges = neighbor_sample(
    colptr, row, input_nodes, num_neighbors,
    replace=True, directed=True
)

print(f"Sampled {len(samples)} nodes and {len(edges)} edges")

Sparse Matrix Multiplication (message passing)

Aggregates neighbour features as A @ X without materialising a [num_edges, features] message array, in both the forward and backward pass.

import mlx.core as mx
from mlx_cluster import coo_to_csr, spmm_coo, spmm_csr

edge_index = mx.array([[0, 1, 2, 2], [1, 2, 0, 1]])   # [src, dst]
src, dst = edge_index[0], edge_index[1]
x = mx.random.normal((3, 64))

# COO: works on the edge list directly
out = spmm_coo(dst, src, x, reduce="sum")             # also "mean", "max", "min"

# CSR: sort once per graph and reuse; deterministic and fastest on larger graphs
csr = coo_to_csr(dst, src, num_rows=3)
out = spmm_csr(csr.rowptr, csr.col, x, reduce="mean",
               long_rows=csr.long_rows, transpose=csr.transpose)

grad = mx.grad(lambda x: spmm_csr(csr.rowptr, csr.col, x,
                                  transpose=csr.transpose).sum())(x)

On an Apple M4 Pro, a GCN training step on a 1M-edge graph (256 features) is about 4x faster and uses about 4.6x less memory than gather-scatter. mlx-graphs uses these kernels automatically via @fused_message_passing. See the SpMM guide for conventions (empty rows, ties) and details.

Documentation

For comprehensive documentation, examples, and API reference, visit: Documentation

Testing

Run the test suite:

# Install test dependencies
pip install pytest mlx-graphs torch

# Run tests
pytest -s -v

Performance

MLX-Cluster is optimized for Apple Silicon and shows significant speedups:

  • Apple M1/M2/M3: 2-5x faster than CPU-only implementations
  • GPU Acceleration: Automatic optimization for Metal Performance Shaders
  • Memory Efficient: Optimized sparse graph representations
  • Batch Processing: Efficient handling of thousands of concurrent walks

Contributing

We welcome contributions!

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/new-feature)
  3. Commit your changes (git commit -m 'Add new algorithm')
  4. Push to the branch (git push origin feature/new-feature)
  5. Open a Pull Request For installation and test intructions please visit the documentation

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

Citation

If you use MLX-Cluster in your research, please cite:

@software{mlx_cluster,
  author = {Vinay Pandya},
  title = {MLX-Cluster: High-Performance Graph Algorithms for Apple MLX},
  url = {https://github.com/vinayhpandya/mlx_cluster},
  version = {0.0.6},
  year = {2025}
}

Metadata

Release files for mlx-cluster 0.1.1

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

Change of provenance

The repository or configuration that created these release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Source distribution (sdist)

Source distribution for mlx-cluster 0.1.1
File Size Uploaded Provenance Actions
mlx_cluster-0.1.1.tar.gz 88.4 kB With provenance Details for mlx_cluster-0.1.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for mlx-cluster 0.1.1
File Actions
mlx_cluster-0.1.1-cp313-cp313-macosx_15_0_universal2.whl CPython 3.13 CPython 3.13 macOS 15.0+ universal2 (ARM64, x86-64) Details for mlx_cluster-0.1.1-cp313-cp313-macosx_15_0_universal2.whl
mlx_cluster-0.1.1-cp312-cp312-macosx_15_0_universal2.whl CPython 3.12 CPython 3.12 macOS 15.0+ universal2 (ARM64, x86-64) Details for mlx_cluster-0.1.1-cp312-cp312-macosx_15_0_universal2.whl
mlx_cluster-0.1.1-cp311-cp311-macosx_15_0_universal2.whl CPython 3.11 CPython 3.11 macOS 15.0+ universal2 (ARM64, x86-64) Details for mlx_cluster-0.1.1-cp311-cp311-macosx_15_0_universal2.whl
mlx_cluster-0.1.1-cp310-cp310-macosx_15_0_universal2.whl CPython 3.10 CPython 3.10 macOS 15.0+ universal2 (ARM64, x86-64) Details for mlx_cluster-0.1.1-cp310-cp310-macosx_15_0_universal2.whl

Total release size: 1.1 MB

Release files / mlx_cluster-0.1.1.tar.gz

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL mlx_cluster-0.1.1.tar.gz
Size 88.4 kB
Tags Source
SHA-256 checksum
How to use checksums
fecf5f4839b4b4dd9be6107d0357026b54c620052b14eceff35b4b122e56e6f9
BLAKE2b-256 checksum
How to use checksums
5e8776b7e4c3d59f8abf4e9889b0e8de4ea06e073eeef21cabc53d02760ff36c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 9, 2026.

Transparency log

Release files / mlx_cluster-0.1.1-cp313-cp313-macosx_15_0_universal2.whl

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL mlx_cluster-0.1.1-cp313-cp313-macosx_15_0_universal2.whl
Size 249.6 kB
Tags CPython 3.13 macOS 15.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
e1cb7ae510fec971894b5a83de70104a96e76a1041f522135502e5c91dc751b1
BLAKE2b-256 checksum
How to use checksums
a22cb1cca66f93a28eec6241c0639759b04ccecdd00e0fc38ae47acff1535c45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 9, 2026.

Transparency log

Release files / mlx_cluster-0.1.1-cp312-cp312-macosx_15_0_universal2.whl

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL mlx_cluster-0.1.1-cp312-cp312-macosx_15_0_universal2.whl
Size 249.7 kB
Tags CPython 3.12 macOS 15.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
1e708beb281e7a2c69553be04b03c1d59450826ae1bc002d50e1b8d24a641bb4
BLAKE2b-256 checksum
How to use checksums
520e3dbf2211afc37292e9b4bf381197a3d4d8606c7c1caa59a9c573d17d5ea7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 9, 2026.

Transparency log

Release files / mlx_cluster-0.1.1-cp311-cp311-macosx_15_0_universal2.whl

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL mlx_cluster-0.1.1-cp311-cp311-macosx_15_0_universal2.whl
Size 250.4 kB
Tags CPython 3.11 macOS 15.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
9a1728156e1cfedd67f5b161e70a05051897d385eb2039f46390b5db07f9994c
BLAKE2b-256 checksum
How to use checksums
e07a09191324aef809aceda1bdbcee7fd893fcd026a00edecdb033ffdce82dfa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 9, 2026.

Transparency log

Release files / mlx_cluster-0.1.1-cp310-cp310-macosx_15_0_universal2.whl

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL mlx_cluster-0.1.1-cp310-cp310-macosx_15_0_universal2.whl
Size 250.5 kB
Tags CPython 3.10 macOS 15.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
79661320ec45fef34186a1192c4bac5ec023409456288f73d4d0189e4586e674
BLAKE2b-256 checksum
How to use checksums
f41b3092cff9a2f74697ebe4dce8b834b56925b126877663df7b1b2a3e8f28a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 9, 2026.

Transparency log

Security for mlx-cluster 0.1.1

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.

Change of provenance

The repository and configuration that created this release differ from a previous release.

While this could reflect a routine change by the project maintainers, it may also indicate that the release files have been compromised.

Select from 5 files

Attestation for mlx_cluster-0.1.1.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 9, 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