Skip to content

Prompt cache: an opt-in rule for families to count keyed image prompts as repeats - #1929

Merged
ashhart merged 3 commits into
ashhart:mainfrom
laudney:pr-ocr-cache-repeat-keyed
Nov 2, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
laudney:pr-ocr-cache-repeat-keyed

Conversation

@laudney

@laudney laudney commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1927.

The repeat log keeps only raw prompts: a request with images or a cache key is never noted, so every family keeps today's policy for image prompts. OCR families want the opposite for their own requests. Users resubmit the same page with the same instruction, and the prompt state that resumes it is keyed by image content and frame identity, not by the raw token IDs. This PR lets a family opt in to noting those keyed prompts, under the same key its lookups and saves use, and leaves every existing family unchanged.

Before (main) After (this PR)
Image or keyed prompt in the repeat log never noted noted only if the family sets Rules.repeat_keyed
Existing families raw prompts only unchanged: raw prompts only
Key a repeat is noted under raw token IDs raw token IDs; with the flag, the image-aware cache key that lookups and saves use
prompt_cache.zig size 599 lines (lean limit 600) 572 lines + prompt_rules.zig 31
Room to add a cache rule none yes

Changes

  • refactor(cache): prompt_cache.zig sits at the 600-line limit, so no rule can be added there. Rules depends on nothing else in the store, so it moves unchanged into zig/src/core/prompt_rules.zig, and prompt_cache.zig re-exports it. Every caller and default stays the same.
  • feat(cache): Rules.repeat_keyed: bool = false. lane_host still notes raw prompts (no images, no cache key) exactly as before. With repeat_keyed, it also notes a request that carries a cache key, under job.cacheKey(). A family sets it in its own Rules. No family sets it in this PR. GLM-OCR and Nemotron Parse will set it (Native OCR models on HIP: dots.mocr, GLM-OCR, LightOnOCR-3 and Nemotron Parse, CUDA to follow (tracker) #1927).

Gates

  • lane_host_frame_test.zig: the frame-cache test runs with the flag off and on. With it off, a repeated keyed image request leaves the repeat log empty, as on main. With it on, the repeat keeps its cut and the next request resumes from it with the same output tokens.
  • zig build test-lane-api-host: 456/456.
  • Host suites at the stack tips: zig build test with the tokenizer PR on top, 465/465 steps, 6,177/6,222 tests (45 skipped); zig build test -Dhip=true with the rocBLAS PR beneath, 492/492 steps, 6,187/6,234 tests (47 skipped).
  • Lean checker: zero new problems over the 425 baseline (prompt_cache.zig 572 lines, prompt_rules.zig 31).
  • No GPU code changes.

laudney and others added 3 commits November 2, 2026 15:51
prompt_cache.zig sits at the 600-line lean limit, so no family can add
a cache rule without splitting it. The Rules struct depends on nothing
else in the store, so it moves unchanged into prompt_rules.zig and
prompt_cache.zig re-exports it, leaving every caller and default as
before.
The repeat log only notes raw prompts, so image and keyed requests
never earn a repeat cut, and an OCR family that serves the same page
image again re-prefills it every time. A new prompt cache rule,
repeat_keyed, lets a family opt in: the lane host then notes a keyed
request under the same effective cache key that lookups and saves
use, so its second pass keeps a repeat cut and later passes resume
from it. The rule defaults to false, so existing families keep the
raw-prompts-only behavior, and frame tests cover both settings.
@ashhart
ashhart force-pushed the pr-ocr-cache-repeat-keyed branch from 0f809ac to a5a7aaa Compare November 2, 2026 15:51
@ashhart
ashhart merged commit 94cce45 into ashhart:main Nov 2, 2026
11 checks passed
@ashhart

ashhart commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Thank you @laudney. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

@laudney
laudney deleted the pr-ocr-cache-repeat-keyed branch November 2, 2026 21:03
@ashhart

ashhart commented Nov 3, 2026

Copy link
Copy Markdown
Owner

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