From 90e08f05027916a72a4530547cfe51342b528cf3 Mon Sep 17 00:00:00 2001 From: Vuong Hoang Date: Thu, 4 Jun 2026 00:29:05 -0700 Subject: [PATCH] fix(vllm-phi4): Ollama-matching chat template to recover R15 baseline vLLM's official Phi-4 tokenizer template emits <|end|> after the system turn; Ollama's does not. That single boundary token regressed brokkr's R15 P02 admission eval (type macro-F1 -33pp) vs the Ollama-measured canonical, while valid_format held at 1.0. Operator chose to make vLLM match Ollama's leaner scaffold globally (baseline == production). Adds conf/phi4-chat-template.jinja (drops the system <|end|>) + mounts it + --chat-template on vllm-phi4. Applied prompt verified via tokenize/detokenize; brokkr re-smokes probe_vllm.yaml. --- stacks/vllm/compose.yaml | 5 +++++ stacks/vllm/conf/phi4-chat-template.jinja | 24 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 stacks/vllm/conf/phi4-chat-template.jinja diff --git a/stacks/vllm/compose.yaml b/stacks/vllm/compose.yaml index 1a0334d..28ec332 100644 --- a/stacks/vllm/compose.yaml +++ b/stacks/vllm/compose.yaml @@ -210,6 +210,7 @@ services: - "${PHI4_PORT}:8000" volumes: - /tank/aimodels/huggingface:/hfcache + - /opt/docker/conf/vllm/phi4-chat-template.jinja:/config/phi4-chat-template.jinja:ro environment: - HF_HOME=/hfcache - HF_HUB_CACHE=/hfcache/hub @@ -237,6 +238,10 @@ services: # FP8 KV cache — halves KV memory at 128K ctx on Ada (cc 8.9); near-lossless. - --kv-cache-dtype - ${PHI4_KV_CACHE_DTYPE} + # Ollama-matching scaffold (drops the system-turn <|end|>) so vLLM reproduces + # brokkr's R15 canonical baseline. See conf/phi4-chat-template.jinja. + - --chat-template + - /config/phi4-chat-template.jinja deploy: resources: reservations: diff --git a/stacks/vllm/conf/phi4-chat-template.jinja b/stacks/vllm/conf/phi4-chat-template.jinja new file mode 100644 index 0000000..31b930b --- /dev/null +++ b/stacks/vllm/conf/phi4-chat-template.jinja @@ -0,0 +1,24 @@ +{#- + Phi-4-mini chat template — OLLAMA-MATCHING variant. + + Why this exists: the official HF tokenizer template emits <|end|> after the + SYSTEM turn; Ollama's phi4 template does NOT (its system-block <|end|> is only + in the tools branch). That single boundary token regressed brokkr's R15 P02 + admission eval on vLLM vs the Ollama-measured canonical (type macro-F1 -33pp) + while valid_format held at 1.0. Operator chose (2026-06-04) to make vLLM match + Ollama's leaner scaffold globally so baseline == production. + + Renders (system + user, add_generation_prompt): + <|system|>{sys}<|user|>{usr}<|end|><|assistant|> + i.e. NO <|end|> after the system turn (the only delta from official). +-#} +{%- for message in messages -%} +{%- if message['role'] == 'system' -%} +{{- '<|system|>' + message['content'] -}} +{%- else -%} +{{- '<|' + message['role'] + '|>' + message['content'] + '<|end|>' -}} +{%- endif -%} +{%- endfor -%} +{%- if add_generation_prompt -%} +{{- '<|assistant|>' -}} +{%- endif -%}