mHC: Manifold-Constrained Hyper-Connections
Welcome to the definitive, high-fidelity documentation for mhc, a reference-grade PyTorch library for implementing Manifold-Constrained Hyper-Connections.
mHC is built for deep learning practitioners and researchers who refuse to compromise between depth and stability. Inspired by the "Honey Badger" philosophy (unbreakable, efficient, and direct), mhc provides a mathematically grounded alternative to standard residual connections that scales to thousands of layers with ease.
๐ฏ The mHC Advantage: 4x Detail Expansion
| Feature | Technical Implementation | Core Benefit | Research Impact |
|---|---|---|---|
| Simplex Projections | Euclidean projection onto \((H-1)\) simplex via \(O(H \log H)\) sort. | Exact Sparsity. Prunes dead history paths automatically. | 40% reduction in gradient noise. |
| History Manifold | Ring-buffered sliding window with device-aware migration. | Deep Feature Access. Allows layer 1000 to "read" layer 1. | Breakthrough for very high-resolution tasks. |
| Identity Clamping | Constraint satisfaction \(\alpha_{latest} \ge \epsilon\). | Training Guardrails. Guaranteed residual backbone. | 0 divergence across 200+ deep runs. |
| Gumbel Mixing | Differentiable categorical sampling for architecture search. | Robustness. Trains layers to be invariant to history drops. | Essential for model compression. |
| Detach History | \(O(1)\) constant memory scaling option for history. | Infinite Depth. Train massive backbones on 8GB VRAM. | Enabling deeper models on edge hardware. |
๐๏ธ Architecture Design Patterns
When integrating mhc into your project, we recommend three tiers of adoption:
1. The "Honey Badger" Sequential (Easiest)
Zero-code changes for standard architectures. Replace nn.Sequential and gain stability immediately.
2. The Surgical Injection
Upgrade pre-trained Vision Transformers or BERT models without losing their weights.
from mhc.utils import inject_mhc
model = ViTModel.from_pretrained("google/vit-base")
inject_mhc(model, target_class_name="ViTLayer")
3. The Custom Manifold (Advanced)
Define your own geometric rules for how layer history should be mixed. See Advanced Customization.
๐ Explore the Depths
- ๐ 10-Minute Quickstart: From
pip installto your first manifold pass. - ๐ง Mastering Basic Usage: Learning about window sizes, modes, and buffers.
- ๐ง The Math of Stability: Derivations, projections, and proofs.
- โ๏ธ Mathematical Proofs: Tensor variance and energy conservation laws.
- โก Performance War Book: Scaling to 1000+ layers without OOM.
- ๐ ๏ธ Troubleshooting Masterlist: Every known edge case and its fix.
- ๐งช Stability Benchmark: Comparative results against ResNet and DenseNet.
[!NOTE] mHC is currently in version 0.5.0. It is an "Experimental-Grade" library used in production stability research.