Skip to content

feat(deepseek): carry bounded V4 target and MTP calibration replay - #3603

Merged
Qubitium merged 1 commit into
ModelCloud:mainfrom
tpurtell:upstream/23-deepseek-v4-mtp-replay-20261108
Nov 9, 2026
Merged

Qubitium merged 1 commit into
ModelCloud:mainfrom
tpurtell:upstream/23-deepseek-v4-mtp-replay-20261108

Conversation

@tpurtell

@tpurtell tpurtell commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Carry the existing V4 floatx/router precision handling, explicit auxiliary traversal, causal target/MTP alignment, bounded prefix runtime, checkpoint mappings, route recovery, vision/native tensor retention, and integrated quantized MTP save behavior.

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

Incremental change: 5 files, +5499/−4 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["DeepSeekV4QModel"]
    M0_0["DeepSeekV4QModel.prepare_input_capture_layer"]
    M0_1["DeepSeekV4QModel.save_state_overlay"]
    M0_2["DeepSeekV4QModel.capture_first_layer_input_kwargs"]
    S1["DeepSeekV4MTPReplay"]
    M1_0["DeepSeekV4MTPReplay.__init__"]
    M1_1["DeepSeekV4MTPReplay.prepare_batch"]
    S2["DeepSeekV4MTPQuantizationModel"]
    M2_0["DeepSeekV4MTPQuantizationModel.prepare_input_capture_layer"]
    M2_1["DeepSeekV4MTPQuantizationModel.prepare_dataset"]
    E["IndexError, RuntimeError, TypeError, ValueError"]
    S0 -. "exposes" .-> M0_0
    S0 -. "exposes" .-> M0_1
    S0 -. "exposes" .-> M0_2
    S0 -->|"raises on rejected input/state"| E
    S1 -. "exposes" .-> M1_0
    S1 -. "exposes" .-> M1_1
    S1 -->|"raises on rejected input/state"| E
    S2 -. "exposes" .-> M2_0
    S2 -. "exposes" .-> M2_1
    S2 -->|"calls where selected"| S1
    S2 -->|"raises on rejected input/state"| E
    style E fill:#fee,stroke:#b22
Loading
Before this extraction layer Carried implementation
Previous stack layer: gptqmodel/models/definitions/deepseek_v4.py:9 gptqmodel/models/definitions/deepseek_v4.py:1410: DeepSeekV4QModel
API absent in the previous stack layer (path/symbol checked) gptqmodel/models/definitions/deepseek_v4.py:740: DeepSeekV4MTPReplay
API absent in the previous stack layer (path/symbol checked) gptqmodel/models/definitions/deepseek_v4.py:2349: DeepSeekV4MTPQuantizationModel

Committed reference: docs/deepseek-v4-mtp-replay.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: tests/test_deepseek_v4_support.py, tests/test_qwen4_exp_exl3_contracts.py

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.

Existing model support: upstream already supports this GLM/DeepSeek family. This proposal adds calibration/MTP/recovery capability; it does not add a competing MODEL_MAP registration. Native Transformers blocks and upstream model plans remain the integration basis.

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/23-deepseek-v4-mtp-replay-20261108 branch from 75b2876 to 713ac84 Compare November 9, 2026 09:37

@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 replay contract is coherent: prepare_dataset refuses concat/sort/batch mutations, _DeepSeekV4MTPPreparedDataset normalizes each replay batch lazily, _DeepSeekV4MTPInputProvider keeps a small LRU instead of expanding the corpus, and run_input_capture validates the required keys and rebuilds target_taps/projected_main from the stored width. The output writer only persists authoritative post-quantization block outputs and discards superseded capture frontiers.

Two things worth calling out explicitly, both now handled:

  1. InputCache.__post_init__ mirrors layer_inputs into src_inputs with list(...). Because layer_inputs here is _DeepSeekV4MTPInputView, that call would iterate the view and materialize the whole lazy corpus on construction — exactly what the cache is meant to avoid. build_quantization_input_cache now passes src_inputs=[]; MTP replay has no input-embedding stage that consumes src_inputs, so nothing is lost.
  2. test_deepseek_v4_pre_quantize_keeps_packed_target_layer_lazy constructed the harness with object.__new__(DeepSeekV4QModel) but never called nn.Module.__init__. The assertion body passed, but monkeypatch teardown then hit nn.Module.__delattr__ and raised AttributeError: ... has no attribute '_parameters'. Initializing the module fixes the teardown without changing what the test asserts.

Validation: ruff check clean on the touched modules; pytest tests/test_deepseek_v4_support.py tests/test_qwen4_exp_exl3_contracts.py reports 45 passed.

No other blocking issues found.

@Qubitium
Qubitium marked this pull request as ready for review November 9, 2026 09:37
@Qubitium
Qubitium merged commit 6f4188a 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