glm5.2: preserve input marking in prompt tokenization (fix output stalls on stray message tags) - #148
glm5.2: preserve input marking in prompt tokenization (fix output stalls on stray message tags)#148mp4 wants to merge 1 commit into
Conversation
…lls on stray message tags)
Port of llama.cpp commit f72dba3ad ('glm5.2 fixed stray message tags in input').
- Thread jinja string parts (with is_input metadata) through chat template
application; strip BOS/EOS from parts consistently
- Add common_tokenize_parts(): user-provided content (is_input) is tokenized
with parse_special=false so stray message/special tags in read files cannot
be injected as real tokens; template parts keep parse_special=true
- OAI-compat path serializes prompt_parts; handle_completions_impl consumes
them with input-marking-aware tokenization when present
- server-context.cpp hunk adapted to beellama's init_opt signatures
- common/arg.cpp.patch included as in the original commit (unapplied reference
patch for --list-devices device-id display)
|
Please retarget this PR from I re-audited the resulting patch against
Please also add focused regression tests covering:
Once the PR targets |
Allow input tags in input
Why this is needed
This change allows models to be able to modify the llama.cpp/beellama source code. Otherwise, when a model encounters certain message tags in the files it is reading, its output stalls: stray chat-template/special tokens present in file contents (e.g. when the model reads or edits source that contains such tags) get tokenized as real special tokens and break generation. With this fix, user-provided content is marked as input and tokenized with
parse_special=false, so those tags are treated as plain text and generation no longer stalls.What changed
common/chat.h/common/chat.cpp: thread the jinja string parts (withis_inputmetadata) through chat template application, with BOS/EOS stripping applied to the parts consistently; newcommon_tokenize_parts()tokenizes each part with input-marking awareness (user contentparse_special=false, template partsparse_special=true);common_chat_paramsnow carriesprompt_partscommon/chat-auto-parser-generator.cpp: pass the parts through the auto-parser pathtools/server/server-common.cpp: OAI-compat params parsing serializesprompt_parts(is_input+text) into the task paramstools/server/server-context.cpp:handle_completions_implconsumesprompt_partswith input-marking-aware tokenization when present (hunk adapted to beellama'sinit_optsignatures)common/arg.cpp.patch: carried over as-is from the original commit (reference patch for--list-devicesdevice-id display; not applied)Verification
Compiles cleanly for ROCm (HIP: gfx900/gfx1030/gfx1100) + Vulkan in a single build:
version: 0.4.5-dev (commit 9427726d9)