A PyTorch implementation of Manifold-Constrained Hyper-Connections (mHC), a multi-stream residual connection mechanism for deep learning models with mathematical constraints.
Project description
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}
}
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mhc_pytorch-0.2.3.tar.gz.
File metadata
- Download URL: mhc_pytorch-0.2.3.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.0 CPython/3.12.12 Linux/6.6.87.2-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53e96eb08f01d38e940d78136f6357d3cc1a696a38b72b88eb65edfdc65ad359
|
|
| MD5 |
c64b9192498bb97a17be964ab01c325a
|
|
| BLAKE2b-256 |
64bc7fce5f01544ca544b77e0c4fd8d485d789dbdd466c767aa677c704ca19fb
|
File details
Details for the file mhc_pytorch-0.2.3-py3-none-any.whl.
File metadata
- Download URL: mhc_pytorch-0.2.3-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.0 CPython/3.12.12 Linux/6.6.87.2-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d25efab136f9b80a47518b6369563f332c9ebf61241ae4bc74a32bcc5f9a1931
|
|
| MD5 |
5445a64bbf17a543dc1de773b75aabc1
|
|
| BLAKE2b-256 |
d7de43708a0f87d01701eef6ee84104927215b0c79db0cf9040ca842e58c0ac6
|