r/LocalLLM • u/Realistic-Elephant-6 • 5h ago
Research Monkey-patched "Latent Reasoning" on DeepSeek-V4.1-Flash at home (two DGX Sparks)
Edit: I run Deepseek-V4.1-Flash at home as my agent's brain and for various work tasks. It is at the edge of what I can run, so I am always looking for ways to improve it. This was an experiment in that direction that I ran about a week ago.
TL;DR: during the thinking block, I fed the model the probability-weighted mix of token embeddings that it produced, instead of it's "reasoning trace" text (embedding of the one token that was sampled). No training, no weight changes. The model keeps its accuracy, thinks 4–18 % fewer tokens on open-ended reasoning (the larger figures shrank on a repeat), shows no change on mechanical arithmetic, and occasionally loops; on real agent work it looped far more often. Because speculative decoding has to be restricted inside thinking, it ends up slower in wall-clock time than plain serving. (An interesting null result with one real effect in it.)
Setup
- Two DGX Spark (GB10) boxes, tensor parallel 2 over the ConnectX link.
- DeepSeek-V4.1-Flash, EXL3 quantisation at 2.75 bits per weight (exllamav3), served with vLLM and a speculative drafter (5 draft tokens per step). The serving stack is not mine: it is sudoingX's
dgx-spark-deepseek-v41recipe with HeNryous's vLLM changes on top. Without their work this model would not run on two Sparks at all, let alone fast enough to experiment on. - A patch to the GPU model runner: per-request options, a hook that replaces the input embedding at the next position, per-step diagnostics. Requests that don't ask for it run unchanged (checked with teacher-forced log-probabilities: the difference between images is inside vLLM's own run-to-run noise).
The idea
Normally step t+1 is fed E[token sampled at t]. Everything else the model "considered" at step t is thrown away. Inside <think> I fed instead
(1 − α) · E[sampled token] + α · inject
with several choices for inject:
| name | inject |
|---|---|
| soft | the expected embedding, Σ pᵢ·E[i], from the model's own distribution |
| hidden | the final hidden state, rescaled to embedding norm |
| map | the hidden state passed through a linear map fitted to land in embedding space |
| noise | random vector of the same norm (control) |
The visible transcript still shows the sampled token. The answer after </think> is generated normally.
How it was measured
All problems are generated from a seed with fresh numbers and invented names, so nothing can be recalled from training data, and every answer is checked exactly.
- Arithmetic and procedures: multiplication, nested expressions, counting, word problems, tracing a loop.
- Search: rule induction, subset sums, cryptarithms (answers proven unique by enumeration).
- Polarity: signed causal chains, orderings with mixed comparatives, cause-and-effect stories.
Outcomes: accuracy (paired test against plain runs) and the number of thinking tokens (paired geometric-mean ratio with a bootstrap interval). vLLM is not deterministic, so every comparison has two plain runs and the distance between them is the yardstick.
Results
The thinking of this model is almost deterministic. On arithmetic the entropy is about 0.3 nats per thinking step, and only about one step in eight is above 1 nat. On search problems and real work it is 0.6–1.1 nats. At most steps the "mix" is simply the sampled token's embedding, so there is little to feed back.
Accuracy never moved for the soft mix. Examples: 577 against 584 of 600 on arithmetic (not significant), 240 of 240 on polarity problems in every arm, 33 against 31 and 28 of 60 on hard search problems.
Hidden states do not work without training. The final hidden state is orthogonal to the embedding space (cosine −0.01). At α = 0.3 it behaves like noise; at α = 1 the model produces garbage. A ridge map was harmful at α = 0.3; a map fitted on 100,000 captured states was harmless at 0.3 and harmful at 1.
Thinking gets shorter on open-ended reasoning, at full strength only (α = 1; fixed criteria, fresh problems, all answers still correct):
| problem set | thinking tokens, soft α = 1 against plain | against the noise control |
|---|---|---|
| polarity (240 problems) | 0.94–0.95 | 0.96 |
| subset sums (80 problems) | 0.82–0.89 | 0.87 |
| arithmetic (600 pairs) | 1.00 (interval 0.97–1.03) |
All six intervals for the first two rows exclude 1. Within arithmetic, word problems and counting were about 8 % shorter and pure multiplication 8 % longer. At α = 0.5 there is no effect at all, and the noise control shows none.
Costs at full strength:
- The transcript stutters. Doubled punctuation and words, occasionally a dropped number. The model's answers don't suffer, so it evidently reasons from what it was fed, not from what the transcript shows.
- Loops. 2 of 38 long real-world requests ran into a repetition loop; on benchmarks it was between none in 600 and 3 in 240, depending on the problem set and the run. Plain decoding looped once in 160 search problems as well, with the same shape: the model asks itself a sum and never answers it.
- The prefix cache stops matching. The sampled tokens
..come back from the client as text and tokenize as.., so replayed reasoning never hits the KV cache past the prompt. - Speculative decoding. Checking draft tokens in one pass needs the input at each position in advance, and here that input depends on the previous position's output. The first version switched drafting off inside thinking, which halved decode speed (18 against 34 tokens/s).
Keeping the drafter: a gate
At 60–70 % of steps the model is confident and the mix equals the plain embedding. So the mix is fed only when the sampled token's probability is below a threshold; drafted tokens are accepted as usual up to the first such step and the rest of the window is discarded, exactly as after a rejected draft.
| setting | steps that get the mix | tokens per pass in thinking | decode speed | thinking tokens against plain (polarity) |
|---|---|---|---|---|
| plain | – | – | 31–36 tok/s | 1 (two plain runs differ by 0.97) |
| mix at every step, no drafting | 100 % | 1 | 17 | 0.94–0.96 |
| gate 0.99 | 43–48 % | 1.7–1.9 | 20 | 0.93–0.95 |
| gate 0.7 | 22–26 % | 2.2–2.6 | 24–26 | 0.94–0.97 |
Measured on 240 polarity and 80 subset-sum problems plus 100 arithmetic ones, all with unchanged accuracy. The gated variants keep the shorter thinking on the polarity problems (all intervals exclude 1, some only just). On subset sums the effect shrank on this second measurement (0.89–0.93 without the gate, intervals for the gated runs include 1), so the 18 % above was the lucky end of the range. The sums do not work out either way: gate 0.7 takes 20–25 % more time for 3–6 % fewer thinking tokens.
The gate comes with a loop guard: when the recent thinking repeats with a short period, the mix is switched off for the rest of the block. It tripped 7 times in 840 gated requests, never falsely. Four of the six loops that the mix had caused recovered and finished correctly; two kept looping under plain decoding, because the repetition was already in the context. The stutter is unchanged by the gate.
Trying it on real work
With the benchmarks looking harmless, gate 0.7 ran as the server default for a few hours of ordinary agent work (long prompts, tool use). It did not go well:
- The mix was fed at 36 % of thinking steps, not the 15–26 % seen on the benchmark problems. Real prompts leave the model less certain per step, so "only when unsure" stops being rare.
- The loop guard tripped in 6 of 77 requests, against 1 in 420 on the benchmarks. Four recovered. One ran to the thinking budget, and one repeated a single word until it was stopped by hand: switching the mix off does not end a loop that is already in the context.
- The thinking ahead of that loop was garbled, well beyond the mild stutter measured before.
So the benchmark picture (same accuracy, slightly shorter thinking, rare loops) does not carry over to long real-world prompts. Short synthetic problems, where the model is confident at three steps in four, were the friendly case.
What I take from it
- A heavily quantised production model tolerates being fed mixtures it was never trained on, at every thinking step, and still gets the same answers. That robustness was the surprise.
- Without training, "same answers, somewhat fewer thinking tokens on open-ended problems" appears to be the ceiling. Published work on continuous or soft reasoning trains the model to use such inputs; this is what the untrained end of that looks like.
- To be useful it would need three things: a model trained to use the mix, a drafter that proposes for it, and the mix round-tripped through the API (sampled ids plus the top few probabilities per step) so that replay and KV caching work.
- Side product: a seeded problem generator and harness that measures accuracy, thinking length, budget hits, stutter and loops, usable on any OpenAI-compatible server.
Who did what
The idea and the direction were mine, along with questions and the occasional suggestion along the way. Essentially everything else was done by an AI assistant, Claude (Anthropic's Claude Code, working with subagents): tracing the serving code, designing and writing the patch, the problem generators and the measurement harness, deciding the test criteria before each run, running and analysing the experiments, finding and fixing its own bugs (including one that crashed the engine), and writing this post. I reviewed, restarted servers, and reported what I saw in real use, which is how the loops were found.
Code
The patch (about 2,000 lines against the vLLM runner), the problem generators and the harness are in a private repository. If anyone is interested, I'm happy to publish them.
Caveats
One model, one quantisation, one sampling temperature (0.6). Problem sets of 60–600 items, so effects under about 3 % are invisible. The per-family splits were looked at after the fact. Speeds are from a shared home setup and vary with load.
1
u/Aggravating-Push-207 5h ago
The first three are mathematically the same assuming tied embeddings btw
1
u/AdSome6934 4h ago
The loop finding is the part that matters for agent work, and it's why I'd put a hard cap on the thinking block whether or not the injection helps. A loop doesn't hand you a wrong answer, it hands you a confident one after burning the whole budget, and by then a tool call has usually already gone out. Cap the thinking tokens and the loop becomes a fast, loud, empty return you can catch and retry instead of a plausible decision you find out about later. I run V4.1-Flash on DGX boxes too and the thinking block burns 1000+ tokens before it answers anything, so the cap has to be generous, but it should exist and be treated as a failure rather than a truncated answer.