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 Overview

🔍 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.1.0.tar.gz (4.7 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.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mhc_pytorch-0.1.0.tar.gz
  • Upload date:
  • Size: 4.7 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.1.0.tar.gz
Algorithm Hash digest
SHA256 4cfaf12abf3e9d4a07b9d11b9d551c190634ed325159b7d2d4b761cfd803f870
MD5 4a919d3bfef1bf13522c18688caad17c
BLAKE2b-256 50a319dd64057091330be153511156508a5ec118e3c28edc9fc5a5196b564ee2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mhc_pytorch-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 78922b53e442856ab2bbaa1cfc8f1dca24d37a41743724510b251c147a3d5e1a
MD5 5f17bc449d9d06fa8967483cbd3c2f8f
BLAKE2b-256 ed783aa1d26bd8c559c6214b1e386bda60f08be357910df68696f1bbb4a1d614

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