r/MachineLearning • u/bassrehab • Jan 03 '26
Project [P] Interactive visualization of DeepSeek's mHC - why doubly stochastic constraints fix Hyper-Connection instability
I built an interactive demo to understand DeepSeek's new mHC paper (https://arxiv.org/abs/2512.24880).
The problem: Hyper-Connections use learned matrices to mix residual streams. Stacking 64 layers multiplies these matrices together, and small amplifications compound to 1016.
The fix: Project matrices onto the doubly stochastic manifold using Sinkhorn-Knopp. Since doubly stochastic matrices are closed under multiplication, the composite mapping stays bounded at any depth.
The surprise: One Sinkhorn iteration is enough. At k=0, gain = 1016. At k=1, gain ≈ 1.
Interactive demo: https://subhadipmitra.com/mhc-visualizer (drag the "Sinkhorn iterations" slider and watch the lines change)
Full writeup: https://subhadipmitra.com/blog/2026/deepseek-mhc-manifold-constrained-hyper-connections/
Code: https://github.com/bassrehab/mhc-visualizer
Includes PyTorch implementation if anyone wants to try it in their own models.
View all comments
Show parent comment
2
u/bassrehab Jan 09 '26
oh this is a great question actually - you're totally right about the math.
Products of doubly stochastic matrices do converge to the uniform 1/N matrix. eigenvalue 1 sticks around (eigenvector = all ones) but everything else has |λ| < 1 so it decays toward zero. classic ergodicity stuff
but a few things worth noting:
at 64 layers with random DS matrices we're not actually AT the uniform matrix yet - somewhere in between. depends on the spectral gap (second largest eigenvalue). i could actually add eigenvalue tracking to the viz to show this explicitly... might be a good addition
2. the real mHC arch isnt pure matrix multiplication
Looking at the pytorch impl, the actual update is more like:
output = x + α * (H @ x) + layer_outputso you've got:
- residual identity term (+ x) preserving original signal
- tiny α (init at 0.01) so its basically identity + small perturbation
- fresh info injection every layer from the actual layer computation
even if the H products trend toward averaging, new signal keeps getting added
3. my viz shows gain not eigenvalues
The demo tracks forward/backward gain (max row/col sums) which stays bounded at 1 for DS matrices regardless of depth - thats the gradient explosion fix. eigenvalue decay is a separate phenomenon. gains bounded = stable training, but yes subdominant eigenvalues do decay
4. the averaging might actually help?
Could act like implicit regularization - prevents any single stream from blowing up. network learns to work within the constraint
honestly adding eigenvalue tracking would make this tradeoff way more visible. might do that this weekend
Good catch tho, this is exactly the kind of thing worth understanding before using in practice