mhc-algorithm
Implement mHC (Manifold-Constrained Hyper-Connections) for stabilizing deep network training
Install / Use
npx skills add benchflow-ai/skillsbench --skill mhc-algorithmInstalls into whichever agent you are using.
SKILL.md
Installable skill definition
Quality Score
Category
Development & EngineeringSupported Platforms
Tags
Our assessment of mhc-algorithm
mhc-algorithm scores 85/100 on our quality scale, 1792nd of 3,997 Development & Engineering skills we index (top 45%).
Its SKILL.md is 4.0 KB long, well organised into 9 sections with 3 code examples: a solid amount of guidance for an agent.
With 1,813 GitHub stars, it is one of the more widely adopted skills in the catalogue.
Maintenance, license and trust
- The repository was last updated about 2 months ago, so mhc-algorithm is actively maintained.
- It is released under the Apache-2.0 license, a permissive license that allows use, modification and commercial use with attribution.
- Its trust signals score 100/100, with no cautions. These come from repository metadata, not a code audit — read the skill file before letting an agent act on it.
mhc-algorithm compared with similar skills
All 4 of these similar skills score higher than mhc-algorithm; compare them before choosing.
| Skill | Score | Stars | Updated | Format |
|---|---|---|---|---|
| mhc-algorithm (this skill)by benchflow-ai | 85 | 1.8k | 2mo ago | SKILL.md |
| ai-job-searchby MadsLorentzen | 100 | 44.6k | today | CLAUDE.md |
| claude-howtoby luongnv89 | 100 | 41.7k | today | CLAUDE.md |
| algorithmic-artby anthropics | 100 | 177.9k | 7d ago | SKILL.md |
| pptxby anthropics | 100 | 177.9k | 7d ago | SKILL.md |
Frequently asked questions
- How do I install mhc-algorithm?
- Run
npx skills add benchflow-ai/skillsbench --skill mhc-algorithm. The install tabs above show the steps for each supported agent. - Which AI agents does mhc-algorithm work with?
- It is written for Universal, as a SKILL.md file. Other agents that read the same format can often use it too.
- Is mhc-algorithm safe to use?
- It is Apache-2.0-licensed and scores 100/100 on trust signals. Skills are instructions an agent will follow, so read the file before installing it and do not approve commands you do not understand.
- Is mhc-algorithm still maintained?
- The repository was last updated about 2 months ago, so mhc-algorithm is actively maintained.
Skill content
View source on GitHubname: mhc-algorithm description: 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).
mHC: Manifold-Constrained Hyper-Connections
Overview
mHC (Manifold-Constrained Hyper-Connections) stabilizes deep network training by constraining residual mixing matrices to be doubly stochastic. It provides:
- Stable Training: Lower gradient norm variance via doubly stochastic constraints
- Multiple Streams: Hyper-Connections with learnable mixing across residual streams
- Sinkhorn Projection: Log-space Sinkhorn-Knopp algorithm for doubly stochastic projection
- GPT Integration: Pattern for wrapping attention and MLP layers
Two components:
- HyperConnections Module: Core PyTorch module with H_res, H_pre, H_post matrices
- Sinkhorn-Knopp: Log-space projection to doubly stochastic manifold
Quick Reference
| Topic | Reference | |-------|-----------| | Core Concepts & Math | Core Concepts | | Sinkhorn Algorithm | Sinkhorn-Knopp | | HyperConnections Module | Module Implementation | | GPT Integration | GPT Integration | | Common Pitfalls | Pitfalls |
Installation
# Required packages
pip install torch einops numpy
Minimal Example
import torch
import torch.nn as nn
from einops import rearrange, einsum
def sinkhorn_knopp(logits, num_iters=20, tau=0.05):
log_alpha = logits / tau
for _ in range(num_iters):
log_alpha = log_alpha - torch.logsumexp(log_alpha, dim=-1, keepdim=True)
log_alpha = log_alpha - torch.logsumexp(log_alpha, dim=-2, keepdim=True)
return torch.exp(log_alpha)
class HyperConnections(nn.Module):
def __init__(self, num_streams, dim, branch=None, layer_idx=0):
super().__init__()
self.num_streams = num_streams
self.branch = branch
# Initialize H_res near identity (use small negative for gradient flow)
init_h_res = torch.full((num_streams, num_streams), -0.1)
init_h_res.fill_diagonal_(0.0)
self.H_res_logits = nn.Parameter(init_h_res)
# H_pre/H_post for depth connections
init_h_pre = torch.full((1, num_streams), -0.1)
init_h_pre[0, layer_idx % num_streams] = 0.0
self.H_pre_logits = nn.Parameter(init_h_pre)
self.H_post_logits = nn.Parameter(torch.zeros(1, num_streams))
def forward(self, x):
s = self.num_streams
x = rearrange(x, "(b s) t d -> b t s d", s=s)
h_res = sinkhorn_knopp(self.H_res_logits)
x_mixed = einsum(h_res, x, "s t, b n s d -> b n t d")
h_pre = self.H_pre_logits.softmax(dim=-1)
branch_in = einsum(h_pre, x, "v s, b n s d -> b n v d").squeeze(-2)
branch_out = self.branch(branch_in) if self.branch else branch_in
h_post = self.H_post_logits.softmax(dim=-1)
depth_out = einsum(branch_out, h_post, "b t d, v s -> b t s d")
output = x_mixed + depth_out
return rearrange(output, "b t s d -> (b s) t d")
Common Imports
import torch
import torch.nn as nn
import torch.nn.functional as F
from einops import rearrange, einsum, repeat, reduce
When to Use What
| Scenario | Approach | |----------|----------| | Standard residual connection | No mHC needed | | Deep networks (>12 layers) with stability issues | Use mHC with num_streams=4 | | GPT/Transformer training | Wrap both attention and MLP with HyperConnections | | Custom Sinkhorn iterations | Adjust num_iters (20 default) and tau (0.05 default) | | Memory-constrained training | Reduce num_streams or batch size |
External Resources
- mHC Paper: https://arxiv.org/abs/2512.24880
- Hyper-Connections: https://arxiv.org/abs/2409.19606
- Sinkhorn's Theorem: https://en.wikipedia.org/wiki/Sinkhorn%27s_theorem
Related Skills
ai-job-search
44.6kThe job search that runs on your machine. AI job application framework built on Claude Code: evaluate postings, tailor CVs, write cover letters, prep interviews. Fork it and own it.
claude-howto
41.7kA visual, example-driven guide to Claude Code — from basic concepts to advanced agents, with copy-paste templates that bring immediate value.
algorithmic-art
177.9kCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems.
pptx
177.9kUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an em…
Languages
Trust signals
From repository metadata: license, adoption, age and documentation. Not a code audit — see the Safety scan above for what the skill file itself contains.
