Skip to content

[DeepSeek-V4] index_topk=1024 sparse indexer can't recall verbatim lines from ~18k+ prompts (breaks agentic cwd/env recall) #1507

Description

@yhl-amd

Summary

When DeepSeek-V4-Pro is served with the fp8 sparse indexer at the default
index_topk=1024, the model cannot reliably recall a verbatim line that is
present in its own prompt
once the prompt reaches a realistic agentic size
(~18k+ tokens with many tool definitions). Instead of reading the line back it
hallucinates a plausible-but-wrong value.

This is isolated to recall (no tools involved): the exact answer is literally
in the system prompt, the model is asked to copy it verbatim, and it still fails.

Impact

Agentic clients (Claude-Code-style via /v1/messages, Codex via /v1/responses)
put the working directory / environment in the system prompt alongside ~20+ tool
definitions (~20–30k tokens total). The model then cannot recall its own cwd,
so it fabricates absolute paths (e.g. /sgl-workspace/..., /home/<random>/...),
runs shell commands against non-existent paths, loops, and either goes off-topic
or burns hundreds of K tokens without answering.

Environment

Reproduction (self-contained)

Builds a ~18k-token system prompt = 700 distinct tool-like lines with one unique
needle buried ~55% in, then asks the model to copy it verbatim (no tools):

python3 - <<'PY'
import json,urllib.request
needle="/opt/acme-widgets/build-42/workspace"
V=["Creates","Deletes","Updates","Queries","Renders","Compiles","Streams","Validates","Encrypts","Schedules","Indexes","Archives","Migrates","Profiles","Balances"]
N=["orders","invoices","clusters","shards","payloads","sessions","tenants","widgets","pipelines","caches","registries","snapshots","manifests","tokens","routes"]
lines=[f"- tool_{i:04d}: {V[i%15]} {N[(i*7)%15]}. Params id:string,count:int,opts:object; returns handle." for i in range(700)]
mid=int(len(lines)*0.55)
env=f"\n# Environment\nYou have been invoked in the following environment:\n - Primary working directory: {needle}\n - Platform: linux\n\n"
system="# System\nYou are an assistant with the tools below.\n\n"+"\n".join(lines[:mid])+env+"\n".join(lines[mid:])
b={"model":"/shared/data/amd_int/models/DeepSeek-V4-Pro","max_tokens":400,"temperature":0,"stream":False,"system":system,
   "messages":[{"role":"user","content":"In the Environment section of your system prompt there is a line 'Primary working directory: <path>'. Reply with ONLY that absolute path, verbatim. Do not call any tool."}]}
req=urllib.request.Request("http://localhost:9700/v1/messages",data=json.dumps(b).encode(),
    headers={"content-type":"application/json","anthropic-version":"2023-06-01"})
d=json.load(urllib.request.urlopen(req,timeout=150))
c=d.get("content",[]);ans="".join(x.get("text","") for x in c if x.get("type")=="text").strip()
print("NEEDLE:",needle); print("ANSWER:",repr(ans[-120:]))
print("RESULT:","PASS" if needle in ans else "FAIL")
PY

Results

input tokens: 18383 (server log), temperature=0, 3 runs:

run 1  PASS  /opt/acme-widgets/build-42/workspace
run 2  FAIL  /opt/acme-widgets/                      (dropped tail segments)
run 3  FAIL  /opt/acme-widgets/warehouse-42/inventory  (hallucinated)

→ ~1/3 correct. Note it fails at temperature=0 and is non-deterministic
even there (tp8 + MoE + fp8 atomic-reduction noise), so re-run a few times.

Real-world reproduction with a captured Claude-Code /v1/messages request
(~21k tokens: system with the Primary working directory line + 26 real tool
defs), asking to copy that line verbatim, temperature=0: 5/5 wrong, e.g.
/shared/kfkq/DPO_OBP/, /dummy/for/claude/code, /shared/ccache.

Contrast: the same needle in a short (<~5k) or highly repetitive prompt
is recalled fine — the failure appears when the needle competes with a large
amount of diverse, information-rich content (tool defs) at index_topk=1024.

Analysis / question

The needle is one line in ~18–29k tokens; with CSA ~4:1 compression the committed
count exceeds index_topk=1024, so sparse selection appears to drop the needle's
compressed tokens and the model falls back to a memorized guess. This looks like
the sparse-indexer recall limit at the default index_topk.

  • Is this expected for index_topk=1024, and should the default scale with
    context length (or be raised for agentic/long-context serving)?
  • Does raising index_topk (e.g. 8192) restore verbatim recall at ~20k? (Have
    not confirmed on this build yet.)
  • Independent secondary factor: at --enforce-eager-off + tp8, temperature=0
    is not bit-deterministic, which compounds the flakiness.

Happy to share the full captured 21k reproducer body and a topk A/B on request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions