Skip to content

feat(sdk): apply chat template in LLM bench text-prompt path#1112

Draft
RemiliaForever (RemiliaForever) wants to merge 1 commit into
mainfrom
feat/bench-llm-chat-template
Draft

feat(sdk): apply chat template in LLM bench text-prompt path#1112
RemiliaForever (RemiliaForever) wants to merge 1 commit into
mainfrom
feat/bench-llm-chat-template

Conversation

@RemiliaForever

@RemiliaForever RemiliaForever (RemiliaForever) commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

What

The VLM path in geniex-bench has always wrapped prompts with a chat template via geniex_vlm_apply_chat_template, but the LLM --prompt-file (text-prompt) path previously fed the raw text directly into prompt_utf8 without applying a template. This made LLM --accuracy output inconsistent with real inference (LLM is templated in the CLI's infer.go).

Changes

  • Add build_llm_prompt (mirroring build_vlm_prompt): run a single user message through geniex_llm_apply_chat_template with add_generation_prompt = true and enable_thinking = true.
  • run_llm now applies the template before feeding gin.prompt_utf8 in --prompt-file mode, and frees it with geniex_free on both the error-exit and normal-completion paths.
  • The VLM path (build_vlm_prompt) also sets enable_thinking = true to align with LLM.
  • Update the file-top comment, run_vlm comment, and --prompt-file help text accordingly.

Behavioral differences remain reasonable: the default random-ids prefill mode (-p N) still skips the tokenizer and template — it is purely a prefill-speed test by design. Template/think only takes effect on the --prompt-file path.

Notes

  • Only touches the SDK's C bench program; geniex.h is untouched, so this is not an FFI change.
  • Builds cleanly locally with cmake --build build --target geniex-bench.

The VLM bench always templated its prompt while the LLM --prompt-file
path fed raw text, so LLM --accuracy runs saw an unformatted prompt
unlike real inference. Run --prompt-file text through the bundle's chat
template (add_generation_prompt + enable_thinking), matching the VLM
path; random-ids prefill still skips the tokenizer and template.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates geniex-bench so the LLM --prompt-file (text-prompt) benchmark path applies the bundle’s chat template (matching real inference behavior and aligning with the existing VLM path), and enables “thinking” in the templating configuration to keep prompt formatting consistent.

Changes:

  • Add build_llm_prompt() to apply geniex_llm_apply_chat_template() for --prompt-file prompts before calling geniex_llm_generate().
  • Enable thinking in the VLM prompt templating path, and update usage/help text + comments to describe the new behavior.
  • Ensure --prompt-file formatted prompt memory is freed via geniex_free() on both success and failure paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sdk/benchmark/benchmark.c
Comment thread sdk/benchmark/benchmark.c
Comment thread sdk/benchmark/benchmark.c
@zhiyuan8

Copy link
Copy Markdown
Contributor

Mengsheng Wu (@mengshengwu) need to take a look, do not merge till next week after we finish perf scorecard run.

@mengshengwu

Copy link
Copy Markdown
Contributor

LGTM

@RemiliaForever

Copy link
Copy Markdown
Contributor Author

since qairt need directly pass prompt to generate, consider adding a flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants