Updated jinja template

#42
by bitworks - opened

Much better results with Froggerics jinja template:

https://huggingface.co/froggeric/Qwen-Fixed-Chat-Templates
.. like.. ALOT better results..

I've been running Ornith 1.0 35B (Q4_K_M) on llama.cpp with the stock Qwen template for weeks, and just switched to froggeric's v21.3. The improvement is measurable and comes from several concrete fixes:

  1. KV Cache hit rate β†’ 100% β€” The stock template strips reasoning content from past turns, invalidating the prefix cache on every turn. Froggeric preserves thoughts chronologically (preserve_thinking: true), so multi-turn conversations reuse cached KV. On llama.cpp with --cache-reuse, this is the difference between 30 t/s and 65 t/s after a few turns.

  2. No more "empty think" poisoning β€” The stock template replaces past thoughts with empty thinking\n\n response blocks + a directive to call a tool immediately. This creates a toxic pattern where the model associates empty thoughts with tools and full thoughts with "forbidden" text, causing an 80%+ premature stall rate. Froggeric abolished empty think injection entirely.

  3. Two-tier agentic error escalation β€” Tracks a consecutive_failures counter. First failure: seeds reasoning at a different token position. Second failure: bypasses thinking and forces a corrected action. This fixes the "model keeps calling the same broken tool forever" problem.

  4. AST flattening β†’ ~80% throughput improvement on C++ engines (llama.cpp, LM Studio). The stock template's deeply nested Jinja creates severe parsing bottlenecks.

  5. minijinja compatibility β€” The stock template uses Python-only Jinja2 features (| items, loop.previtem, | first) that crash or silently misbehave on C++ runtimes. Froggeric rewrote every filter to be 100% minijinja-safe.

  6. Smart false-positive detection β€” Instead of broad "error" substring matching (which triggers false retry loops on successful DB returns containing the word "error"), uses strict structural guards: Exception:, "error":, Traceback, command not found.

  7. Dynamic payload truncation β€” max_tool_arg_chars / max_tool_response_chars limiters prevent context window blowouts from massive API returns.

  8. Inline thinking toggle β€” <|think_on|> / <|think_off|> anywhere in system/user prompts to control reasoning per-query. Huge for BI/analytics use cases.

Bottom line: Every fix addresses a specific, reproducible failure mode in the stock Qwen template β€” KV cache invalidation, agentic stalls, C++ parsing crashes, false error loops, and context window blowouts. If you're running Ornith (or any Qwen3.5/3.6 model) on llama.cpp, vLLM, or LM Studio, this template is essentially required for reliable agentic behavior.

One caveat: remove any chat_template_kwargs overrides you were using (enable_thinking, auto_disable_thinking_with_tools) β€” the new template handles everything internally via <|think_on|>/<|think_off|> tags. Just pass --chat-template-file chat_template.jinja and let it work.

test to enable "preserve thinking" also.. its freakish BIG when it comes to Agentic loops

Edit:
I am blind or can't read :-/

do you use --reasoning-format deepseek with this template ?

Sign up or log in to comment