# Llama 4 Scout / Maverick on Iluvatar BI-V150
#
# 一个镜像同时支持：
#   - Llama-4-Scout-17B-16E-Instruct（BF16，TP8，8 卡）
#   - Llama-4-Maverick-17B-128E-Instruct-FP8（FP8，TP8+PP2，16 卡）
#
# 模型权重不打进镜像，运行时挂载模型目录；容器启动后读取 config.json
# 自动判断 Scout / Maverick，并选择对应的 TP / PP / 端口。
#
# 构建：
#   docker build -t llama4-bi150:2026-10-26 .
#
# 运行：
#   ./run.sh /mnt/disk0/models/LLM-Research/Llama-4-Scout-17B-16E-Instruct
#   ./run.sh /mnt/disk0/models/LLM-Research/Llama-4-Maverick-17B-128E-Instruct-FP8
#
# 补丁是针对下面这个精确基础镜像生成的；换基础镜像需要重新生成 diff。
#   registry.iluvatar.com.cn:10443/customer/sz/vllm0.17.0-4.4.0-x86:v7
#   (vLLM 0.17.0+corex.20260612070235)

FROM registry.iluvatar.com.cn:10443/customer/sz/vllm0.17.0-4.4.0-x86:v7

ARG IMAGE_VERSION=2026-10-26

LABEL org.opencontainers.image.title="llama4-bi150" \
      org.opencontainers.image.description="Llama 4 Scout / Maverick on Iluvatar BI-V150 with vLLM 0.17.0+corex" \
      org.opencontainers.image.version="${IMAGE_VERSION}"

COPY patches /opt/llama4/patches
COPY apply_patch.py /opt/llama4/apply_patch.py
COPY detect_model.py /opt/llama4/detect_model.py
COPY entrypoint.sh /usr/local/bin/llama4-entrypoint.sh

RUN chmod +x /usr/local/bin/llama4-entrypoint.sh \
    && chmod +x /opt/llama4/detect_model.py \
    && python3 /opt/llama4/apply_patch.py

ENV MODEL_PATH=/models/llama4 \
    AUTO_DETECT=1 \
    HOST=0.0.0.0 \
    MAX_MODEL_LEN=4096 \
    MAX_NUM_SEQS=1 \
    GPU_MEM_UTIL=0.90 \
    ENFORCE_EAGER=1 \
    PYTHONUNBUFFERED=1

WORKDIR /opt/llama4
EXPOSE 8091 8092

ENTRYPOINT ["/usr/local/bin/llama4-entrypoint.sh"]
