Skip to main content

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), an advanced 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.

MHC Architecture

🔍 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.

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

mhc_pytorch-0.2.1.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

mhc_pytorch-0.2.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file mhc_pytorch-0.2.1.tar.gz.

File metadata

  • Download URL: mhc_pytorch-0.2.1.tar.gz
  • Upload date:
  • Size: 4.8 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

Hashes for mhc_pytorch-0.2.1.tar.gz
Algorithm Hash digest
SHA256 8301e772ff6f610c489e30145d13a8009d3dfc6fe56dea84a2ae97889493dad5
MD5 22b1af0001647508170ceb4f12568777
BLAKE2b-256 33c2b720b6fd06ca3d026600ce4f7e230e2ab42e2ddfd9bb1ae5112c64f9a282

See more details on using hashes here.

File details

Details for the file mhc_pytorch-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: mhc_pytorch-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 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

Hashes for mhc_pytorch-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e2a67fa886f6c067c3dd5e68077c8cc27d99259c5b8c32a5797c7be9ef2aa6f2
MD5 15e89ffadff24a734ed7bf52fa320293
BLAKE2b-256 a29e702e8b9ccd72ca522c452bbe6fbb19484efa339552273a8c27c965e509b5

See more details on using hashes here.

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