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

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.

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

mhc_pytorch-0.2.2.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.2-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mhc_pytorch-0.2.2.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.2.tar.gz
Algorithm Hash digest
SHA256 b397f9d521a61e59528e95e6f099d32b450e7b6e17a4182fdd14504f4928e1e5
MD5 bf97fb6400e9a18ff5f44e23f602ad00
BLAKE2b-256 0bdd704739ad485186c053b3f2ac16bf7d4feda8e2e2a4f86e392b5c2ac5362a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mhc_pytorch-0.2.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 85579dba0f5ae8321606bb975f9dec14b9321978775c6769966fab7e906a9ab6
MD5 9729d96ffbef9051d7b3c6ca5f9542d9
BLAKE2b-256 a2774f02d246a2a805626268e3b14503f612ad90556084b24dde325ce88a9606

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