# syntax=docker/dockerfile:1.7
# dsv41-flash-b12x + Aiden's DCP2 stack (production-1.1 overlay, extracted
# 2026-09-12): a thin FROM wrapper that replaces 23 vLLM files in
# site-packages with their final (baked) versions — the DCP2 (decode
# context parallelism) port of Aiden's aidendle94 image onto our
# clone-at-pin tree.
#
# The file set (dcp2-files/, vllm-package-relative paths; provenance +
# per-file triage in top-level dcp2/README.md) is a strict superset of our
# current files: it carries the DCP2 machinery (sharded KV + per-rank
# attention, dcp_replicated spec flags, a2a all-to-all combine, DCP-aware
# dflash speculator, engram mmap/prefetch) AND independently converged
# copies of our own fixes (SM12x top-k guard, get_swa_block_size,
# get_compressed_block_size, DSV41_ENGRAM_DISK, the kai pread thread pool).
# Verified 2026-09-12 by diffing every file (our baked image vs theirs).
#
# Runtime (recipe dsv41-flash-4x-dcp2):
#   --decode-context-parallel-size 2   (4 TP ranks = 2 DCP groups of 2)
#   --dcp-comm-backend a2a             (the new all-to-all + LSE path)
# DCP2 env (DSV41_DCP_*/DSV41_ENGRAM_MMAP/PREFETCH) stay at the image
# defaults (all OFF) — the sharding is driven by the CLI flags.
#
# A/B verdict the variant exists to test (see dcp2/README.md): on Aiden's
# own stack DCP2 bought 2.5M-token KV @300K (vs our 167/176 baseline) but
# lost 9 points of quality and single-stream speed. This variant checks the
# same trade on our fresher tree + b12x.

ARG BASE_IMAGE
FROM ${BASE_IMAGE}

# The 23 final files, package-relative (distributed/… v1/… models/…
# model_executor/…). One COPY layer; no pip, no compile.
COPY dcp2-files/ /usr/local/lib/python3.12/dist-packages/vllm/

# Fail the build (not the first serve) on a syntax or import regression.
RUN set -eux; \
    python3 -m compileall -q \
        /usr/local/lib/python3.12/dist-packages/vllm/v1/attention/backends/mla/sparse_swa.py \
        /usr/local/lib/python3.12/dist-packages/vllm/models/deepseek_v4_1/attention.py \
        /usr/local/lib/python3.12/dist-packages/vllm/models/deepseek_v4_1/common/engram.py \
        /usr/local/lib/python3.12/dist-packages/vllm/models/deepseek_v4_1/nvidia/flashinfer_sparse.py \
        /usr/local/lib/python3.12/dist-packages/vllm/v1/worker/gpu/model_runner.py; \
    python3 - <<'PY'
# Symbol checks: the DCP2 machinery must be importable, and our own fixes
# (present in the superset) must still be there.
import importlib
mods = {
    "vllm.v1.kv_cache_interface": ["is_dcp_replicated_spec", "is_dcp_sharded_spec"],
    "vllm.v1.core.kv_cache_utils": ["dcp_world_size_for_kv_cache_spec"],
    "vllm.v1.attention.backends.utils": ["get_dcp_local_seq_lens"],
    "vllm.distributed": ["get_dcp_group"],
    "vllm.models.deepseek_v4_1.common.engram": ["Engram", "EngramDiskStager", "NgramHashState", "_kai_pool", "DiskEngramTable"],
}
for name, syms in mods.items():
    mod = importlib.import_module(name)
    for s in syms:
        assert hasattr(mod, s), f"{name} missing {s}"
print("DCP2 file set OK: all symbols present")
PY
