mhc-mlx
High-performance MLX implementation of Manifold-Constrained Hyper-Connections (mHC).
mHC improves training stability and performance in deep architectures by constraining residual connections to the Birkhoff polytope (doubly stochastic matrices). This library provides optimized Metal kernels for Apple Silicon and a fast compiled fallback for other platforms.
Original Paper: mHC: Manifold-Constrained Hyper-Connections (DeepSeek-AI)
Installation
pip install mhc-mlx
Compatibility
- Primary: macOS + Apple Silicon for peak performance.
- Support: Linux (CPU/CUDA) and Intel Macs via automatic pure-MLX compiled fallback.
- Software: MLX >= 0.30.0.
Quick Start (30-second Demo)
import mlx.core as mx
import mlx.nn as nn
from mhc_mlx import MHCRewire
# 1. Take any standard MLX layer
layer = nn.Linear(2048, 2048)
# 2. Wrap it with mHC stability (automatically uses optimized Metal kernels)
model = MHCRewire(layer, dims=2048, n=32)
# 3. Run forward pass
x = mx.random.normal((1, 2048))
y = model(x)
mx.eval(y)
# 4. Run backward pass (fully vectorized)
loss_fn = lambda m, x: mx.sum(m(x))
grads = mx.grad(loss_fn)(model, x)
mx.eval(grads)
print(f"Output shape: {y.shape}") # (1, 2048)
Note: You can also use from mlx_mhc import MHCRewire for a community-friendly alias.
Performance
mhc-mlx utilizes fused Metal kernels to minimize memory bandwidth bottlenecks. We benchmarked on an Apple M4 Pro (macOS 15.6).
Comparative Benchmarks
Comparison with a standard MLX implementation of mHC ($C=512$):
| Metric | mhc-mlx | Baseline Impl | Speedup |
|---|---|---|---|
| Inference Latency ($B=1$) | 392 us | 1120 us | 2.86x |
| Training Throughput ($B=32$) | 105 us | 866 us | 8.25x |
Why It's Faster
| Approach | Architecture | Impact |
|---|---|---|
| Baseline | Multiple kernel launches | High memory overhead, low GPU occupancy |
| mhc-mlx | Fused Metal Kernels | Minimal memory round-trips, maximal bandwidth |
Reproduce Benchmarks
Run the standardized benchmark suite on your own hardware:
mhc-mlx-bench --mode latency --C 512,2048,4096
Key Optimizations
- Universal Rewiring:
MHCRewirewraps any existingnn.Module(Linear, Conv2d) to apply mHC dynamics. - Quantized Layer Support: Seamlessly wraps
nn.QuantizedLinear(4-bit/8-bit). - Fully Fused Kernel: Single-pass kernel for Aggregate + RMS + Mix + Add.
- Adaptive Dispatch: Runtime heuristic selects the fastest kernel strategy for your workload.
Diagnostics
If you encounter issues, run the diagnostic utility:
mhc-mlx-info
Set MHC_MLX_DISABLE_METAL=1 in your environment to force the pure-MLX reference path (useful for debugging or non-Metal hardware).
Support Policy
- Tested: macOS (Apple Silicon) + Linux (CPU/CUDA) using MLX 0.30.0+.
- Best Effort: Intel Macs, older macOS versions, and older MLX versions.
- Reporting: Please include OS, MLX version, and
mhc-mlx-infooutput in bug reports.
License
MIT
Metadata
Release files for mhc-mlx 0.6.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mhc_mlx-0.6.3.tar.gz | 60.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mhc_mlx-0.6.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 140.2 kB
Release files / mhc_mlx-0.6.3.tar.gz
| Download URL | mhc_mlx-0.6.3.tar.gz |
|---|---|
| Size | 60.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
af456d4861a682db887ab3ac4f70d36f459b6f156e2f19641921f6c3f7b1afcb
|
|
BLAKE2b-256 checksum How to use checksums |
cec18b5e12495f6367ef1a8ccc027582e88a047ea6926e2a65252d3471904fd9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Jan 13, 2026.
Transparency logRelease files / mhc_mlx-0.6.3-py3-none-any.whl
| Download URL | mhc_mlx-0.6.3-py3-none-any.whl |
|---|---|
| Size | 79.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9d2c9975fac2dff282bc8e3cfc49bf41af5637431714722fb3c0ae629ef3d82c
|
|
BLAKE2b-256 checksum How to use checksums |
032c0adcfbb71af28f5037cc5be6a9e86eff86b63837bc0424b34de0459f3705
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Jan 13, 2026.
Transparency log