Skip to content

Commit

Permalink
pickle stuff in llm caching path bc not everything is jsonifiable
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Lindeman <[email protected]>
  • Loading branch information
HenryL27 committed Jan 30, 2025
1 parent 98ce6a0 commit 1789409
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/sycamore/sycamore/llms/llms.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def _llm_cache_get(self, prompt: RenderedPrompt, llm_kwargs: Optional[dict]) ->
key = self._llm_cache_key(prompt, llm_kwargs)
hit = self._cache.get(key)
if hit:
hit = pickle.loads(hit)
assert (
len(hit) == 5
and hit.get("prompt") == RenderedPrompt(messages=prompt.messages)
Expand Down Expand Up @@ -156,13 +157,15 @@ def _llm_cache_set(self, prompt: RenderedPrompt, llm_kwargs: Optional[dict], res
key = self._llm_cache_key(prompt, llm_kwargs)
self._cache.set(
key,
{
"prompt": RenderedPrompt(messages=prompt.messages),
"prompt.response_format": self._pickleable_response_format(prompt),
"llm_kwargs": llm_kwargs,
"model_name": self._model_name,
"result": result,
},
pickle.dumps(
{
"prompt": RenderedPrompt(messages=prompt.messages),
"prompt.response_format": self._pickleable_response_format(prompt),
"llm_kwargs": llm_kwargs,
"model_name": self._model_name,
"result": result,
}
),
)

def get_metadata(self, kwargs, response_text, wall_latency, in_tokens, out_tokens) -> dict:
Expand Down

0 comments on commit 1789409

Please sign in to comment.