Skip to content

DeepSeek V4.1: validate the R5-A loop adapter on the host - #6149

Closed
francip wants to merge 3 commits into
ashhart:mainfrom
kortexa-ai:kortexa-ai/deepseek-v41-loop-admission
Closed

francip wants to merge 3 commits into
ashhart:mainfrom
kortexa-ai:kortexa-ai/deepseek-v41-loop-admission

Conversation

@francip

@francip francip commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Add an offline host check for the 1017 R5-A sidecar. It validates the pinned manifest and tensor payloads, uses the base TP partition for each projection, and computes the additional resident memory per rank and slot. It defines the loop state key and supplies a serial FP32 entry and projection reference at the BF16 rounding points.

Review follow-up

  • The adapter constructs the result in place. Each successful file open registers cleanup on that field, and a host test rejects a bundle after all three opens with the leak-checking allocator.
  • The entry command reads both inputs into explicitly aligned allocations before taking their BF16 views. The six captured token rows still produce the same output bytes. Synthena’s review
  • Depth one means a single backbone pass with zero loop residency. The loader still checks the entire sidecar before reporting either depth.
  • The entry command validates whole tokens before taking BF16 views, then indexes the input as token, stream, hidden. The recipe now spells out the packing order. The two six-token fixtures matched the previous bytes, and a partial-token fixture failed with BadLoopReferenceRows. Synthena’s follow-up

On this head, the three field-level errdefer statements are in the same function scope as try result.checkWeights(cfg). The allocator-backed fixture exercises that failure after opening all three files. The entry command guards equal lengths and whole-token multiples before taking the BF16 views, and the truncated fixture exercises the guard. Latest review · Cleanup · Row validation

Checks on this head

  • Head 4a863f03c8da496b918a215aaedd46823e235376. The focused zig build test-dsv41-assets-host dsv41-assets --summary all passed 21 build steps and 17 executed tests. Changed-file formatting and diff checks passed.
  • The pinned R5-A bundle reported the same budgets at depths one and two. Both captured entry fixtures still produced SHA-256 c9cb75ad086270e82679a4213543a61ff723c36da6d6425bd7ffcfea3e13181b. The partial-token fixture produced no output file.
  • Lean checker reported 88 inherited findings on base and head, with zero new findings. The scoped ATC checks found zero conflicts and the branch test-merged with upstream 4e232d7c91.
  • The full host suite and GPU receipts below are from the original head. This follow-up used focused host verification.

Original host and device evidence

  • Original head c7a412abfd2eb07d00967ab4a69e3f63d1610ec6.
  • Lean checker reported 88 inherited findings on both base and head, zero new findings, and zero new import-cycle edges.
  • zig build dsv41-assets test-dsv41-assets-host passed 28 tests on Linux x86-64. The installed tool accepted the pinned step-300 sidecar and rejected an unsupported depth, a mismatched hash, incorrect layer coverage, a corrupt weight payload, and a correctly rehashed nonfinite weight.
  • zig build test-golden test-kernel-contract fuzz-cortheon test-dsv41-assets-host passed 305 tests. zig fmt --check build.zig zig and git diff --check passed.
  • The broad zig build test run and the ordered native suite on upstream main stopped at the same CUDA disk staging-permit test. The test passed in isolation on upstream main. Both long runs were ended after reproducing the stall.
  • Original-head CI passed verify, format, Zig, Python, and benchmark-client checks. Device inference checks apply to the serving slice.

Receipt

N/A for inference. This PR adds a CPU-only tool and its host reference. The standalone GB10 entry and TP2 projection receipts are recorded in #5938. The state key and byte accounting here are inputs for the serving integration.

The depth-two host result was 88,113,152 adapter bytes and 1,794,048 extra SWA bytes per slot on each rank. Depth one reported zero additional device bytes. The reference uses the published MIT-licensed sidecar for the experiment. Pinned R5-A checkpoint

Checklist

  • The title and description match the head commit, scope, and stack.
  • The host tests and planted refusal cases exercise the new checks.
  • Comments and docstrings are one line. No measurements or history in the source.
  • The diff contains no private paths, internal hosts, or attribution lines.

@francip
francip marked this pull request as ready for review December 3, 2026 07:49
@ashhart ashhart added kind:feature Classified by Synthena as feature addition synthena:needs-ash Needs owner decision labels Dec 3, 2026
@ashhart

ashhart commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Synthena Initial Review — Needs maintainer review (kind:feature)

Adds a CPU-only host tool that validates the pinned DeepSeek V4.1 R5-A loop adapter sidecar (manifest, tensor hashes, shapes, finiteness, zero-gate consistency) and reports per-rank resident weight and SWA bytes, plus a serial FP32/BF16 reference for the loop entry and projection deltas.

  • Large code diff (618 lines across 5 files); requires maintainer review.

Findings:

  • [WARNING] zig/src/families/deepseek_v41/loop_adapter.zig: If checkWeights fails, the errdefer chain in open does not cover the returned result, so the three already-opened safetensors files leak on that error path. Suggested fix: Wrap the result construction and checkWeights call with an errdefer that closes all three files, or move checkWeights before the result is returned via a local that is covered by the existing errdefers.
  • [WARNING] zig/src/families/deepseek_v41/loop_asset_tool.zig: bytesAsSlice on unaligned file-read buffers requires the underlying allocation to be sufficiently aligned; readFileAlloc may return a pointer with alignment below u16, causing an illegal behavior on strict-alignment targets. Suggested fix: Use std.mem.bytesAsSlice(u16, old) only after verifying alignment, or copy through an aligned allocation (e.g. a.alloc(u16, ...) and read into it via bytesAsSlice on a properly aligned buffer).
  • Synthena

@ashhart

ashhart commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Synthena Initial Review — Needs maintainer review (kind:feature)

Adds a CPU-only host tool that validates the pinned DeepSeek V4.1 R5-A loop sidecar (manifest, tensor digests, TP2 partitions) and computes per-rank resident byte costs, plus a serial FP32/BF16 entry and projection reference. Includes host tests and a recipe doc; no runtime or serving-path changes.

Findings:

  • [WARNING] zig/src/families/deepseek_v41/loop_adapter.zig: fit() returns zero for depth one without validating that the depth-one entry tensors exist or are loadable, so a depth-one budget of zero is reported even if the sidecar is unusable at that depth. Suggested fix: Validate the depth-one entry tensors (or document that depth one requires no adapter residency) before returning a zero Fit.
  • [WARNING] zig/src/families/deepseek_v41/loop_asset_tool.zig: The row-count check validates length in elements but the loop indexes rows by hidden only, so a file whose length is a multiple of hiddenhc but not a whole number of hidden-element rows per stream could still be mis-sliced if hiddenhc does not divide evenly into per-token rows. Suggested fix: Assert anchors.len % hidden == 0 explicitly and document the expected [tokens, 4, 5120] flattening order.
  • Synthena

@ashhart

ashhart commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Synthena Initial Review — Needs maintainer review (kind:feature)

Adds a host-side admission tool and serial FP32/BF16 reference for the DeepSeek V4.1 R5-A loop sidecar, including manifest/tensor validation, per-rank memory fit reporting, a state key, and a new tf-dsv41-loop-check build step.

Findings:

  • [WARNING] zig/src/families/deepseek_v41/loop_adapter.zig: The three tensor files are opened and digest-checked sequentially with errdefer cleanup, but if checkWeights fails after all three opens, no errdefer covers that path, so a BadLoopTensorCount or NonfiniteLoopWeight failure leaks all three file handles. Suggested fix: Wrap the checkWeights call with an errdefer that closes all three files (e.g. errdefer result.close(io) placed after the last open), or restructure so close is guaranteed on any post-open failure.
  • [WARNING] zig/src/families/deepseek_v41/loop_asset_tool.zig: The entry command reads both input files fully into memory with a 16 MiB cap and no validation that the file length is a whole multiple of the token row size before indexing as token, stream, hidden, so a truncated file can produce an out-of-bounds slice or silently wrong results. Suggested fix: Validate old.len == past.len and old.len % (hc * hidden * @sizeof(u16)) == 0 before slicing, returning BadLoopReferenceRows otherwise.
  • Synthena

@ashhart

ashhart commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Thanks @francip. Your commits had a work email as the commit address, and we don't put personal addresses into main's history, so we moved them to your GitHub noreply. Pushes to this branch are refused, so we carried the same three commits, authorship kept, in #6170, which lands in your name. Closing this in favour of #6170.

  • Synthena

@ashhart ashhart closed this Dec 3, 2026
@francip

francip commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

my (agent's) bad. will be careful with the noreply email moving forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:feature Classified by Synthena as feature addition synthena:needs-ash Needs owner decision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants