Add DeepSeek V4 architecture adapter#1513
Draft
abhinav-bellapu wants to merge 2 commits into
Draft
Conversation
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.
Description
Adds a TransformerBridge architecture adapter for
DeepseekV4ForCausalLM, addressing #1466.DeepSeek V4 does not have a conventional single residual stream or V2/V3-style MLA. It keeps
hc_multresidual streams alive between blocks through manifold-constrained Hyper-Connections (mHC), and interleaves sliding attention with Compressed Sparse Attention (CSA) and Heavily Compressed Attention (HCA). This adapter delegates those model-specific calculations to Transformers for parity, while exposing the internal surfaces needed for interpretability:The block bridge intentionally does not register conventional residual aliases: block-boundary hooks carry
[batch, pos, hc_mult, d_model], so presenting them as an ordinary three-dimensional residual would make patching code silently target the wrong tensor. Collapsed sublayer inputs remain directly patchable atblocks.{i}.attn_hc.hook_outandblocks.{i}.mlp_hc.hook_out.The architecture is registered in the factory and all model-registry sites, and V4-specific compression, mHC, indexer, and router metadata is preserved on
bridge.cfgfor analysis tools.Validation
The integration suite builds a download-free ~40K-parameter
DeepseekV4ForCausalLMspanning all three attention layer types and both router types.atol=0,rtol=0)mypy .: success across 309 source filespycln --check --all,isort --check-only,black --check, andgit diff --check: cleanA broad local unit sweep reached 3,215 passed, 34 skipped, 42 deselected, and 9 expected failures. Its remaining 18 setup errors required unavailable Hugging Face downloads, and one unrelated dataset test was blocked by the local sandbox's shared-memory restriction. CI should provide the clean-environment result.
As scoped in #1466, this PR does not claim full Flash/Pro checkpoint verification: the smallest real checkpoint is 284B total parameters and requires cluster hardware. The tiny model exercises the architecture and numerical parity without that hardware dependency.
Type of change
Checklist