Skip to content

feat(deepseek): carry V4.1 native source and mapped PLE replay - #3613

Merged
Qubitium merged 1 commit into
ModelCloud:mainfrom
tpurtell:upstream/33-v41-native-source-20261108
Nov 9, 2026
Merged

Qubitium merged 1 commit into
ModelCloud:mainfrom
tpurtell:upstream/33-v41-native-source-20261108

Conversation

@tpurtell

@tpurtell tpurtell commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Carry the V4.1-specific architecture contract, packed source execution, one-tensor source reads, memory-mapped PLE gathers, native attention/index selection, RMS normalization and explicit mHC/window replay state. This family remains an explicit calibration API, without a new automatic MODEL_MAP registration.

This is layer 33/36, extracted from an already-used fork for initial maintainer feedback. It depends on #3612. Review only this feature; the cross-fork Files changed view is cumulative because the PR targets upstream main.

Incremental change: 7 files, +1009/−0 lines, including carried tests and the mechanism reference. No merge is automatic. Review value and API shape first; substantial rework can follow that feedback.

Flow and existing-code boundary

flowchart TD
    S0["MappedPLETable"]
    M0_0["MappedPLETable.__init__"]
    M0_1["MappedPLETable.__enter__"]
    S1["V41Source"]
    M1_0["V41Source.__init__"]
    M1_1["V41Source.load_dspark_input"]
    M1_2["V41Source.load_main_input"]
    S2["V41NativeLinear"]
    M2_0["V41NativeLinear.__init__"]
    M2_1["V41NativeLinear.forward"]
    S3["V41ReplayBatch"]
    M3_0["V41ReplayBatch.prepare"]
    E["Captured, IndexError, RuntimeError, ValueError"]
    S0 -. "exposes" .-> M0_0
    S0 -. "exposes" .-> M0_1
    S0 -->|"raises on rejected input/state"| E
    S1 -. "exposes" .-> M1_0
    S1 -. "exposes" .-> M1_1
    S1 -. "exposes" .-> M1_2
    S1 -->|"calls where selected"| S2
    S1 -->|"raises on rejected input/state"| E
    S2 -. "exposes" .-> M2_0
    S2 -. "exposes" .-> M2_1
    S2 -->|"raises on rejected input/state"| E
    S3 -. "exposes" .-> M3_0
    S3 -->|"raises on rejected input/state"| E
    style E fill:#fee,stroke:#b22
Loading
Before this extraction layer Carried implementation
API absent in the previous stack layer (path/symbol checked) gptqmodel/utils/ple_mmap.py:15: MappedPLETable
API absent in the previous stack layer (path/symbol checked) gptqmodel/utils/v41_source.py:45: V41Source
API absent in the previous stack layer (path/symbol checked) gptqmodel/utils/v41_native.py:212: V41NativeLinear
API absent in the previous stack layer (path/symbol checked) gptqmodel/utils/v41_replay.py:26: V41ReplayBatch

Committed reference: docs/v41-native-source.md, linked from README. Class entry points/calls and rejected-state paths describe code present in this branch, rather than planned integrations.

Validation

Carried test files: No standalone test file existed in the fork for this helper; retained original implementation and documented the structural checks.

This packaging pass checked Python parsing, whitespace, dependency order and balanced Mermaid blocks. The author reports successful prior use of these features. Per the requested resource limit and feedback-first scope, existing model quantization, GPU/ROCm tests, heavyweight CPU workloads and full model benchmarks were not rerun; no new performance or model-accuracy claim is made. Tests accompanying earlier stack layers retain their previously reported results.

V4.1 remains an explicit native calibration/replay API and is not added to MODEL_MAP. The source requires its native/reference implementation; upstream inventory documentation alone does not provide that runtime.

Extract the existing working fork feature for first maintainer feedback. Preserve carried code and tests; limit validation to lightweight structural checks. See the linked mechanism reference for actual API/call and failure paths.
@Qubitium
Qubitium force-pushed the upstream/33-v41-native-source-20261108 branch from 19cdbb7 to a0f2404 Compare November 9, 2026 09:58

@Qubitium Qubitium left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed against current main.

The V4.1 source layer is bounded and fails closed where it matters:

  • V41Source validates model_type and every shard basename/presence, refuses full-tensor PLE loads (engram.embed must go through MappedPLETable), and reads one tensor at a time with copy=True.
  • Scaled tensors are handled narrowly: INT8 is only accepted for (layers|mtp).<n>.ffn.experts.<e>.w[123].weight and dequantized through the DeepSeek FP4 expert helper; FP8 requires a block-32 scale grid and is expanded in 32-row chunks so a whole matrix never inflates to FP32 at once.
  • packed_projection restricts EXL3 reload to routed projections, bounds layer/expert ids, requires exactly the four packed buffers, and validates trellis/suh/svh/mcg dtype and geometry before reconstruction.
  • MappedPLETable mmaps FP8 E4M3 values plus E8M0 scales read-only, bounds the safetensors header and gather row count, validates payload extents/overlap, returns owned row bytes, and supports separate value/scale shards plus prefetch/release/close.
  • v41_replay, v41_native, and the deepseek_v41 definition carry the mapped PLE replay and native block contracts.

Validation note: this layer adds no tests of its own. ple_mmap, v41_replay, and v41_source import cleanly; v41_native and deepseek_v41 require the Transformers release that ships deepseek_v41 and are not registered by this PR, so they remain dormant on the installed Transformers 5.22.1. Cleanup was import ordering only.

@Qubitium
Qubitium marked this pull request as ready for review November 9, 2026 09:58
@Qubitium
Qubitium merged commit 3225745 into ModelCloud:main Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants