Skip to content

feat(server): TF_SEED=random — an opt-in re-roll when a request omits the seed - #2

Merged
bertholomus merged 1 commit into
bertholomus:deepseek-v41-tp2from
Capicua25x:tf-seed-random
Oct 17, 2026
Merged

bertholomus merged 1 commit into
bertholomus:deepseek-v41-tp2from
Capicua25x:tf-seed-random

Conversation

@Capicua25x

Copy link
Copy Markdown

Motivation

Following up on the loop guard (dfbe519f, and the #9 novelty signal it carries) — the guard makes a collapse graceful: it closes thinking and the reply goes on to answer. This PR is about what happens to the retry after a turn fails, which the guard does not reach.

When a request omits seed, the engine derives one from the prompt hash — exact_sampling.seed_for, whose docstring states the intent: "the same conversation samples the same reply." For evals that is exactly right. For an agent harness that re-sends an unchanged history it is a trap:

a retry is not a re-roll — it is the same trajectory, replayed.

Measured on a real long tool-heavy agentic session (~400k tokens, DeepSeek-V4.1-Flash, TP2 on 2x GB10, t=0.6 / top_p=0.95):

condition runs outcome
omitted seed (seed_for) 2 looped BOTH, loop start 40,035 vs 40,096 — novelty curves identical to 4 decimals through char 40k
same session, production retries 6 aborts in 20 min all pinned to the same ~40k region
explicit seeds 1–5 5 4 answered clean; 1 looped at char 24,054 — a different attractor

So the collapse base rate on that history is real but modest (~20%); the prompt-keyed seed pins this particular conversation into it, deterministically, on every retry. Turning off the drafter (--mtp-drafts 0) changed nothing — same char, same trajectory — so this is not a speculation about drafting; it is the sampling seed. The v0.5.1 fp32 fix addresses the greedy class; it does not change this one (verified on 90b68e0: guard+fp32 present, three replays still bit-identical).

What this PR does

Adds an opt-in re-roll for the omitted-seed path, in the house convention of TF_LOOP_GUARD — env flag, default = current behavior, validated at import like TENSORFOLD_SEED_SALT:

TF_SEED=prompt    # default — unchanged: omitted seed keyed to the prompt
TF_SEED=random    # omitted seed draws fresh per request (same int63 range)

A per-request "seed" still wins in both modes. seed_for itself is untouched — reproducible evals keep their guarantee.

One function, three sites (the trap this PR also removes)

The omitted-seed choice is currently open-coded at three places, and they are not all on every serve's path:

  • engine/exact_sampling.py::seed_for — the helper.
  • server/request_options.py::_resolve_sampling — the shared options layer.
  • cuda/server.py::sampling_for — the site that answers on CUDA serves.

We learned this the hard way: patching only request_options made TF_SEED=random a silent no-op on the TP2 CUDA path — measured, three identical replays with the flag set. This PR factors the choice into default_seed() and routes all three sites through it, so they cannot drift.

Tests

  • Fingerprint: two identical streamed requests, t=1.0, thinking ON, reasoning streams compared byte-for-byte. TF_SEED=prompt: identical. TF_SEED=random: diverge. (Comparing only a truncated reply is a false positive — the first tokens are shared; we hit that trap too.)
  • Loop replay x3 on the poisoned history above, t=0.6/p=0.95, with the guard also on:
lane outcome
shipped (seed_for, no guard) 0/3 answered; every run loops at the SAME char, bit-identical across runs
guard + fp32, seed flag inert 3/3 answered via the guard — but bit-identical trajectories
guard + this PR 3/3 answered: two runs guard-closed at ~24k/~28k then answered; one never drifted (clean at 9.2k). No two alike, no voids, no cap waste

Unrelated observation found while testing (no code change here)

RankCache.open deletes prior rank{r}of{w}-* files on a key miss before checking disk room. The key includes bool(dspark) and the layer count, so a one-flag experiment (--mtp-drafts 5 -> 0) unlinks a ~100 GB cache that may not fit to rebuild on a tight disk — fast boots lost permanently, silently. (We had to rename caches by hand across such an A/B: 106 GB/rank, 90 GB free.) Keep-old-until-new-verifies, or a loud log line before unlinking, would close it.

Notes

  • random.getrandbits(63) keeps the exact seed_for range; the seed stays a non-negative int63 wherever it is packed (multi._pack — unchanged).
  • With TF_SEED=random, batched streams carry distinct seed rows in _pack — per-stream admission data, not a compatibility key; no concurrency cost measured.
  • Clean-room note: the diagnosis and measurements were made on our own TP2 deployment; no code from other DeepSeek-V4.1 recipes was consulted.

…the seed

An omitted seed is keyed to the prompt (seed_for), which is right for reproducible
evals and a trap for a retrying agent harness: the same history samples the same
trajectory, so a retry replays the same loop at the same character. Measured on a
long tool-heavy session: derived seed looped 2/2 bit-identical; explicit seeds
answered 4/5. The choice now lives in one default_seed() routed through all three
seed sites (exact_sampling, request_options, and cuda/server, the one that answers
on CUDA serves); per-request seed still wins; TF_SEED=prompt is the unchanged default.
@bertholomus

Copy link
Copy Markdown
Owner

Thank you @Capicua25x — the "a retry is not a re-roll, it is the same trajectory replayed" framing, with the identical novelty curves to prove it, makes the problem very clear.

We're not merging it now: it adds a new runtime knob, and in maintenance mode we're only taking small fixes that keep existing behavior untouched. Leaving it open for the maintainers — the measurements you attached should make that call easy when there's a development window again. Thanks again.

@bertholomus
bertholomus merged commit 8e0966e into bertholomus:deepseek-v41-tp2 Oct 17, 2026
@bertholomus

Copy link
Copy Markdown
Owner

Thank you @Capicua25x, merged. Development is back on, so this opt-in switch fits now. With TF_SEED unset a request gets the same seed as before (the server tests pass, 232 of 232), and TF_SEED=random gives every request without a seed a fresh one.

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