Repository navigation
feat(bailing_hybrid): Ling-3.0 KDA + MLA hybrid MoE backbone (P0, #672) - #759
Merged
Merged
Conversation
… recurrent state, so Inkling 2's conv ArraysCache does not turn on anchor search (#672 review) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012cicguZMN3jhNGmf5327oh
Owner
Author
|
Review at the owner's request. Rebased on main 4ca5435 (#733), plus one fix commit:
Run locally on the rebased branch: BailingHybrid, GenerationPlan, PromptCache, Inkling, BatchedDecodingIsolation, TokenTrace, FeatureMatrix, ModelProfile, KVCacheGeometry and Anatomy. 211 tests, all pass. The fixture move to |
goodmai
force-pushed
the
feat/672-bailing-hybrid-p0
branch
from
November 24, 2026 10:22
0a11408 to
b2a9b0e
Compare
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.
Part of #672 (Phase P0: runnable
bailing_hybridbackbone in plain MLX ops + tiny parity & all-family integration).Summary
Sources/BasaltInference/Models/BailingHybrid/):BailingHybridConfiguration.swift:Codable,Sendable,Equatableconfig supportingshort_conv_kernel_size/conv_kernel_size,no_kda_lora/use_kda_lora, MLA LoRA / RoPE / head-wise or element-wise output gate granularity,noaux_tcMoE routing,isMLALayer(_:)group + trailing remainder schedule, andvalidated()typed throws.BailingHybridKDA.swift: Kimi Delta Attention with causal depthwise short-conv (*_conv1d.conv.weight[C, K, 1], fp) + SiLU + rolling history inArraysCache(size: 4)slots 0–2, L2-normalizedq/k(x / (||x|| + 1e-6)) withqscaled byd^-0.5, fp32 per-channel safe gatelowerBound * sigmoid(exp(A_log) * (f + dt_bias))(plus softplus fallback & full/LoRA gate projections), fp32 delta-rule recurrence in slot 3, gatedo_norm->o_proj.BailingHybridMLA.swift: DeepSeek-V3-style MLA (q_a_proj/q_a_layernorm/q_b_projor directq_proj,kv_a_proj_with_mqa/kv_a_layernorm/kv_b_proj), interleaved RoPE (traditional: ropeInterleave) withcache?.ropeOffset,attentionWithCacheUpdate, head-wise / element-wise output gatesigmoid(g_proj(x)), anddenseoutput projection.BailingHybridMoE.swift: Sigmoid router withexpert_bias+noaux_tcgroup selection (top-topk_groupgroups by sum of top-2 biased scores, top-kexperts, unbiased normalized sigmoid weights ×routed_scaling_factor), stackedSwitchGLUexperts (experts), optionalshared_experts, and dense SwiGLU forlayer < first_k_dense_replace.BailingHybridModel.swift: Decoder layer, inner model,BailingHybridModel(LLMModel,KVCacheDimensionProvider,LoRAModel,BasaltProbableModel,toolCallFormat: .glm4), hybridnewCache(ArraysCache(size: 4)on KDA,KVCacheSimpleon MLA),sanitize(weights:)(drops MTP / out-of-range layers / tiedlm_head/ disabledexpert_bias, atomically stacks unmerged experts, canonicalizes 2D & 3D conv weights, callsFlintModel.quantizeModulesMatchingPackedWeights)."bailing_hybrid"inLLMTypeRegistryandVLMTypeRegistryviaMLXInferenceEngine.registerBailingHybridAliases().ModelCapabilitiesrow ([.batchedDecode, .promptCacheReuse, .grammarJumpForward]; lookup, KV quantization/zones/head-split, Quest, MTP, CacheBlend stay off for P0).BailingHybridProfile(<think>/</think>,enable_thinking,detailed thinking on|off,16_384default max tokens) and table-driven exact lookup inModelProfileRegistry.KVCacheGeometry(layer_group_size+kv_lora_rankschedule and KDA fixed state bytes),AnatomyScan(word_embeddings,.experts., reflected linear-attention heads), andMLXInferenceEngine.cacheIsHybrid(ArraysCacherecurrent-state detection so multi-turn anchor snapshots activate).TinyModel.Family.bailingHybrid(6 layers[KDA, KDA, MLA] × 2,head_dim = 32, 8 experts top-2 in 4 groups keep 2,first_k_dense_replace = 1) and wired all-family suites (TinyModelFixtureTests,CausalityTests,FeatureMatrixTests,TokenTraceParityTests,BatchedDecoderTests,BatchedRoutingTests,GenerationPlanTests).BailingHybridTests.swiftandBailingHybridIntegrationTests.swiftcovering CPU reference parity (< 1e-5), full vs chunked (1, 3, 7) decode parity (< 1e-4, exact greedy IDs), optional architecture variants, packed-weightsanitize&ModelDeepCheck/ModelInspectorround-trip, andPromptCacheTree+PromptCacheDiskStoresnapshot parity.7-Round Self-Review Summary
BailingHybridRouter.routeexpertMaskprobe under sigmoid + positiveexpert_bias(mask applied after bias); guarded emptysteps == 0in KDA recurrence and short-conv; matched Metal kernel masked-output zeroing inrecurrentStep; eliminated all force unwraps (!); moved MLAForwardProbe.headOutputspost-gate to match KDA; added evenqk_rope_head_dimvalidation.sanitizeedge cases: MadestackExpertPartatomic (verify all experts present before mutating dict) and removed brittlegate_proj-only gate; tightened MTP key drop prefixes; dropped unusedexpert_biaswhenmoe_router_enable_expert_bias == false; verified dualquantization+quantization_configcheckpoints do not double-quantize.MLXInferenceEngine.cacheIsHybridcheckingMambaCacheinstead ofArraysCache(which disabled multi-turn anchor snapshots forbailing_hybrid); tightenedbailingLinearStateBytespredicate to requirekv_lora_rank; verifiedPromptCacheDiskStoresave/load round-trip parity.Sendablevalues, all MLX objects isolated insideModelContainer.projDim,convKernelSize,qLoraRank,BailingHybridDecoderLayer.layerIdx), added KDAkvHeadsreflection forAnatomyScan, splitModelProfileRegistryexact lookup (CCN 16 → 14), splitMLXInferenceEngine+Loading.swiftextension (≤ 150 NLOC), splitTinyModels/GenerationPlanTests/BailingHybrid*Testsso zero limits exceed or grow.swift build -c release -Xswiftc -warnings-as-errors).origin/main(e35d2a5), passed all static gates and 95 tests across 12 affected suites.Verification Gates
swift scripts/check_no_new_comments.swift origin/main: PASS (No comments added.)swift scripts/check_size_limits.swift origin/main --impact: PASSImpact: 13 Swift file(s) in Sources, 61 of 8258 functions in Sources touched (0.7%), CCN sum 351 → 521, largest CCN 15 → 14No size or complexity limit exceeded or grown.swift scripts/check_concurrency_hatches.swift: PASS (No concurrency hatch outside scripts/concurrency-hatches.allow.)swift build -Xswiftc -warnings-as-errors: PASSswift build -c release -Xswiftc -warnings-as-errors: PASS (318.16s)swift test --maximum-repetitions 5 --repeat-until fail --filter "BailingHybridTests|BailingHybridIntegrationTests": PASS (13 tests × 5 repetitions = 65 runs, 9.33s)swift scripts/check_changed_coverage.swift <codecov> origin/main: PASS (Changed-line coverage: 96.4% (815/845), minimum 60%.)SWT_EXPERIMENTAL_MAXIMUM_PARALLELIZATION_WIDTH=4 swift test --parallel --filter "BailingHybridTests|BailingHybridIntegrationTests|TinyModelFixtureTests|CausalityTests|GenerationPlanTests|TokenTraceParityTests|FeatureMatrixTests|BatchedDecoderTests|BatchedRoutingTests|KVCacheGeometryTests|PromptCacheDiskTests|ModelDeepCheckTests|ModelProfileTests": PASS (95 tests in 12 suites, 215.19s)