DS4 DeepSeek Quants Repeat Tool Calls Indefinitely
I tried running SWE bench verified mini with the ds4 engine (HIP fork on AMD Strix Halo, 128GB) and two quants:
- DeepSeek-V4-Flash-IQ2XXS-w2Q2K-AProjQ8-SExpQ8-OutQ8-chat-v2
- DeepSeek-V4-Flash-Q4KExperts-F16HC-F16Compressor-F16Indexer-Q8Attn-Q8Shared-Q8Out-chat-v2-imatrix (this distributed across two devices)
The coding harness is pi and this is my benchmark harness: https://github.com/kyuz0/pi-bench.
Issue - Repeating Tool Calls Indefinitely
I noticed that both quants tend to get into a loop and repeat the same tool call, such as a file read, forever. Even when the benchmark detects this and tries to break the behaviour and prompts the model to do something else, it still falls back to its looping behaviour.
In contrast, I ran some tasks from the benchmark using an FP4 quant on OpenRouter, and this behavipur was not present, the model being able to complete its tasks successfully.
1. Loop Frequency and Severity
- FP4 (OpenRouter):
- Zero loops detected. The model consistently makes progress, correctly adjusts arguments based on tool outputs, and finishes the tasks efficiently. For instance,
django__django-11790finished in 39 tool calls, anddjango__django-11848in just 12.
- Zero loops detected. The model consistently makes progress, correctly adjusts arguments based on tool outputs, and finishes the tasks efficiently. For instance,
- Q4 (ds4-hip):
- Significant looping detected. In
django__django-11848, the model reached 97 tool calls, heavily looping onreadandbash(e.g., runningsed -n '158,200p' django/utils/http.py7 times). Max consecutive identical loops reached up to 6 indjango-11790.
- Significant looping detected. In
- Q2 (ds4-hip):
- Severe looping detected. In
django__django-11790, the model made 78 tool calls, with one specificreadcall (offset 55) repeated 36 times. Max consecutive loops reached 11.
- Severe looping detected. In
2. Context of the Loops
Observation 1: Ignoring System Hints
In the read tool loops (e.g., Q2 on django-11790), the model requests lines from a file. The tool output explicitly truncates and appends a hint: [352 more lines in file. Use offset=85 to continue.].
- Behavior: The model's reasoning trace acknowledges that it needs more information (e.g., "Let me read the UsernameField class definition more carefully" or "Let me see more of this file"). However, it issues the EXACT same
readcommand with the original offset (offset=55), rather than incrementing it to85.
Observation 2: Amnesia / State Stagnation
In bash command loops (e.g., Q4 on django-11848), the model repeatedly runs the same sed command to view a function.
- Behavior: The model thinks, "Let me look at the full function to understand the current implementation", runs
sed, gets the output, and in the very next turn thinks again, "Let me read the full function:..." and runs the exact samesedcommand. It behaves as if it has forgotten the immediate previous step or failed to absorb the information into its context.
3. Context Length Analysis
I analyzed the token usage at the onset of these loops to determine if context window overflow was the culprit.
- Q2 Loop Onset: In
django-11790, loops begin around Step 53, at which point the context length is ~14,800 tokens. The transcript continues up to ~26,000 tokens. - Q4 Loop Onset: In
django-11848, loops begin around 17,000 tokens and continue up to ~45,000 tokens. - Conclusion on Context: DeepSeek V4 Flash natively supports very large context windows (128k+). The loops begin well before any standard extreme context limits, suggesting the issue is not simply a hard context cutoff, though it could be related to how the engine handles attention at these moderate lengths.
Data
You will find all the transcripts for runs for the same tasks that I was able to run across the three quants (Q2/Q4/FP4) i nthe debug folder:
https://github.com/kyuz0/pi-bench/blob/main/debug
You'll notice I wasn't able to get many tasks done with DeepSeek-V4-Flash-Q4KExperts-F16HC-F16Compressor-F16Indexer-Q8Attn-Q8Shared-Q8Out-chat-v2-imatrix as this is running across two strix halo nodes and that is, well... very slow! But still, there is enough evidence to show the looping/repeating behaviours.
I also had Gemini 3.1 Pro look at the runs and make a quick summary report (some of it MAY be AI slop, but in general it's capturing good observations):
https://github.com/kyuz0/pi-bench/blob/main/debug/analysis_report.md
Not sure where else to share this, but if somebody sees something in the transcripts of the three quants for the same tasks that sheds some light on what could be wrong...
What next?
I have a few requests:
- Are people on Apple silicon or Nvidia GPUs seeing the same behaviour? Is anybody willing to pull my benchmark harness and try to run it to check?
- Could this be a quantization calibration issue, I would expect Q4 to perform decently and similarly to FP4, but perhaps that expectation is wishful thinking
Hi @kyuz0, Thanks for the very detailed writeup. A couple of things I'd rule out before pinning it on quantization calibration.
The "model's reasoning says offset=85, actual call has offset=55" pattern is the bit that stood out. That gap usually shows up when either the prompt template eats the "[Use offset=85 to continue]" hint (so the reasoning is confabulating it saw it) or sampling is too deterministic to break out (low temp, no repetition_penalty). Worth diffing what pi sends to ds4 vs OpenRouter on both fronts before assuming it's a weights problem.
The IQ2XXS + bf16 KV angle is plausible too, especially since gfx1151 has had bf16 numerical edge cases turning up in other inference paths recently. At 14-17k tokens the cumulative precision loss in attention could be enough that recent tool output stops weighing on the next decision. Q4 looping later but still looping is consistent with that as a contributing factor.
This need to be confirmed with Metal since the ROCm branch is currently not officially supported, but today I'll receive a Strix Halo and should be able in the next days to start the work to support it, ensure correctness and so forth.
Thank you @antirez , we have since figured out the issue, indeed it was due to a mistake in the ROCm branch (missing indexer and some precision issues that led to long context behaviour issues), and we confirmed the fix resolves the looping behaviour.