mlx-cluster 0.0.6__cp310-cp310-macosx_14_0_universal2.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mlx_cluster/__init__.py +5 -0
- mlx_cluster/_ext.cpython-310-darwin.so +0 -0
- mlx_cluster/libmlx_cluster.dylib +0 -0
- mlx_cluster/mlx_cluster.metallib +0 -0
- mlx_cluster-0.0.6.dist-info/METADATA +243 -0
- mlx_cluster-0.0.6.dist-info/RECORD +9 -0
- mlx_cluster-0.0.6.dist-info/WHEEL +5 -0
- mlx_cluster-0.0.6.dist-info/licenses/LICENSE +21 -0
- mlx_cluster-0.0.6.dist-info/top_level.txt +1 -0
mlx_cluster/__init__.py
ADDED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mlx_cluster
|
|
3
|
+
Version: 0.0.6
|
|
4
|
+
Summary: C++ extension for generating random graphs
|
|
5
|
+
Author-email: Vinay Pandya <vinayharshadpandya27@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/vinayhpandya/mlx_cluster
|
|
7
|
+
Project-URL: Issues, https://github.com/vinayhpandya/mlx_cluster/Issues
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: C++
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: MacOS
|
|
13
|
+
Requires-Python: >=3.8
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Provides-Extra: dev
|
|
17
|
+
Provides-Extra: docs
|
|
18
|
+
Requires-Dist: mlx>=0.27.1; extra == "docs"
|
|
19
|
+
Requires-Dist: mlx-graphs>=0.0.8; extra == "docs"
|
|
20
|
+
Requires-Dist: ipython==8.21.0; extra == "docs"
|
|
21
|
+
Requires-Dist: sphinx>=7.2.6; extra == "docs"
|
|
22
|
+
Requires-Dist: sphinx-book-theme==1.1.0; extra == "docs"
|
|
23
|
+
Requires-Dist: sphinx-autodoc-typehints==1.25.2; extra == "docs"
|
|
24
|
+
Requires-Dist: nbsphinx==0.9.3; extra == "docs"
|
|
25
|
+
Requires-Dist: sphinx-gallery==0.15.0; extra == "docs"
|
|
26
|
+
Provides-Extra: test
|
|
27
|
+
Requires-Dist: mlx-graphs>=0.0.8; extra == "test"
|
|
28
|
+
Requires-Dist: torch>=2.2.0; extra == "test"
|
|
29
|
+
Requires-Dist: mlx>=0.26.0; extra == "test"
|
|
30
|
+
Requires-Dist: pytest==7.4.4; extra == "test"
|
|
31
|
+
Requires-Dist: scipy>=1.13.0; extra == "test"
|
|
32
|
+
Requires-Dist: requests==2.31.0; extra == "test"
|
|
33
|
+
Requires-Dist: fsspec[http]==2024.2.0; extra == "test"
|
|
34
|
+
Requires-Dist: tqdm==4.66.1; extra == "test"
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
Dynamic: requires-python
|
|
37
|
+
|
|
38
|
+
# MLX-Cluster
|
|
39
|
+
|
|
40
|
+
High-performance graph algorithms optimized for Apple's MLX framework, featuring random walks, biased random walks, and neighbor sampling.
|
|
41
|
+
|
|
42
|
+
[](https://pypi.org/project/mlx-cluster/)
|
|
43
|
+
[](https://opensource.org/licenses/MIT)
|
|
44
|
+
[](https://www.python.org/downloads/)
|
|
45
|
+
|
|
46
|
+
**[Documentation](https://vinayhpandya.github.io/mlx_cluster/)** | **[Quickstart](https://vinayhpandya.github.io/mlx_cluster/quickstart.html)** |
|
|
47
|
+
|
|
48
|
+
## ๐ Features
|
|
49
|
+
|
|
50
|
+
- **๐ฅ MLX Optimized**: Built specifically for Apple's MLX framework with GPU acceleration
|
|
51
|
+
- **โก High Performance**: Optimized C++ implementations with Metal shaders for Apple Silicon
|
|
52
|
+
- **๐ฏ Graph Algorithms**:
|
|
53
|
+
- Uniform random walks
|
|
54
|
+
- Biased random walks (Node2Vec style with p/q parameters)
|
|
55
|
+
- Multi-hop neighbor sampling (GraphSAGE style)
|
|
56
|
+
|
|
57
|
+
## ๐ฆ Installation
|
|
58
|
+
|
|
59
|
+
### From PyPI (Recommended)
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pip install mlx-cluster
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### From Source
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
git clone https://github.com/vinayhpandya/mlx_cluster.git
|
|
69
|
+
cd mlx_cluster
|
|
70
|
+
pip install -e .
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Development Installation
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
git clone https://github.com/vinayhpandya/mlx_cluster.git
|
|
77
|
+
cd mlx_cluster
|
|
78
|
+
pip install -e . --verbose
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Dependencies
|
|
82
|
+
|
|
83
|
+
Required:
|
|
84
|
+
- Python 3.8+
|
|
85
|
+
- MLX framework
|
|
86
|
+
- NumPy
|
|
87
|
+
|
|
88
|
+
Optional (for examples and testing):
|
|
89
|
+
- MLX-Graphs
|
|
90
|
+
- PyTorch (for dataset utilities)
|
|
91
|
+
- pytest
|
|
92
|
+
|
|
93
|
+
## ๐ง Quick Start
|
|
94
|
+
|
|
95
|
+
### Random Walks
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
import mlx.core as mx
|
|
99
|
+
import numpy as np
|
|
100
|
+
from mlx_cluster import random_walk
|
|
101
|
+
from mlx_graphs.datasets import PlanetoidDataset
|
|
102
|
+
from mlx_graphs.utils.sorting import sort_edge_index
|
|
103
|
+
|
|
104
|
+
# Load dataset
|
|
105
|
+
cora = PlanetoidDataset(name="cora")
|
|
106
|
+
edge_index = cora.graphs[0].edge_index.astype(mx.int64)
|
|
107
|
+
|
|
108
|
+
# Convert to CSR format
|
|
109
|
+
sorted_edge_index = sort_edge_index(edge_index=edge_index)
|
|
110
|
+
row = sorted_edge_index[0][0]
|
|
111
|
+
col = sorted_edge_index[0][1]
|
|
112
|
+
_, counts = np.unique(np.array(row, copy=False), return_counts=True)
|
|
113
|
+
row_ptr = mx.concatenate([mx.array([0]), mx.array(counts.cumsum())])
|
|
114
|
+
|
|
115
|
+
# Generate random walks
|
|
116
|
+
num_walks = 1000
|
|
117
|
+
walk_length = 10
|
|
118
|
+
start_nodes = mx.array(np.random.randint(0, cora.graphs[0].num_nodes, num_walks))
|
|
119
|
+
rand_values = mx.random.uniform(shape=[num_walks, walk_length])
|
|
120
|
+
|
|
121
|
+
mx.eval(rowptr,col, start_nodes, rand_values)
|
|
122
|
+
# Perform walks
|
|
123
|
+
node_sequences, edge_sequences = random_walk(
|
|
124
|
+
row_ptr, col, start_nodes, rand_values, walk_length, stream=mx.gpu
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
print(f"Generated {num_walks} walks of length {walk_length + 1}")
|
|
128
|
+
print(f"Shape: {node_sequences.shape}")
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Biased Random Walks (Node2Vec)
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
from mlx_cluster import rejection_sampling
|
|
135
|
+
|
|
136
|
+
# Biased random walks with p/q parameters
|
|
137
|
+
node_sequences, edge_sequences = rejection_sampling(
|
|
138
|
+
row_ptr, col, start_nodes, walk_length,
|
|
139
|
+
p=1.0, # Return parameter
|
|
140
|
+
q=2.0, # In-out parameter
|
|
141
|
+
stream=mx.gpu
|
|
142
|
+
)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Neighbor Sampling
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
from mlx_cluster import neighbor_sample
|
|
149
|
+
|
|
150
|
+
# Convert to CSC format (required for neighbor sampling)
|
|
151
|
+
def create_csc_format(edge_index, num_nodes):
|
|
152
|
+
sources, targets = edge_index[0].tolist(), edge_index[1].tolist()
|
|
153
|
+
edges = sorted(zip(sources, targets), key=lambda x: x[1])
|
|
154
|
+
|
|
155
|
+
colptr = np.zeros(num_nodes + 1, dtype=np.int64)
|
|
156
|
+
for _, target in edges:
|
|
157
|
+
colptr[target + 1] += 1
|
|
158
|
+
colptr = np.cumsum(colptr)
|
|
159
|
+
|
|
160
|
+
sorted_sources = [source for source, _ in edges]
|
|
161
|
+
return mx.array(colptr), mx.array(sorted_sources, dtype=mx.int64)
|
|
162
|
+
|
|
163
|
+
colptr, row = create_csc_format(edge_index, cora.graphs[0].num_nodes)
|
|
164
|
+
|
|
165
|
+
# Multi-hop neighbor sampling
|
|
166
|
+
input_nodes = mx.array([0, 1, 2], dtype=mx.int64)
|
|
167
|
+
num_neighbors = [10, 5] # 10 neighbors in first hop, 5 in second
|
|
168
|
+
mx.eval(colptr, row, input_nodes)
|
|
169
|
+
samples, rows, cols, edges = neighbor_sample(
|
|
170
|
+
colptr, row, input_nodes, num_neighbors,
|
|
171
|
+
replace=True, directed=True
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
print(f"Sampled {len(samples)} nodes and {len(edges)} edges")
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## ๐ Documentation
|
|
178
|
+
|
|
179
|
+
For comprehensive documentation, examples, and API reference, visit:
|
|
180
|
+
[Documentation]()
|
|
181
|
+
|
|
182
|
+
## ๐งช Testing
|
|
183
|
+
|
|
184
|
+
Run the test suite:
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
# Install test dependencies
|
|
188
|
+
pip install pytest mlx-graphs torch
|
|
189
|
+
|
|
190
|
+
# Run tests
|
|
191
|
+
pytest -s -v
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## โก Performance
|
|
195
|
+
|
|
196
|
+
MLX-Cluster is optimized for Apple Silicon and shows significant speedups:
|
|
197
|
+
|
|
198
|
+
- **Apple M1/M2/M3**: 2-5x faster than CPU-only implementations
|
|
199
|
+
- **GPU Acceleration**: Automatic optimization for Metal Performance Shaders
|
|
200
|
+
- **Memory Efficient**: Optimized sparse graph representations
|
|
201
|
+
- **Batch Processing**: Efficient handling of thousands of concurrent walks
|
|
202
|
+
|
|
203
|
+
## ๐ค Contributing
|
|
204
|
+
|
|
205
|
+
We welcome contributions!
|
|
206
|
+
1. Fork the repository
|
|
207
|
+
2. Create your feature branch (`git checkout -b feature/new-feature`)
|
|
208
|
+
3. Commit your changes (`git commit -m 'Add new algorithm'`)
|
|
209
|
+
4. Push to the branch (`git push origin feature/new-feature`)
|
|
210
|
+
5. Open a Pull Request
|
|
211
|
+
For installation and test intructions please visit the documentation
|
|
212
|
+
|
|
213
|
+
## ๐ License
|
|
214
|
+
|
|
215
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
216
|
+
|
|
217
|
+
## ๐ Acknowledgments
|
|
218
|
+
|
|
219
|
+
- [PyTorch Cluster](https://github.com/rusty1s/pytorch_cluster) for everything
|
|
220
|
+
- [MLX](https://github.com/ml-explore/mlx) for the foundational framework
|
|
221
|
+
- [MLX-Graphs](https://github.com/mlx-graphs/mlx-graphs) for graph utilities and datasets
|
|
222
|
+
|
|
223
|
+
## ๐ Citation
|
|
224
|
+
|
|
225
|
+
If you use MLX-Cluster in your research, please cite:
|
|
226
|
+
|
|
227
|
+
```bibtex
|
|
228
|
+
@software{mlx_cluster,
|
|
229
|
+
author = {Vinay Pandya},
|
|
230
|
+
title = {MLX-Cluster: High-Performance Graph Algorithms for Apple MLX},
|
|
231
|
+
url = {https://github.com/vinayhpandya/mlx_cluster},
|
|
232
|
+
version = {0.0.6},
|
|
233
|
+
year = {2025}
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## ๐ Related Projects
|
|
238
|
+
|
|
239
|
+
- [MLX](https://github.com/ml-explore/mlx) - Apple's machine learning framework
|
|
240
|
+
- [MLX-Graphs](https://github.com/mlx-graphs/mlx-graphs) - Graph neural networks for MLX
|
|
241
|
+
- [PyTorch Geometric](https://github.com/pyg-team/pytorch_geometric) - Graph deep learning library
|
|
242
|
+
|
|
243
|
+
---
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
mlx_cluster/__init__.py,sha256=0OCVEloeEo3Y9a-RlrSH7-C18IOTMDFS1-TjUMEYlSw,124
|
|
2
|
+
mlx_cluster/_ext.cpython-310-darwin.so,sha256=VDCXTlyjz445WJg7wr8sSflnynWYeKDHTatSBT9i8iI,148616
|
|
3
|
+
mlx_cluster/libmlx_cluster.dylib,sha256=aOIkBNXNZzQek1Rv9o_qsaarL77LNiDoeN9hazH7de8,86248
|
|
4
|
+
mlx_cluster/mlx_cluster.metallib,sha256=LdYPYY3iNcwYXpRY-yX_ANOMbDPx04iMx4QJaCFTanA,5416
|
|
5
|
+
mlx_cluster-0.0.6.dist-info/licenses/LICENSE,sha256=7ixsoVuroKzGl84-ZV90CDH6bQrQF2UXvgnTqtW4Zb4,1069
|
|
6
|
+
mlx_cluster-0.0.6.dist-info/METADATA,sha256=-8iqo7hi_d_sug1sGTbjfeFzA0noYLrN1r3OuaMGD1Y,7451
|
|
7
|
+
mlx_cluster-0.0.6.dist-info/WHEEL,sha256=T2p57lol9__xkoU6aJTyN1Pm43ZpRU3q6km7mIbrAMs,114
|
|
8
|
+
mlx_cluster-0.0.6.dist-info/top_level.txt,sha256=sERi0kZuQnKmsHnqOkAda1kkBXdQAwV25Y9L-ATj110,12
|
|
9
|
+
mlx_cluster-0.0.6.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 vinayhpandya
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mlx_cluster
|