feat(compute): Hyper-Connection forward pass (DSV4 Phase 2) - #67
Merged
Conversation
Implement the HC (Hyper-Connections) structural backbone for DeepSeek-V4-Flash. HC replaces standard residual connections with a 4-copy hidden state [seq, hc_mult, d] that flows through every layer. New module: forward/hyper_connection.rs - hc_expand: initialize HC dimension from [seq, d] → [seq, hc, d] - hc_pre: reduce hc_mult→1 via RMSNorm → linear projection → sigmoid/Sinkhorn split - pre = sigmoid(mixes_pre * scale + base) + eps - post = 2 * sigmoid(mixes_post * scale + base) - comb = softmax → Sinkhorn-normalized (configurable iters, default 20) - y = sum(pre * x, dim=hc) → [seq, d] - hc_post: expand 1→hc_mult via weighted residual mixing - y = post * x + sum(comb * residual, dim=hc) → [seq, hc, d] - hc_head: final-layer sigmoid-based reduction (no Sinkhorn) - Uses [1] scale instead of [3] - 22 unit tests covering shapes, finiteness, Sinkhorn doubly-stochastic property, round-trip, and V4-Flash realistic dimensions (hidden=4096, hc=4) This is the structural backbone — nothing in V4-Flash works without it. Attention and FFN blocks operate between hc_pre and hc_post.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DeepSeek-V4-Flash Phase 2: Hyper-Connections (HC) — the structural backbone.
HC replaces standard residual connections with a 4-copy hidden state
[seq, hc_mult, d]that flows through every layer. Each block hashc_pre(reduce hc_mult→1) before attention/FFN andhc_post(expand 1→hc_mult) after. The final layer useshc_head(sigmoid-based, no Sinkhorn).New module:
forward/hyper_connection.rshc_expand(h, hc_mult): Initialize HC dimension from[seq, d]→[seq, hc, d]hc_pre(x_hc, params, iters, eps): Reduce[seq, hc, d]→[seq, d][seq, hc*d][seq, mix_hc]wheremix_hc = (2+hc)*hc = 24pre = sigmoid(mixes * scale[0] + base) + epspost = 2 * sigmoid(mixes * scale[1] + base)comb = softmax(mixes * scale[2])→ Sinkhorn-normalized (alternating row/col, 20 iters)y = sum(pre * x, dim=hc)— weighted reductionhc_post(x, residual, post, comb): Expand[seq, d]→[seq, hc, d]y = post * x + sum(comb * residual, dim=hc)— weighted expansion + residual mixinghc_head(x_hc, params, eps): Final-layer reduction[seq, hc, d]→[seq, d][1]scale (not[3]), sigmoid-based (no Sinkhorn)HC parameter shapes (hc_mult=4, hidden=4096)
Tests (22 total)
Test results (Valinor RTX 3060, Rust 1.97.0)
Phase context