mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #5382] [Engine] dsv41: apply a request's logit_bias in the DeepSeek-V4.1 engine #5409
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#5409
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/Niko1221/Strata/pull/5382
Author: @srkim-business
Created: 11/6/2026
Status: 🔄 Open
Base:
main← Head:dsv41-logit-bias📝 Commits (1)
e9bdcfe[Engine] dsv41: apply a request's logit_bias in the DeepSeek-V4.1 engine📊 Changes
6 files changed (+318 additions, -2 deletions)
View changed files
📝
docs/DETAILS.md(+1 -1)📝
docs/LOGIT_BIAS.md(+17 -0)📝
src/dsv41/ds4_main.cpp(+26 -0)📝
src/dsv41/ds4_model.cu(+69 -1)📝
src/dsv41/ds4_model.hpp(+7 -0)➕
tools/logit_bias_dsv41_probe.py(+198 -0)📄 Description
Problem and result
The server takes
logit_bias(docs/LOGIT_BIAS.md), but the DeepSeek-V4.1 engine never advertiseslogit_bias=1, so every request with a nonempty bias gets HTTP 400 there. The engine's vendored sampler alreadyreads
SamplerParams.logit_bias; every call passes nullptr.With this change the engine reads the GEN line's
logit_bias=with the shared parser(
include/strata/core/logit_bias.hpp), adds it to the request's picks, and advertisesINFO logit_bias=1on CUDA builds (the HIP build compiles the same code but does not advertise it until it has run on an AMD card;
Metal does not either). A request without a bias takes the same path as before: the same token IDs as main (Validation).
Why we need it: our users ask in Korean, and DeepSeek-V4.1-Flash answers mix in Han and kana characters. With a
list of the vocabulary's Han/kana tokens sent on every request (an earlier form of this patch on 0.2.10), 0 of 100
free-form Korean answers had them, against 21 of 100 without the list; KMMLU (135 items) and HRM8K (100 items)
scores stayed the same (80.7% and 96% with the list, 81.5% and 96% without).
Related discussion
None needed, I think: this enables the existing, documented field on one more engine, with no new option and no
default change. The same field on the Qwen engine: #1627, #1646. #3266 (Qwen
--batch) is separate. No issue orpull request covers the DeepSeek engine.
Approach
ds4_main.cpp: the GEN line'slogit_bias=is parsed once when the prompt starts; a bad list ends the requestwith ERR before any token. The list is set before each pick: in the one-conversation path, per conversation with
--parallel, and before each conversation's own drafts.ds4_model.cu: one device row (vocab floats) per distinct list on the head GPU. The last 16 are kept with ahost copy, found by the list text's hash and then compared, so a list sent with every request is copied once;
past 16 the oldest row's memory is reused. The copy is
cudaMemcpyAsyncon the head stream, where every pickreads the row. The row goes into
SamplerParams.logit_biasforsample,verify(greedy and sampled), theDSpark drafter's picks,
sample_multiandverify_multi.draft_multi(rows of several conversations, each with its own list) and the markov drafts of a headsplit over a GPU group (
mk_split). Verification has the list and rejects a banned draft there like any other.Covering
mk_splitwould be one line (mk = mk_split && !drafts_q && d_bias == nullptr, the gathered path thatsampled drafts already take), but the engine runs our pack with
tensor parallel 2 -> 1on our cards, so Icould not run it and left it out.
docs/LOGIT_BIAS.md, one line indocs/DETAILS.md.tools/logit_bias_dsv41_probe.py:tools/logit_bias_http_probe.pyadapted to this engine (DeepSeek config andfamily, late-token bans, DSpark off, two conversations at once). I can fold it into the existing probe instead,
or drop it, if you prefer.
Validation
Passed:
CUDA build:
packaging/build_dsv41_cuda.sh, ARCH=120, CUDA 13.1.115, gcc 13.3, Ubuntu 24.04 x86_64, main9f7d977with this patch and without it, llama.cpp 3cf0325. The patched binary hasINFO logit_bias=1; theunpatched one does not.
HIP build, compile only:
VARIANT=rx9070 NO_PACKAGE=1 packaging/build_dsv41_hip_linux.shwith this patch, ROCm7.10.0a20251120 from the TheRock
gfx120X-allwheels (setup.py's pin).dsv41 built rc=0, offload bundlesgfx1200 gfx1201, and no
INFO logit_bias=1in the binary (left off on HIP, see Not run).Probe, 32 requests, all passed (rows.json attached):
python tools/logit_bias_dsv41_probe.py --source . --config <run config> --baseline <main build>/strata-dsv41 --candidate <this PR's build>/strata-dsv41 --output <dir>on 2x RTX PRO 6000 Blackwell Max-Q 96 GB, Linux, DeepSeek-V4.1-Flash-1017 IQ2_XS (2.25 bpw) GGUF, pack
ist-das-2.25bpw, all experts in VRAM, the setup-written run config (--tp 2, which the engine reports astensor parallel 2 -> 1with the head on one GPU,--layer-split auto,--dspark auto,--max-context 131072).!defined(STRATA_USE_HIP)to theINFOcondition; the CUDAbuild was rebuilt after it and still advertises
logit_bias=1.[30594, 1], andsampled (T 0.7, top_k 20, seed 42)
[36914, 344, 260, 1669, 12675, 14, 26398, 14051].bananamade it the firsttoken. A bad ID and a bias of 101 gave 400 on a streamed request. A cleared bias and
{}gave the firstrequest's IDs again. 103,215 bans, a streamed ban and a sampled ban held.
first writes at position 5 or later kept that token out, greedy (26 drafted, 18 accepted) and sampled at
T 0.7, seed 7 (26 drafted, 15 accepted).
你好intoHello; the next request without a biasgave
你好again. The same with--dspark off.--parallel 2, three pairs run over the same interval (start and end times in rows.json):times: beside an English answer banning a token the unbiased one writes late, and beside a Chinese answer
banning a token of its own. Neither biased answer wrote its banned token.
Speed without a bias, interleaved A/B on the same machine and run config: the unpatched main build and this PR's
build started alternately, three times each; per start, five identical requests per prompt (384 tokens, T 0,
ignore_eos, thinking off). Decode tok/s from the server'stimings, mean of 15 requests per build (raw lines inthe attached speed-ab-1106.txt (JSON lines)):
9f7d977All 15 answers per prompt had the same text on both builds, with the same DSpark counts (drafted/accepted
319/319, 103/88, 284/245).
probe-rows-1106-0854.json
speed-ab-1106.txt
Failed: none observed.
Not run:
logit_bias=1(!defined(STRATA_USE_HIP)inds4_model.cu), so AMD users keep the 400 they get today. A run onan R9700 (the probe above) and dropping that condition would turn it on.
INFOline is left out underSTRATA_METAL, so the server keeps answering 400 there. The newcode uses only functions
metal/include/metal_compat/cuda_runtime.hhas, but I did not build it.serve/logit_bias.py.mk_split): see Approach.Limits
the next starting with its continuation bytes) can still come out: on 0.2.10, 2 such characters in 135 long
thinking traces with the Han/kana list, none in answers.
draft_multi,mk_split) can lower acceptance under a restrictive list; the output is notaffected.
against 0.043 s for the same 2-token answer without it (0.085 s against 0.034 s with
--dspark off); 103,215bans took 0.469 s.
bias; the request is not ended.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.