# syntax=docker/dockerfile:1.7
# TensorFold 2x DeepSeek-V4.1-Flash-1017 image.
#
# Upstream: x00byte/DeepSeek-V4.1-Flash-1017-Dual-Spark (forum 386121) —
# TensorFold 0.6.0 with Jay Leaton's DeepSeek-family patches and the repo's
# tensorfold-1017.patch, on NVIDIA's 26.07 PyTorch container (the stack asserts
# triton 3.7.1 + torch nv26.07). The sources are fetched at pins by
# fetch-sources.sh (outside this directory) and copied in as `upstream/build/tensorfold`.
FROM nvcr.io/nvidia/pytorch:26.07-py3
ENV PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1 HF_HUB_OFFLINE=1 TENSORFOLD_NO_UPDATE_CHECK=1
RUN test -f /usr/include/infiniband/verbs.h || (apt-get update && apt-get install -y --no-install-recommends libibverbs-dev ibverbs-providers && rm -rf /var/lib/apt/lists/*)
RUN pip install --no-cache-dir --no-deps xgrammar==0.2.8 && pip install --no-cache-dir transformers==5.18.0
COPY upstream/build/tensorfold /opt/tensorfold
# Host-side helper scripts the launcher's prepare hook pulls back out of the
# image (engram packer, CUDA prebuild, chat template) — keeps the lane to ONE
# artifact: the image.
COPY upstream/build/jayleaton/scripts/pack_engram.py \
     upstream/build/jayleaton/scripts/prebuild_ext.py \
     upstream/scripts/prebuild-offline.py \
     upstream/build/jayleaton/config/pfdense-table.json \
     upstream/build/mia-runtime/files/chat_template.jinja \
     /opt/sm121-helpers/
RUN pip install --no-deps --no-build-isolation /opt/tensorfold && python -c "import torch,triton,tensorfold.families.deepseek_v41; assert triton.__version__ == '3.7.1'; assert 'nv26.07' in torch.__version__; print(torch.__version__)"
ENTRYPOINT ["python", "-m", "tensorfold"]
