Skip to main content

High-performance MLX implementation of Manifold-Constrained Hyper-Connections (mHC)

Project description

mhc-mlx

High-performance MLX implementation of Manifold-Constrained Hyper-Connections (mHC) for Apple Silicon.

This library provides a drop-in MHCLayer that fuses multiple operations into optimized Metal kernels, achieving significant speedups over standard implementations.

Installation

Install from PyPI:

pip install mhc-mlx

Quick Start

import mlx.core as mx
from mhc_mlx import MHCLayer

# Create some dummy data
B, n, C = 1, 32, 2048
x = mx.random.normal((B, n, C)).astype(mx.bfloat16)

# Initialize layer (uses Metal kernels by default)
layer = MHCLayer(n=n, C=C)

# Forward pass
y = layer(x)
mx.eval(y)
print(y.shape)  # (1, 32, 2048)

Note: You can also import as mlx_mhc if you prefer the style of other community packages:

from mlx_mhc import MHCLayer

Performance

We benchmarked on an Apple M4 Pro (macOS 15.6). mhc-mlx automatically selects the best kernel strategy based on workload size.

Latency Floor ($B=1$, Sequence Length=32)

Optimized for ultra-low latency response times.

Channels (C) Kernel Strategy Speedup vs Compiled MLX
256 Fully Fused 2.27x
1024 Fully Fused 1.57x
2048 Fully Fused 1.58x
4096 Column Parallel 1.41x
8192 Column Parallel 2.18x

High Throughput ($B=32$, Sequence Length=32)

Optimized for maximum data processing rate.

Channels (C) Kernel Strategy Speedup vs Compiled MLX
2048 Column Parallel 13.19x
8192 Column Parallel 12.36x

(Benchmarks run with bfloat16)

To reproduce:

mhc-mlx-bench --mode latency
mhc-mlx-bench --mode throughput --B 32

Key Optimizations

  • Fully Fused Kernel: Single kernel for Aggregate + RMS + Mix + Add. Ideal for $B \times C \le 2048$.
  • Column-Parallel Mixing: Vectorized kernel maximizing throughput for larger workloads.
  • Adaptive Dispatch: Runtime heuristic selects the fastest kernel.
  • Super-Fused Backward: Fused gradients for maximum training efficiency.

Troubleshooting

Kernel Compilation Errors: If you see Metal build errors, ensure you are on macOS with Apple Silicon. Run diagnostics to check your environment:

mhc-mlx-info

"No module named mhc_mlx" Ensure you installed the package mhc-mlx (dash), not mlx-mhc (which is a different package).

Development & Publishing

Workflow Name: For PyPI Trusted Publishing, the workflow filename is publish.yml.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mhc_mlx-0.1.0.tar.gz (35.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mhc_mlx-0.1.0-py3-none-any.whl (55.6 kB view details)

Uploaded Python 3

File details

Details for the file mhc_mlx-0.1.0.tar.gz.

File metadata

  • Download URL: mhc_mlx-0.1.0.tar.gz
  • Upload date:
  • Size: 35.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mhc_mlx-0.1.0.tar.gz
Algorithm Hash digest
SHA256 123a7ad7132ffbf4b507139e8094310ff7b770f1ed12cd15b2a242cc82f03e03
MD5 8c935f7aa66fdd6866df64489fc50637
BLAKE2b-256 04bd3a96e9f16fefdc2a08a326fa19b489396a1868a5322893365bb1e23ee1ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for mhc_mlx-0.1.0.tar.gz:

Publisher: publish.yml on svdrecbd/mhc-mlx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mhc_mlx-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mhc_mlx-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 55.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mhc_mlx-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 959afe93207c8ea7ac7c46c3441a8d1fe0dae1232f41a17fd2131821fee0667e
MD5 dc844704ee25ca06f7c66e75b1ad6fa1
BLAKE2b-256 e2d19dacae0fb60185c3b9b14e3b046e42dbed1700c7395994b473dd7edb53dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for mhc_mlx-0.1.0-py3-none-any.whl:

Publisher: publish.yml on svdrecbd/mhc-mlx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page