# syntax=docker/dockerfile:1.7
# DeepSeek-V4-Flash-DSpark — overlay on top of
# aidendle94/sparkrun-vllm-ds4-gb10:production-3.8
#
# production-3.8 is the clean-overlay micromamba/conda build (vLLM 0.21.1,
# torch 2.11+cu130, NCCL 2.30.4, flashinfer 0.6.12, b12x 0.15.3) with the
# opt-in DSPARK tiny-A8 decode kernel (VLLM_B12X_TINY_DECODE=1, see
# /opt/tinydec). It is a clean base (empty entrypoint) meant to be launched
# externally, matching how sm121 launches engines.
#
# Vs production-3.75 (vLLM 0.11.2 @ /opt/venv): the deepseek_v4 tokenizer
# stack is byte-identical (verified md5), so the same patches apply; only the
# prefix path differs (/opt/env, not /opt/venv). instanttensor is dropped — it
# is not shipped in 3.8 and the recipe uses --load-format auto.
#
# Build: cd docker-images/deepseek-v4-flash-dspark && docker build -t sparkrun-vllm-ds4-gb10:fixed .

FROM aidendle94/sparkrun-vllm-ds4-gb10:production-3.8

# Fix reasoning_effort handling in the vendored deepseek_v4 tokenizer:
# - high was accepted but silently injected nothing (only max triggered text)
# - low / unknown values were coerced to high (unreachable low, silent escalation)
# - the bundled deepseek_v4_encoding.py was an OLD revision (single REASONING_EFFORT_MAX
#   wording, max used the high text, read the deprecated `reasoning` key)
# deepseek_v4_encoding.py is replaced with the canonical model-card reference
# (deepseek-ai/DeepSeek-V4-Flash-0731 encoding/encoding_dsv4.py): full low/high/max
# prompt dict, correct gate for both high and max, and reasoning_content key.
# deepseek_v4.py carries the normalization fix so low is reachable and unknown
# values map to None. See deepseek_v4.py / deepseek_v4_encoding.py in patches/.
#
# Tool-calling benchmarks showed three further encoding-level fixes on top of the
# canonical file (see patches/):
#   * thinking_mode kwarg ('thinking'/'chat') honored as a model-card alias
#   * TOOLS_TEMPLATE carries an anti-prompt-injection security line
#   * response_format_template requires raw JSON (no markdown fences)
COPY patches/deepseek_v4.py \
     patches/deepseek_v4_encoding.py \
     /opt/env/lib/python3.12/site-packages/vllm/tokenizers/

# Tiny-decode kernel is opt-in via env (sitecustomize hook reads these at
# interpreter start); the recipe[env] sets VLLM_B12X_TINY_DECODE=1 to enable.
ENV VLLM_B12X_TINY_DECODE=0
