Repository navigation
Add Qwen3.5 hybrid architecture and Gated DeltaNet linear attention support - #502
Merged
Merged
Conversation
- Add reusable linear attention / SSM / DeltaNet package (ml/layers/attention/linear) with stateless Core and fluent stateful Builder (GatedDeltaNet, DeltaNet, GLA, Simple). - Support all 6 combinations of decay (none, scalar, channel-wise) and update rule (associative write vs. surgical delta rule with generalized power-of-2 block-recursive WY/UT unit lower-triangular inversion), GVA, static/dynamic sequence lengths, incremental state caching, and unrolled chunk scanning for reverse-mode autodiff. - Add comprehensive package documentation (doc.go) with equations, architecture table, usage examples, and literature links. - Add unit, float64 token-by-token parity, prefill/decode state parity, padding mask, and finite-difference autodiff gradient tests across Go and XLA backends. - Refactor ml/zoo/transformer/gated_deltanet.go to delegate to linear.GatedDeltaNet. - Update docs/CHANGELOG.md, .agents/AGENTS.md, and skills reference.
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
Reusable Linear Attention / SSM / DeltaNet Package (
ml/layers/attention/linear)ml/layers/attention/linearpackage with rich package documentation (doc.go, including unified recurrence equations, architecture matrix, usage examples, and literature links) and a two-tier API:linear.Core(query, key, value, CoreOptions): unified chunkwise parallel scan andS == 1single-step recurrence supporting all 6 combinations of decay (nil, scalar[B,S,H], channel-wise[B,S,H,Dk]) and update rule (associative write vs. surgical delta rule):linear.Builder: presetsNew/GatedDeltaNet,DeltaNet,GLA, andSimple, configurable projections (in_proj_qkv,in_proj_z,in_proj_a,in_proj_b,out_proj), Grouped Value Attention (WithNumKeyHeads), optional causal depthwise Conv1d (WithShortConv), QK L2 norm, gated/plain RMSNorm, padding masks (WithAttentionMask/WithSeqLen), and incremental prefill+decode state I/O (WithState,WithReturnState,DoneWithState).ops.go):CausalDepthwiseConv1D,RMSNormGated,L2NormLastAxis, andRepeatInterleaveHeads.invertUnitLowerTriangular) generalized for any power-of-2 chunk size>= 2.Whilechunk scan).scope.IsTraining(g)/WithUnrollChunks) so reverse-mode autodiff (core/autodiff.Gradient) works out of the box.Qwen3.5 Hybrid Architecture & KVCache Support
attention.LinearLayerandMultiHeadAttentionBuilder.WithOutputGate(Sigmoid(gate)beforeo_proj) for Qwen3.5 hybrid models.kvcache.KVCachewithLinearStateConfig,ConvStateSuffix,RecurrentStateSuffix,GetLinearState, andSetLinearStatesoLinearLayerscopes store fixed-sizeconv_state([B, K-1, convDim]) andrecurrent_state([B, numVHeads, headKDim, headVDim]) tensors alongside standard KV-cache layers (untouched byPadTensorsand skipped ingenerate'sminCacheCapcalculation).ArchitectureQwen35(ml/zoo/transformer/gated_deltanet.go):RMSNorm(1.0 + weight), per-head(query, gate)split, QK RMSNorm, partial RoPE, and SwiGLU MLP.linear.GatedDeltaNet(...).Verification
ml/layers/attention/lineartests (core_test.go,linear_test.go) pass ongo,xla:cpu, andxla:cuda:TestInvertUnitLowerTriangularacross chunk sizesC = 2, 4, 8, 16, 32, 64TestCoreAllModesMatchReferenceagainst a float64 token-by-token reference across all 6 modes (staticWhile, static unrolled, and dynamicWhile)TestBuilderPresetsPrefillAndDecodeParity(GatedDeltaNet,DeltaNet,GLA,Simple)TestBuilderPaddingMaskEquivalence(WithAttentionMaskvs.WithSeqLen)TestBuilderAutodiffGradientsMatchFiniteDifferences(GatedDeltaNetandGLAmulti-chunk unrolled backward verified against central finite differences on CPU, plus CUDA forward+backward smoke test)ml/layers/attention/...andml/zoo/transformer/...pass ongo,xla:cpu, andxla:cuda, includingTestQwen35HybridModelPrefillAndDecodeParity(full-sequence vs. incremental prefill + step-by-step decode parity +generate.Generator).Qwen/Qwen3.5-4Bingo-huggingface(PR Added inference example for CIFAR-10 demo. #87) for both sentence embedding (msmarco/benchmark_embedwith-dynamic=true) and autoregressive generation (dolly/browse).