Skip to content

deepseek41 : add bounded routed expert execution - #6

Draft
ajaxdude wants to merge 22 commits into
jeromecoste-microsoft-deepseek-v41-engram-runtimefrom
jeromecoste-microsoft-deepseek-v41-expert-execution
Draft

ajaxdude wants to merge 22 commits into
jeromecoste-microsoft-deepseek-v41-engram-runtimefrom
jeromecoste-microsoft-deepseek-v41-expert-execution

Conversation

@ajaxdude

@ajaxdude ajaxdude commented Sep 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • register all 40 x gate/up/down DeepSeek V4.1 routed tensors as external before ordinary allocation, mmap, prefetch, and warm paths
  • allocate fixed per-layer resident slot tensors and stage exact IQ2_XXS gate/up and Q2_K down bytes through the accepted bounded expert store
  • preserve original expert IDs for routing weights, normalization, bias, scales, telemetry, and traces; use resident slot IDs only for expert tensor lookup
  • retain the ordinary single build_moe_ffn() reduction order; this does not port or enable wave-prefill
  • hold move-only cache leases through backend upload and expert-kernel completion, with synchronized cleanup on graph failure
  • require explicit nonzero --expert-cache-slots and --expert-cache-mib; the DeepSeek V4.1 production path requires strict direct I/O and never selects buffered mode
  • select cache buffers by probing the actual native-quantized MUL_MAT_ID operation

Execution design

A CPU-pinned remap node observes selected original IDs, acquires the deduplicated gate/up/down union atomically, stages complete native payloads into fixed slots, uploads every plane, and publishes the original-ID-to-slot mapping only after all work succeeds. The existing MoE graph keeps original IDs for routing and passes slot IDs only to ggml_mul_mat_id. The completion dependency releases each layer lease only after the final expert backend work completes.

Callback failures publish in-range slot zero as a temporary sentinel, never -1, so already-queued MUL_MAT_ID nodes cannot index outside the cache tensors. The original error remains recorded; evaluation synchronizes the graph, reports failure, and then releases leases. Reads complete before any resident eviction, and pin publication reserves all required storage before incrementing pins, so short reads, upload failures, and allocation failures cannot publish partial slots.

Grovemoe keeps full expert IDs for probability gathers and derives chunk-local IDs only for tensor lookup. Shared and dense experts remain on the ordinary path. Gate/up remain IQ2_XXS and down remains Q2_K; no dequantization or GGUF change is introduced.

The remap design follows ggml-org#25294 commit 4260e4608; lease safety follows ggml-org#27861 commit bccbacdb8. The implementation reuses the accepted expert-store core from #4.

Stack and reconciliation

  • Tracks Feature Request: support DeepSeek V4.1 Flash with bounded SSD expert caching halo-box/strix-llama.cpp#48.
  • Stacked on accepted deepseek41 : add disk-backed Engram runtime #5 head 0fa6b96b2b647500e6033eb28ceebdcbdb40d89f, tree ab683c8b7f6fc0e0636bcb5d18123da5571bec3a.
  • Includes accepted llama : add bounded routed expert store #4 head f8d537e3642eb03539c5e840a929e86a76dde134, parent 8805ae2d415e2ecc155a105659a9d49072550807, tree a85d80bc4356981a9e5da1ab236f766961d082dc.
  • Reconciled by two ordinary merge commits with full ancestry and no rebase or force-push.
  • First merge: b18148f1a4b5f0a1bd1764bbe4af4694ca24ff8a, tree aee2d1db0b2839ccc1ef912927c64f06f88d96b7, parents c4bab9a74c37ded9ef5b92eda4e81d3ed2ed797f and 0fa6b96b2b647500e6033eb28ceebdcbdb40d89f.
  • Reconciled technical head 3089e0a6ba13c536d2e02d56461fd8deb18b661d, tree 8c87d1f970caa80d84c89b7a7005d98094b0a1bf, parents b18148f1a4b5f0a1bd1764bbe4af4694ca24ff8a and f8d537e3642eb03539c5e840a929e86a76dde134, is provenance-ineligible because it and b18148f1a4b5f0a1bd1764bbe4af4694ca24ff8a lack Copilot-Session.
  • Provenance successor f5626396d04804ad309b07670e91b6c313fc1057, tree 8c87d1f970caa80d84c89b7a7005d98094b0a1bf, parent 3089e0a6ba13c536d2e02d56461fd8deb18b661d, is preserved but technically superseded after review found allocation-unsafe pin publication in its unchanged tree.
  • Technical head 6bdd97133e1209c2aa761b7e11ebb76da31828ac, tree 412a656b787d7f9bcff41fd4dd45d6f7f4889df9, parent f5626396d04804ad309b07670e91b6c313fc1057, is preserved but superseded after exact review found async staging resources were not released on cancellation, partial setup, or exceptions.
  • Current head: 83024f92db6b344b55f75103c43507788d853b0a, tree 4f051a9422f9c8db90100fc7883efd29c71cf6f0, parent 6bdd97133e1209c2aa761b7e11ebb76da31828ac. It has parsed Assisted-by, Copilot-Session, and Co-authored-by trailers. No predecessor review or hosted check transfers.
  • Diff from the previously reviewed PR deepseek41 : add bounded routed expert execution #6 head c4bab9a74c37ded9ef5b92eda4e81d3ed2ed797f: 14 files, 344 insertions, 67 deletions; binary diff SHA-256 cf8aa667432fd9fc827ebea369084654be030aa8a2d428db6cb523a4010741c5; stable patch-id be4a28ec1ee36a02781c4b1765c81ba79dfe5682.
  • Direct pin-publication fix from f5626396d04804ad309b07670e91b6c313fc1057 to 6bdd97133e1209c2aa761b7e11ebb76da31828ac: binary diff SHA-256 322b15961771fb68c3d4c2eb6cf971a68f7ea175a134be13e4df9df762afba25; stable patch-id 3ec88c433234923912412f8d499ec66f411ea041.
  • Direct staging-cleanup fix from 6bdd97133e1209c2aa761b7e11ebb76da31828ac: binary diff SHA-256 771728378f0deb91b2b20da762799cbcd72ffc89c590c4ac36fcef03c56f6ca6; stable patch-id b87015a3be19342f3a6a1de7900a2fb3d202ec1e.

The PR #4 exact-head acceptance was recorded for reviewer final-expert-review agent 7dd1c30d-9427-4f56-a850-ac419d2c7426, Turn 2, with no blockers. Two later-created local custody artifacts corroborate that disposition:

  • expert-store-final-review.txt: SHA-256 a53e97a70958e22f6c58b8f1d6102f5f20144d30e8b982048c94528aef4bb01e, size 1113, mode 0444.
  • pr4-f8d537e-review-transcript.md: SHA-256 becea28e7bc59a5f6402ca2331466591b753bed067359d072f5e2c7fba833870, size 4418, mode 0444.

These artifacts are local, unsigned, non-append-proof custodian preservations. Neither is an authenticated raw Turn 2 transcript, and the original background-agent context was unavailable.

Local validation

Passed on exact head 83024f92db6b344b55f75103c43507788d853b0a, tree 4f051a9422f9c8db90100fc7883efd29c71cf6f0, on macOS with CPU, Accelerate, Metal, and mock paths where applicable:

  • Python DeepSeek V4.1 schema unittest: 4 tests.
  • test-deepseek41-schema
  • test-deepseek41-engram
  • test-deepseek41-expert
  • test-deepseek41-runtime
  • test-engram
  • test-expert-store
  • test-arg-parser
  • test-llama-archs -a grovemoe
  • test-llama-archs -a qwen4exp
  • git diff --check

The model-free expert coverage includes all 120 routed tensor registrations, exact plane extents and offsets, duplicate IDs and multi-token unions, original-ID/slot-ID separation, exact native upload bytes, over-capacity rejection before graph execution, failed read/upload atomicity, real MUL_MAT_ID execution after injected callback failure, lease pinning through simulated backend completion, deterministic eviction, Grovemoe lookup separation, shared-expert exclusion, strict external-hole advice policy, allocation-failure rollback without leaked pins, and explicit cache configuration gates. A focused review found that vector allocation after incrementing a logical slot pin could leak an untracked pin and permanently reduce cache capacity. Head 6bdd97133e1209c2aa761b7e11ebb76da31828ac prepares all allocating pin/remap/active vectors before pin mutation, publishes them with moves, and adds an injected std::bad_alloc regression proving the sole slot remains replaceable. Its exact review then found raw async staging buffers, events, and the upload backend could leak on cancellation, partial setup, or exceptions. Head 83024f92db6b344b55f75103c43507788d853b0a scopes those resources under deterministic cleanup, preserves event-buffer-backend teardown order, and cleans partial setup before synchronous fallback. Reviews and hosted checks for predecessors are superseded and non-transferable. Fresh exact-head reviewer 57bd532f-ba1f-41c5-a85e-36c7136f33ab returned ACCEPT at 97% confidence for 83024f92db6b344b55f75103c43507788d853b0a, including partial setup, cancellation after staging begins, exception unwind, normal cleanup, synchronization/free ordering, and double-reset safety. The local read-only custodian artifact is SHA-256 acd39a8dc8c87468f24994a7c1909748dcd4b890ab786d6f668bbda31da6881b, size 1102, mode 0444; it is later-created, local, unsigned, and non-append-proof, not a raw signed transcript. Exact-head hosted labeler, Ubuntu, and Windows checks passed. Python type-check did not trigger for the final C++-only descendant; the local Python schema suite passed.

The generic architecture harness still intentionally skips DeepSeek41 published-model construction, so no DeepSeek41 no_alloc architecture result is claimed. That downstream enablement is outside this PR.

Unverified and incomplete

  • No Strix or ROCm run.
  • No real model or GGUF load.
  • No inference or full-logit DeepSeek comparison.
  • No automatic memory admission or 116 GiB host fitting.
  • No large-prefill adaptation.
  • The existing DeepSeek V4.1 attention/state graph dependency remains gated, so this PR validates the bounded expert layer but does not enable end-to-end model execution.

Written by GPT-5.6 Sol. Local tests were run on an Apple M5; no performance claim is made.

Jerome Coste and others added 7 commits September 12, 2026 08:44
Adapt the positional I/O and cache reservation design from ggml-org#25294, with lease-based in-flight safety informed by ggml-org#27861.

Assisted-by: GPT-5.6 Sol

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Stop aligned reads once the complete expert payload is available and make buffered fallback explicit opt-in so page-cache growth cannot bypass the production memory budget.

Assisted-by: GPT-5.6 Sol

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Report direct I/O unavailable until the Windows file path supports FILE_FLAG_NO_BUFFERING, and cover strict failure plus explicit buffered opt-in.

Assisted-by: GPT-5.6 Sol

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Adapt the positional I/O and cache reservation design from ggml-org#25294, with lease-based in-flight safety informed by ggml-org#27861.

Assisted-by: GPT-5.6 Sol

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Stop aligned reads once the complete expert payload is available and make buffered fallback explicit opt-in so page-cache growth cannot bypass the production memory budget.

Assisted-by: GPT-5.6 Sol

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Report direct I/O unavailable until the Windows file path supports FILE_FLAG_NO_BUFFERING, and cover strict failure plus explicit buffered opt-in.

Assisted-by: GPT-5.6 Sol

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Assisted-by: GPT-5.6 Sol

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Merge the current schema branch and preserve the expert-store source registration in the new core source list.

Assisted-by: GPT-5.6 Sol

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Jerome Coste and others added 3 commits September 12, 2026 20:21
Preserve bounded expert execution across the attention/Engram restack and fix failure-safe remapping, Grovemoe lookup IDs, and lease release ordering.

Assisted-by: GPT-5.6 Sol

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Merge the updated schema support branch with the normal-RoPE classification needed by the shared model loader.

Assisted-by: GPT-5.6 Sol

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Retain bounded expert execution safety fixes and select cache buffers using the native quantized MUL_MAT_ID operation.

Assisted-by: GPT-5.6 Sol

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@ajaxdude
ajaxdude marked this pull request as ready for review September 14, 2026 01:37
Jerome Coste and others added 6 commits September 14, 2026 00:18
Merge the current schema support branch before final expert-store review and validation.

Assisted-by: GPT-5.6 Sol

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Load contexts that cross disk-owned holes without mmap, discard copied source pages where supported, preserve mlock for safe mapped spans, and make lease publication allocation-safe.

Assisted-by: GPT-5.6 Sol

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use random file advice when disk-owned tensor ranges are excluded so Linux readahead cannot cross into the expert corpus.

Assisted-by: GPT-5.6 Sol

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Keep lazy-table prefetch behavior unchanged, but give external routed tensors a strict policy that disables positive prefetch ranges on every platform.

Assisted-by: GPT-5.6 Sol

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Throw before mmap when POSIX_FADV_RANDOM cannot be applied to an external-hole file. Keep legacy sequential advice warning-only and cover both paths through an injectable constructor seam.

This successor binds corrective commits 9b53142 and c1a00d2, including c1 tree 56460c3.

Assisted-by: GPT-5.6 Sol

Copilot-Session: 6df503f4-c9eb-436d-a324-e8c5f8cabed9

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Binds fail-closed corrective head 8805ae2 and its tree a85d80b without source changes.

Assisted-by: GPT-5.6 Sol
Copilot-Session: 6df503f4-c9eb-436d-a324-e8c5f8cabed9
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@ajaxdude
ajaxdude marked this pull request as draft September 14, 2026 08:33
Jerome Coste and others added 5 commits September 14, 2026 01:33
Merge exact accepted PR #5 head 0fa6b96 without changing bounded routed-expert execution.

Assisted-by: GPT-5.6 Sol

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Merge exact accepted PR #4 head f8d537e while retaining transactional expert replacement, file metadata, Windows test guards, and bounded DeepSeek V4.1 execution.

Assisted-by: GPT-5.6 Sol

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Binds rejected provenance parent 3089e0a and its unchanged tree 8c87d1f.

The parent reconciles merge commit b18148f with accepted expert-store head f8d537e. The merge ancestry contains accepted Engram runtime head 0fa6b96.

Assisted-by: GPT-5.6 Sol
Copilot-Session: 9d10038c-5360-458f-b024-26761335c596
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Prepare every allocating remap and pin-tracking vector before changing slot pin counts. Publish the prepared state with moves so allocation failure cannot leak an untracked pin or reduce cache capacity.

Add an injected allocation-failure regression that replaces the sole slot after the failed publication.

Assisted-by: GPT-5.6 Sol
Copilot-Session: 9d10038c-5360-458f-b024-26761335c596
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Own async upload buffers, events, and the upload backend for the full load scope. Clean partial setup immediately and synchronize/free all resources on cancellation, exceptions, and normal completion.

Assisted-by: GPT-5.6 Sol
Copilot-Session: 9d10038c-5360-458f-b024-26761335c596
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant