[PR #5382] [Engine] dsv41: apply a request's logit_bias in the DeepSeek-V4.1 engine #5409

Open
opened 2026-11-07 16:35:00 +07:00 by bsakaguchi · 0 comments
Owner

📋 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 advertises
logit_bias=1, so every request with a nonempty bias gets HTTP 400 there. The engine's vendored sampler already
reads 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 advertises INFO logit_bias=1
on 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).

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 or
pull request covers the DeepSeek engine.

Approach

  • ds4_main.cpp: the GEN line's logit_bias= is parsed once when the prompt starts; a bad list ends the request
    with 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 a
    host 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 cudaMemcpyAsync on the head stream, where every pick
    reads the row. The row goes into SamplerParams.logit_bias for sample, verify (greedy and sampled), the
    DSpark drafter's picks, sample_multi and verify_multi.
  • Not biased: draft_multi (rows of several conversations, each with its own list) and the markov drafts of a head
    split over a GPU group (mk_split). Verification has the list and rejects a banned draft there like any other.
    Covering mk_split would be one line (mk = mk_split && !drafts_q && d_bias == nullptr, the gathered path that
    sampled drafts already take), but the engine runs our pack with tensor parallel 2 -> 1 on our cards, so I
    could not run it and left it out.
  • Docs: a DeepSeek section in docs/LOGIT_BIAS.md, one line in docs/DETAILS.md.
  • tools/logit_bias_dsv41_probe.py: tools/logit_bias_http_probe.py adapted to this engine (DeepSeek config and
    family, 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, main
    9f7d977 with this patch and without it, llama.cpp 3cf0325. The patched binary has INFO logit_bias=1; the
    unpatched one does not.

  • HIP build, compile only: VARIANT=rx9070 NO_PACKAGE=1 packaging/build_dsv41_hip_linux.sh with this patch, ROCm
    7.10.0a20251120 from the TheRock gfx120X-all wheels (setup.py's pin). dsv41 built rc=0, offload bundles
    gfx1200 gfx1201, and no INFO logit_bias=1 in 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 as
    tensor parallel 2 -> 1 with the head on one GPU, --layer-split auto, --dspark auto, --max-context 131072).

    • The probe ran before the last change, which only adds !defined(STRATA_USE_HIP) to the INFO condition; the CUDA
      build was rebuilt after it and still advertises logit_bias=1.
    • Without a bias the candidate emitted the same token IDs as the unpatched main build: greedy [30594, 1], and
      sampled (T 0.7, top_k 20, seed 42) [36914, 344, 260, 1669, 12675, 14, 26398, 14051].
    • Ban as an object and as a pair list: the same IDs, the banned token gone. +100 on banana made it the first
      token. A bad ID and a bias of 101 gave 400 on a streamed request. A cleared bias and {} gave the first
      request's IDs again. 103,215 bans, a streamed ban and a sampled ban held.
    • Late bans with DSpark drafting, 48 tokens: the unbiased answer drafted 26 and accepted 23. A ban of a token it
      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).
    • A ban of the 36,088 tokens whose text has Han or kana turned 你好 into Hello; the next request without a bias
      gave 你好 again. The same with --dspark off.
    • --parallel 2, three pairs run over the same interval (start and end times in rows.json):
      • An unbiased 48-token English answer beside a biased one was identical to the same request alone, both
        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.
      • A Chinese answer with the Han/kana ban beside an English answer with a late-token ban: both held.
  • 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's timings, mean of 15 requests per build (raw lines in
    the attached speed-ab-1106.txt (JSON lines)):

    Prompt main 9f7d977 this PR Change Per start pair
    Counting 184.3 184.0 -0.1% -0.3%, 0.0%, 0.0%
    Essay 76.4 76.4 +0.1% +0.3%, 0.0%, -0.1%
    Python module 120.8 120.8 0.0% +0.1%, 0.0%, 0.0%

    All 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:

  • HIP execution: I have no AMD card. The rx9070 build compiles (above), but the HIP build does not advertise
    logit_bias=1 (!defined(STRATA_USE_HIP) in ds4_model.cu), so AMD users keep the 400 they get today. A run on
    an R9700 (the probe above) and dropping that condition would turn it on.
  • Metal build: the INFO line is left out under STRATA_METAL, so the server keeps answering 400 there. The new
    code uses only functions metal/include/metal_compat/cuda_runtime.h has, but I did not build it.
  • Windows builds.
  • The engine's own ERR for a bad list: the server rejects bad lists first, so the probe's 400s come from
    serve/logit_bias.py.
  • A head split over a GPU group (mk_split): see Approach.

Limits

  • A token ban is not a character ban. A character split over byte-level tokens (one token ending in its lead byte,
    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.
  • Unbiased drafts (draft_multi, mk_split) can lower acceptance under a restrictive list; the output is not
    affected.
  • A large list costs each request its transfer and parsing: the 36,088-token list (a 548 KB request) took 0.200 s
    against 0.043 s for the same 2-token answer without it (0.085 s against 0.034 s with --dspark off); 103,215
    bans took 0.469 s.
  • If a kept row was pushed out (more than 16 lists in flight) and copying it back fails, that pick runs without the
    bias; the request is not ended.
  • Request-level only, as on the Qwen engine: no startup list file.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/5382 **Author:** [@srkim-business](https://github.com/srkim-business) **Created:** 11/6/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `dsv41-logit-bias` --- ### 📝 Commits (1) - [`e9bdcfe`](https://github.com/Niko1221/Strata/commit/e9bdcfedac9187cfcc7df782583e9cc2ed30a432) [Engine] dsv41: apply a request's logit_bias in the DeepSeek-V4.1 engine ### 📊 Changes **6 files changed** (+318 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `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) </details> ### 📄 Description ## Problem and result The server takes `logit_bias` (docs/LOGIT_BIAS.md), but the DeepSeek-V4.1 engine never advertises `logit_bias=1`, so every request with a nonempty bias gets HTTP 400 there. The engine's vendored sampler already reads `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 advertises `INFO logit_bias=1` on 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 or pull request covers the DeepSeek engine. ## Approach - `ds4_main.cpp`: the GEN line's `logit_bias=` is parsed once when the prompt starts; a bad list ends the request with 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 a host 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 `cudaMemcpyAsync` on the head stream, where every pick reads the row. The row goes into `SamplerParams.logit_bias` for `sample`, `verify` (greedy and sampled), the DSpark drafter's picks, `sample_multi` and `verify_multi`. - Not biased: `draft_multi` (rows of several conversations, each with its own list) and the markov drafts of a head split over a GPU group (`mk_split`). Verification has the list and rejects a banned draft there like any other. Covering `mk_split` would be one line (`mk = mk_split && !drafts_q && d_bias == nullptr`, the gathered path that sampled drafts already take), but the engine runs our pack with `tensor parallel 2 -> 1` on our cards, so I could not run it and left it out. - Docs: a DeepSeek section in `docs/LOGIT_BIAS.md`, one line in `docs/DETAILS.md`. - `tools/logit_bias_dsv41_probe.py`: `tools/logit_bias_http_probe.py` adapted to this engine (DeepSeek config and family, 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, main 9f7d977 with this patch and without it, llama.cpp 3cf0325. The patched binary has `INFO logit_bias=1`; the unpatched one does not. - HIP build, compile only: `VARIANT=rx9070 NO_PACKAGE=1 packaging/build_dsv41_hip_linux.sh` with this patch, ROCm 7.10.0a20251120 from the TheRock `gfx120X-all` wheels (setup.py's pin). `dsv41 built rc=0`, offload bundles gfx1200 gfx1201, and no `INFO logit_bias=1` in 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 as `tensor parallel 2 -> 1` with the head on one GPU, `--layer-split auto`, `--dspark auto`, `--max-context 131072`). - The probe ran before the last change, which only adds `!defined(STRATA_USE_HIP)` to the `INFO` condition; the CUDA build was rebuilt after it and still advertises `logit_bias=1`. - Without a bias the candidate emitted the same token IDs as the unpatched main build: greedy `[30594, 1]`, and sampled (T 0.7, top_k 20, seed 42) `[36914, 344, 260, 1669, 12675, 14, 26398, 14051]`. - Ban as an object and as a pair list: the same IDs, the banned token gone. +100 on ` banana` made it the first token. A bad ID and a bias of 101 gave 400 on a streamed request. A cleared bias and `{}` gave the first request's IDs again. 103,215 bans, a streamed ban and a sampled ban held. - Late bans with DSpark drafting, 48 tokens: the unbiased answer drafted 26 and accepted 23. A ban of a token it 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). - A ban of the 36,088 tokens whose text has Han or kana turned `你好` into `Hello`; the next request without a bias gave `你好` again. The same with `--dspark off`. - `--parallel 2`, three pairs run over the same interval (start and end times in rows.json): - An unbiased 48-token English answer beside a biased one was identical to the same request alone, both 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. - A Chinese answer with the Han/kana ban beside an English answer with a late-token ban: both held. - 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's `timings`, mean of 15 requests per build (raw lines in the attached speed-ab-1106.txt (JSON lines)): | Prompt | main 9f7d977 | this PR | Change | Per start pair | |---|---|---|---|---| | Counting | 184.3 | 184.0 | -0.1% | -0.3%, 0.0%, 0.0% | | Essay | 76.4 | 76.4 | +0.1% | +0.3%, 0.0%, -0.1% | | Python module | 120.8 | 120.8 | 0.0% | +0.1%, 0.0%, 0.0% | All 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](https://github.com/user-attachments/files/34465908/probe-rows-1106-0854.json) [speed-ab-1106.txt](https://github.com/user-attachments/files/34465927/speed-ab-1106.txt) **Failed:** none observed. **Not run:** - HIP execution: I have no AMD card. The rx9070 build compiles (above), but the HIP build does not advertise `logit_bias=1` (`!defined(STRATA_USE_HIP)` in `ds4_model.cu`), so AMD users keep the 400 they get today. A run on an R9700 (the probe above) and dropping that condition would turn it on. - Metal build: the `INFO` line is left out under `STRATA_METAL`, so the server keeps answering 400 there. The new code uses only functions `metal/include/metal_compat/cuda_runtime.h` has, but I did not build it. - Windows builds. - The engine's own ERR for a bad list: the server rejects bad lists first, so the probe's 400s come from `serve/logit_bias.py`. - A head split over a GPU group (`mk_split`): see Approach. ## Limits - A token ban is not a character ban. A character split over byte-level tokens (one token ending in its lead byte, 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. - Unbiased drafts (`draft_multi`, `mk_split`) can lower acceptance under a restrictive list; the output is not affected. - A large list costs each request its transfer and parsing: the 36,088-token list (a 548 KB request) took 0.200 s against 0.043 s for the same 2-token answer without it (0.085 s against 0.034 s with `--dspark off`); 103,215 bans took 0.469 s. - If a kept row was pushed out (more than 16 lists in flight) and copying it back fails, that pick runs without the bias; the request is not ended. - Request-level only, as on the Qwen engine: no startup list file. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5409
No description provided.