mirror of
https://github.com/mw00/project-maya.git
synced 2026-12-03 21:08:26 +07:00
[PR #300] [MERGED] Match DeepSeek-V4.1 reference prompts and preserve agent tool histories #457
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
mw00/project-maya#457
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/mw00/project-maya/pull/300
Author: @Gazelle221B
Created: 10/20/2026
Status: ✅ Merged
Merged: 10/20/2026
Merged by: @mw00
Base:
main← Head:ds41-reference-prompt-format📝 Commits (1)
5372cddMatch DeepSeek-V4.1 reference prompt rendering and tool parsing📊 Changes
19 files changed (+2214 additions, -36 deletions)
View changed files
➕
LICENSE.deepseek-v41(+21 -0)📝
README.md(+3 -0)➕
docs/deepseek-prompt-format.md(+40 -0)➕
serve/ds41_encoding.py(+995 -0)➕
serve/fixtures/deepseek_v41/README.md(+21 -0)➕
serve/fixtures/deepseek_v41/test_input_1.json(+82 -0)➕
serve/fixtures/deepseek_v41/test_input_2.json(+24 -0)➕
serve/fixtures/deepseek_v41/test_input_3.json(+93 -0)➕
serve/fixtures/deepseek_v41/test_input_4.json(+28 -0)➕
serve/fixtures/deepseek_v41/test_input_5.json(+39 -0)➕
serve/fixtures/deepseek_v41/test_output_1.txt(+38 -0)➕
serve/fixtures/deepseek_v41/test_output_2.txt(+1 -0)➕
serve/fixtures/deepseek_v41/test_output_3.txt(+35 -0)➕
serve/fixtures/deepseek_v41/test_output_4.txt(+2 -0)➕
serve/fixtures/deepseek_v41/test_output_5.txt(+11 -0)📝
serve/frontend.py(+190 -15)📝
serve/server.py(+24 -20)➕
serve/test_ds41_conformance.py(+563 -0)📝
tools/ds4/chat_template.jinja(+4 -1)📄 Description
DeepSeek's official fixtures expose lost reminders, later system instructions and message-local tools. Parallel tool results can also lose their call association, and DSML string flags can change argument types. Use the pinned reference encoder for DeepSeek rendering and preserve the metadata needed by it. Other model families keep their existing rendering path.
Based on
mainat8d9a9b5d705049a87da853717cdc59440252de30(v1.1.17). The encoder and unchanged fixtures come from DeepSeek-V4.1-Flash-1017, revision1bae0e1088993b9b82de08f59de5be5a34e42170, with MIT attribution and license retained.The change preserves later system/developer messages, tool IDs and parallel result order; accepts integer reasoning budgets 1–100 and retains
medium→ 75 /xhigh→ 100; respects DSML string flags; and preserves leading newlines and text-block boundaries.Measured on 2 × Radeon AI PRO R9700 (32 GB each, PCIe 5.0 ×16), Ryzen 9 7950X, 122.7 GiB RAM, HIP, DeepSeek-V4.1-Flash-1017 Maya-S (six shards). Both servers used the same engine binary and config, DSpark on, vision off, context 131072, and separate workspace expert-profile copies initialized identically. Requests were greedy with thinking off: a 16-token warm-up, then three 256-token chat completions, plus 2048/8192-token prefill requests with zero cached tokens.
All three ordinary chat prompts had identical rendered bytes before/after; all three generated answers differed. Both runs generated two parallel weather calls and, after city-labelled results arrived in reverse order, reported Tokyo 18 and Osaka 23, with different wording. The round-trip response took 2.30 s before and 16.85 s after; its 44-token prefill took 1.48 s and 15.96 s. The tool-result prompt deliberately changes order with this fix, so that round trip is excluded from the throughput comparison.
This single sequential A/B includes slower 2048-token prefill and a large agent-round-trip latency outlier (a 44-token prefill taking 16 s, which looks like cold expert reads rather than rendering cost, but I have not confirmed it). It does not establish a causal speed change or generation-quality improvement. Opened as a draft until that outlier is re-measured.
Validation: 29 new conformance tests pass, including all five official prompt pairs, numeric budgets, late system/developer messages, parallel results in both adapters, DSML argument types and literal nested DSML tags, chunk boundaries/newlines and namespaced response/history round trips. All CI-equivalent checks passed under Python 3.12.14 with the workflow's dependencies and pinned gguf-py (
3cf03257f219afbe7334045ff7c6a06ac68c627d): HIP mapping check; 244 server tests (6 skipped); 331 installer/tools tests (28 skipped). Exact commands, requests, responses and engine logs are available on request.Scope: prompt rendering and response parsing only. No engine, weights, quantization or GPU kernels change. DSML parameters are buffered until their closing tag before argument JSON is streamed, so the first argument fragment can arrive later. OpenAI responses expose the reference's bare function name and optional call-level namespace; internal routing and Anthropic names stay qualified. Anthropic thinking token budgets keep their existing low/high/max conversion.
tools/ds4/chat_template.jinjaremains a partial compatibility export for ordinary chat/tools. It does not implement the full reference's reminders/tasks, message-local tools, later system roles, ID sorting or namespaces; duplicating the encoder's preprocessing in sandboxed Jinja would introduce a second implementation. The server uses the pinned Python encoder. This boundary is documented indocs/deepseek-prompt-format.md; existing model packs are not rewritten. Image placeholders pass the fixtures, but vision inference, model quality and exhaustive malformed/truncated completion equivalence are not established by these tests.Refs #299
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.