mHC: Manifold-Constrained Hyper-Connections
A PyTorch implementation of Manifold-Constrained Hyper-Connections (mHC), a multi-stream residual connection mechanism for deep learning models. This module dynamically determines stream mixing based on input while constraining the parameters to mathematical manifolds such as Sinkhorn.
🔍 Features
- Manifold-Constrained Mixing: Ensures mixing parameters with mathematical manifolds
- Multi-Stream Architecture: Supports parallel residual streams for enhanced model capacity
- PyTorch Native: Seamless integration with existing PyTorch models and training pipelines
📦 Installation
Make sure you have Python 3.12+ and Poetry installed.
Using pip
pip install mhc-pytorch
From the source
git clone https://github.com/KennyStryker/manifold-constrained-hyper-connections.git
cd manifold-constrained-hyper-connections
poetry install
🚀 Usage
import torch
import torch.nn as nn
from mhc import ManifoldHyperConnections
# Define your base block
class MLPBlock(nn.Module):
def __init__(self, dim):
super().__init__()
self.block = nn.Sequential(
nn.Linear(dim, 4 * dim),
nn.GELU(),
nn.Linear(4 * dim, dim)
)
def forward(self, x):
return self.block(x)
# Create mHC module
dim = 512
num_streams = 4
block = MLPBlock(dim)
mhc_layer = ManifoldHyperConnections(dim=dim, num_streams=num_streams, block=block)
# Use in forward pass
x = torch.randn(32, 128, dim) # [batch_size, seq_len, dim]
output = mhc_layer(x) # [batch_size, seq_len, dim]
Citations
@article{arXiv,
title = {mHC: Manifold-Constrained Hyper-Connections},
author = {Zhenda Xie, Yixuan Wei, Huanqi Cao, Chenggang Zhao, Chengqi Deng, Jiashi Li, Damai Dai, Huazuo Gao, Jiang Chang, Kuai Yu, Liang Zhao, Shangyan Zhou, Zhean Xu, Zhengyan Zhang, Wangding Zeng, Shengding Hu, Yuqing Wang, Jingyang Yuan, Lean Wang, Wenfeng Liang},
url = {https://www.arxiv.org/abs/2512.24880}
}
@article{arXiv,
title = {Hyper-Connections},
author = {Defa Zhu, Hongzhi Huang, Zihao Huang, Yutao Zeng, Yunyao Mao, Banggu Wu, Qiyang Min, Xun Zhou},
url = {https://arxiv.org/abs/2409.19606}
}
Metadata
Release files for mhc-pytorch 0.2.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 | Provenance | Actions |
|---|---|---|---|---|
| mhc_pytorch-0.2.3.tar.gz | 4.9 kB | Without provenance | Details for mhc_pytorch-0.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mhc_pytorch-0.2.3-py3-none-any.whl | Python 3 | none | any | Details for mhc_pytorch-0.2.3-py3-none-any.whl |
Total release size: 10.6 kB
Release files / mhc_pytorch-0.2.3.tar.gz
| Download URL | mhc_pytorch-0.2.3.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
53e96eb08f01d38e940d78136f6357d3cc1a696a38b72b88eb65edfdc65ad359
|
|
BLAKE2b-256 checksum How to use checksums |
64bc7fce5f01544ca544b77e0c4fd8d485d789dbdd466c767aa677c704ca19fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.0 CPython/3.12.12 Linux/6.6.87.2-microsoft-standard-WSL2
|
Release files / mhc_pytorch-0.2.3-py3-none-any.whl
| Download URL | mhc_pytorch-0.2.3-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d25efab136f9b80a47518b6369563f332c9ebf61241ae4bc74a32bcc5f9a1931
|
|
BLAKE2b-256 checksum How to use checksums |
d7de43708a0f87d01701eef6ee84104927215b0c79db0cf9040ca842e58c0ac6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.0 CPython/3.12.12 Linux/6.6.87.2-microsoft-standard-WSL2
|
Security for mhc-pytorch 0.2.3
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.