Skip to content

Cache (2/5): Cache inference at do_inference - #122

Open
ErlisLushtaku wants to merge 1 commit into
cache-on-118/01-local-storefrom
cache-on-118/02-do-inference
Open

ErlisLushtaku wants to merge 1 commit into
cache-on-118/01-local-storefrom
cache-on-118/02-do-inference

Conversation

@ErlisLushtaku

@ErlisLushtaku ErlisLushtaku commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Description

Moves cache lookup and writes to do_inference.

  • PreparedModel defers backend construction until an input misses the cache.
  • Cache identity combines the canonical model input with the validated model descriptor.
  • Mixed batches run only missing inputs and restore the original output order.
  • Completion and judgement cache classes define their own stored rows.
  • Cached judgements restore first-token logprobs. Hits do not record provider usage.

This is stacked on #121.

@ErlisLushtaku
ErlisLushtaku force-pushed the cache-on-118/02-do-inference branch from 97138e9 to 965bacf Compare September 9, 2026 13:01
@ErlisLushtaku ErlisLushtaku changed the title Cache: WIP (2/6) Cache inference at do_inference Cache: WIP (2/5) Cache inference at do_inference Sep 9, 2026
@ErlisLushtaku ErlisLushtaku changed the title Cache: WIP (2/5) Cache inference at do_inference Cache (2/5): Cache inference at do_inference Sep 15, 2026
@ErlisLushtaku
ErlisLushtaku marked this pull request as ready for review September 15, 2026 07:40
@kargibora
kargibora force-pushed the cache-on-118/01-local-store branch from b1156b8 to 52a4620 Compare September 15, 2026 12:54
@kargibora
kargibora force-pushed the cache-on-118/02-do-inference branch from 58f0f59 to 969347c Compare September 15, 2026 12:54
Comment thread judgearena/inference.py


@dataclass(frozen=True)
class InferenceCache(ABC):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we create a seperate file for storing these cache objects?

Comment thread judgearena/models.py
cached_rows = store.query(input_hashes).set_index("input_hash")
results: list[InferenceResult | None] = [
(
InferenceResult(**cache.cached_result(cached_rows.loc[key]).__dict__)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we are converting CachedInferenceResult back to InferenceResult? If so we may not need CachedInferenceResultat all

Comment thread judgearena/models.py
)
for index, result in zip(missing_indices, generated, strict=True):
results[index] = result
cache.save_outputs(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this fail? If it fails for some reason the entire pipeline fails. We can put try except

  try:
       cache.save_outputs(...)
   except CacheWriteError as exc:
       logger.warning("Could not save inference cache: %s", exc)

Comment thread judgearena/models.py
return_top_logprobs: bool = False,
*,
stage: str = "unspecified",
cache_metadata: list[dict] | None = None,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think one thing that is confusing for me is this PR introduces some changes like cache_metadata which will be provided in the future PR's in #124. Design-wise it makes sense to first introduce it without wiring however while reading the PR it creates some readability problems. I think if necessary, creating large PR's (~1000-2000LOC) where we introduce the functionality while introducing the changes makes more sense to me.

Not a requirement for this PR (as I will review the entire stack as a single one)

Comment thread judgearena/models.py


def do_inference(
def _do_inference_uncached(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can rename this to _call_model or _invoke_model or similar (I am not creative enough). Because we will be using it to do inference for uncached samples, this reads like we will be doing inference without using the cache (although it is true we are doing it for uncached inputs, flow can be better)

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