mhc-algorithm
Implement mHC (Manifold-Constrained Hyper-Connections) for stabilizing deep network training.
Skill by benchflow-ai
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/benchflow-ai-mhc-algorithm
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: research
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/mhc-algorithm
What's inside
- Skill name
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).
- License
- Apache-2.0
- Instructions
- 108 lines in SKILL.md · view on GitHub
Files (6)
- SKILL.md
- core-concepts.md · references/
- gpt-integration.md · references/
- module-implementation.md · references/
- pitfalls.md · references/
- sinkhorn-knopp.md · references/
SKILL.md (first lines)
# 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](references/core-concepts.md) |
| Sinkhorn Algorithm | [Sinkhorn-Knopp](references/sinkhorn-knopp.md) |
| HyperConnections Module | [Module Implementation](references/module-implementation.md) |
| GPT Integration | [GPT Integration](references/gpt-integration.md) |
| Common Pitfalls | [Pitfalls](references/pitfalls.md) |
## Installation
```python
# Required packages
pip install torch einops numpy
```
## Minimal Example
```python
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
```python
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_theoremFrom benchflow-ai/skillsbench, Apache-2.0.
More from benchflow-ai/skillsbench
- 0.552score
grpo
benchflow-ai
Reference for the GRPO (Group Relative Policy Optimization) algorithm.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
rl-post-training
benchflow-ai
Diagnostic guide for RL-based post-training of language models (GRPO, PPO, REINFORCE, DPO).
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
d3-visualization
benchflow-ai
Build deterministic, verifiable data visualizations with D3.js (v6).
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
task-review
benchflow-ai
SkillsBench task PR review — classifies the task track (standard / research / multimodal), runs static policy checks against the track-specific rubric…
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
mesh-analysis
benchflow-ai
Analyzes 3D mesh files (STL) to calculate geometric properties (volume, components) and extract attribute data.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
hex-grid-spatial
benchflow-ai
Hex grid spatial utilities for offset coordinate systems.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
modal-gpu
benchflow-ai
Run Python code on cloud GPUs using Modal serverless platform.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
civ6lib
benchflow-ai
Civilization 6 district mechanics library.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
transaction-concurrency-control-foundations
benchflow-ai
Provides database transaction concurrency-control background.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
search-accommodations
benchflow-ai
Lookup accommodations by city from the bundled dataset.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
search-attractions
benchflow-ai
Retrieve attractions by city from the bundled dataset.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
trl
benchflow-ai
Reference for the TRL (Transformer Reinforcement Learning) library codebase.
SkillCFreshness: C★ 1.9KClaude Code +9
Signals
- Stars
- 1,870
- Forks
- 372
- Open issues
- 50
- Last commit (this folder)
- May 30, 2026 (5 months ago)
- Last release
- Jun 14, 2026 (4 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- Apache-2.0
- Repository
- github.com/benchflow-ai/skillsbench
- Website
- www.skillsbench.ai
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from benchflow-ai
- 0.552score
transaction-concurrency-control-foundations
benchflow-ai
Provides database transaction concurrency-control background.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
search-accommodations
benchflow-ai
Lookup accommodations by city from the bundled dataset.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
search-attractions
benchflow-ai
Retrieve attractions by city from the bundled dataset.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
task-review
benchflow-ai
SkillsBench task PR review — classifies the task track (standard / research / multimodal), runs static policy checks against the track-specific rubric…
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
modal-gpu
benchflow-ai
Run Python code on cloud GPUs using Modal serverless platform.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
mesh-analysis
benchflow-ai
Analyzes 3D mesh files (STL) to calculate geometric properties (volume, components) and extract attribute data.
SkillCFreshness: C★ 1.9KClaude Code +9
Cite this page
mhc-algorithm skill. Agent Mart. https://agentmart.dev/skills/benchflow-ai-mhc-algorithm (last updated 2026-10-24)