Skip to content

fix(server): unseeded sampled requests no longer repeat under concurrency - #876

Merged
davide221 merged 1 commit into
Luce-Org:mainfrom
Graffioh:fix/parallel-unseeded-sampling
Oct 25, 2026
Merged

davide221 merged 1 commit into
Luce-Org:mainfrom
Graffioh:fix/parallel-unseeded-sampling

Conversation

@Graffioh

@Graffioh Graffioh commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Measured on the R9700 on 2026-10-22, on a build of origin/main 727fa95 plus an unrelated branch that does not touch this code. The server ran with --max-concurrency 4. We sent 200 chat requests with the same prompt at temperature 1.0, top_p 0.95 and top_k 20, with no seed field. They returned 2 distinct outputs, and 192 of them were identical. With a seed per request, the outputs differ. At concurrency 1, 3 unseeded sampled requests on the same build gave 3 different outputs.

Cause:

  • server/src/server/http_server.cpp:1801 sets sampler.seed only when the body has "seed". Otherwise SamplerCfg::seed stays at its default of 0 (server/src/common/sampler.h:31).
  • server/src/common/concurrency/seq_slot_manager.cpp:193-197 calls s.rng.seed(sampler.seed) whenever sampler.needs_logit_processing() is true. So every unseeded sampled request starts from seed 0 and repeats the same draws for the same prompt.
  • The single-lane backends seed only when sampler_.seed != 0. Otherwise they keep using their random_device-initialised sampler_rng_, which is why concurrency 1 was fine.

Why it matters: RL group rollouts sample one prompt many times. When the samples are identical, every reward in the group is the same and the advantage is zero.

Fix and semantics

This follows OpenAI: with no seed, each request gets a fresh random stream. An explicit seed is reproducible, and that includes seed: 0.

  • SamplerCfg gains has_seed and seeded() (has_seed || seed != 0). parse_request_sampler sets has_seed when the body contains "seed".
  • request_rng_seed(cfg) returns cfg.seed when seeded(), and otherwise 64 fresh bits from std::random_device. Every sampled request starts its stream from it: the slot manager, the single-lane backends (qwen35, qwen35moe, qwen3, gemma4, laguna, deepseek4), the layer-split adapters and qwen4exp. The qwen35 layer-split daemon loop parses samp= but decodes greedily, so it is left as it is.
  • The single-lane backends used to keep one persistent stream and reseed it only for a seeded request, so an unseeded request continued whatever the previous request left. After a repeated seeded request it repeated too: A(seed 7), B, A(seed 7), B gave B the same output twice. Every unseeded request now starts fresh, on every path, at any concurrency.
  • An explicit seed: 0 is reproducible on every in-process path.
  • Some transports carry only the seed value: the daemon samp=temp,top_p,top_k,rep_pen,seed tail and the cluster RequestMsg. Their wire formats are unchanged. There, a nonzero seed stays reproducible and 0 still means "no seed", as before.

Tests

Both are CPU-only. test_seq_slot_manager is already in the cpu ctest label.

  • test_seq_slot_manager: a new case admits two unseeded sampled requests and asserts that their rng streams differ, then reuses one slot and asserts that the next request's stream differs too. The existing seed-0 case now sets has_seed, and the greedy and explicit-seed cases are unchanged.
    • Before the fix (origin/main's seq_slot_manager.cpp): FAIL test/unit/test_seq_slot_manager.cpp:566: mgr.slot(a.slot).rng() != mgr.slot(b.slot).rng()
    • After the fix: OK test_seq_slot_manager (311 checks)
    • Built with plain g++ -std=c++17 from the test, seq_slot_manager.cpp and paged_kv_pool.cpp.
  • test_server_unit: a new case goes from the request body to the stream seed. With no seed, request_rng_seed differs on every call; seed: 0 gives 0 and seed: UINT64_MAX gives UINT64_MAX.
  • Full gfx1201 HIP build (luce_server, test_server_unit, test_seq_slot_manager) on main 32a3137: test_seq_slot_manager OK (311 checks), test_server_unit 0 failures.

Not yet re-measured on GPU. The 200-request run at concurrency 4 still needs repeating: expect about 200 distinct outputs without a seed, and identical outputs for a repeated explicit seed.

🤖 Generated with Claude Code

View guided diff

@Graffioh
Graffioh force-pushed the fix/parallel-unseeded-sampling branch from c1bed53 to d23a505 Compare October 22, 2026 10:52
@Graffioh
Graffioh marked this pull request as ready for review October 22, 2026 11:42

@davide221 davide221 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.

Code review

No issues found. Checked for bugs and logic errors in the changed code.

Reviewed d23a5056 · 0 candidate issues checked, kept at ≥70% confidence · add the code-review label to review again

…ency

With --max-concurrency > 1, the slot manager seeded every sampled
request's rng from sampler.seed, which is 0 when the request has no
"seed" field. Every unseeded request for the same prompt then drew the
same tokens: 200 requests at temperature 1.0 returned 2 distinct
outputs on the R9700.

SamplerCfg gains has_seed (set when the HTTP body names a seed) and
seeded(). request_rng_seed() returns the seed when seeded() and 64
fresh random bits otherwise. Every sampled request now starts its
stream from it: the slot manager, the single-lane backends, the
layer-split adapters and qwen4exp.
Single-lane unseeded requests used to continue the backend's stream
instead, so one after a repeated seeded request repeated with it. An
explicit seed, 0 included, is reproducible on every in-process path.
Transports that carry only the seed value (daemon samp= tail, cluster
wire) keep treating 0 as "no seed".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Graffioh
Graffioh force-pushed the fix/parallel-unseeded-sampling branch from d23a505 to cf8e5b6 Compare October 22, 2026 17:36
@davide221
davide221 merged commit aa1f746 into Luce-Org:main Oct 25, 2026
9 checks passed
davide221 added a commit to dusterbloom/lucebox-hub that referenced this pull request Oct 25, 2026
…lash DeltaNet ladder branch

Clean 3-way merge against the tested Luce-Org#850 head: Luce-Org#851 changes and the
main-side changes (Luce-Org#876 sampler seeding, Luce-Org#863 PFlash cleanup) are both
kept exactly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
davide221 added a commit to dusterbloom/lucebox-hub that referenced this pull request Oct 25, 2026
…rg#850, Luce-Org#876, Luce-Org#863) into kvflash turn checkpoints branch

Clean 3-way merge against the tested Luce-Org#851 head: Luce-Org#852 changes and the
main-side changes are both kept exactly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

2 participants