mhc-algorithm
Agent skill frombenchflow-ai/skillsbench
Implement mHC (Manifold-Constrained Hyper-Connections) for stabilizing deep network training. Use when implementing residual connection improvements with doubly stochastic matrices via Sinkhorn-Knopp algorithm. Based on DeepSeek's 2025 paper (arXiv:2512.24880).
How to install mhc-algorithm
install mhc-algorithm
# install the skillsbench pack with the skills CLI
npx skills add benchflow-ai/skillsbench# or add only this skill to Claude Code: copy the folder
tasks-extra/mhc-layer-impl/environment/skills/mhc-algorithm/
# into
~/.claude/skills/mhc-algorithm/ (all projects)
.claude/skills/mhc-algorithm/ (one project)
1# mHC: Manifold-Constrained Hyper-Connections23## Overview45mHC (Manifold-Constrained Hyper-Connections) stabilizes deep network training by constraining residual mixing matrices to be **doubly stochastic**. It provides:67- **Stable Training**: Lower gradient norm variance via doubly stochastic constraints8- **Multiple Streams**: Hyper-Connections with learnable mixing across residual streams9- **Sinkhorn Projection**: Log-space Sinkhorn-Knopp algorithm for doubly stochastic projection10- **GPT Integration**: Pattern for wrapping attention and MLP layers1112Two components:13- **HyperConnections Module**: Core PyTorch module with H_res, H_pre, H_post matrices14- **Sinkhorn-Knopp**: Log-space projection to doubly stochastic manifold1516## Quick Reference1718| Topic | Reference |19|-------|-----------|20| Core Concepts & Math | [Core Concepts](references/core-concepts.md) |21| Sinkhorn Algorithm | [Sinkhorn-Knopp](references/sinkhorn-knopp.md) |22| HyperConnections Module | [Module Implementation](references/module-implementation.md) |23| GPT Integration | [GPT Integration](references/gpt-integration.md) |24| Common Pitfalls | [Pitfalls](references/pitfalls.md) |2526## Installation2728```python29# Required packages30pip install torch einops numpy31```3233## Minimal Example3435```python36import torch37import torch.nn as nn38from einops import rearrange, einsum3940def sinkhorn_knopp(logits, num_iters=20, tau=0.05):41 log_alpha = logits / tau42 for _ in range(num_iters):43…
Excerpt shown under the repository's Apache-2.0 license.
