EvaluationCache¶
gepa.core.state.EvaluationCache(_cache: dict[CacheKey, CachedEvaluation[RolloutOutput]] = dict())
dataclass
¶
Bases: Generic[RolloutOutput, DataId]
Cache for (candidate, split, example) evaluation results.
Data loaders identify examples by position, so a trainset and a separate valset both number
their examples from zero. Every lookup therefore takes a required keyword-only split of
:data:TRAINSET_CACHE_SPLIT or :data:VALSET_CACHE_SPLIT. A valset that is a distinct loader
from the trainset uses VALSET_CACHE_SPLIT; when the two are the same loader the ids mean
the same thing and both sides share TRAINSET_CACHE_SPLIT so minibatch rollouts are reused
on valset evaluation.
Keys persisted before splits existed are (candidate_hash, example_id). Those cannot be
told apart from contaminated distinct-valset entries, so :meth:GEPAState.load drops them
rather than serving them. There is no default split: omitting it is a TypeError, not a
silent trainset hit.
Methods:¶
drop_unsplit_entries() -> int
¶
Discard entries written before splits existed. Returns the number dropped.
Those keys are (candidate_hash, example_id) with no namespace, so a valset rollout and
the trainset rollout at the same position were stored under the same key. They can no longer
be served (every lookup is namespaced now), and keeping them would grow the persisted state
on every resume, so GEPAState.load drops them.
Source code in gepa/core/state.py
get(candidate: dict[str, str], example_id: DataId, *, split: str) -> CachedEvaluation[RolloutOutput] | None
¶
Retrieve cached evaluation result if it exists. split is required.
Source code in gepa/core/state.py
put(candidate: dict[str, str], example_id: DataId, output: RolloutOutput, score: float, objective_scores: ObjectiveScores | None = None, *, split: str) -> None
¶
Store an evaluation result in the cache.
Source code in gepa/core/state.py
get_batch(candidate: dict[str, str], example_ids: list[DataId], *, split: str) -> tuple[dict[DataId, CachedEvaluation[RolloutOutput]], list[DataId]]
¶
Look up cached results for a batch. Returns (cached_results, uncached_ids).
Source code in gepa/core/state.py
put_batch(candidate: dict[str, str], example_ids: list[DataId], outputs: list[RolloutOutput], scores: list[float], objective_scores_list: Sequence[ObjectiveScores] | None = None, *, split: str) -> None
¶
Store evaluation results for a batch of examples.
Source code in gepa/core/state.py
evaluate_with_cache_full(candidate: dict[str, str], example_ids: list[DataId], fetcher: Callable[[list[DataId]], Any], evaluator: Callable[[Any, dict[str, str]], tuple[Any, list[float], Sequence[ObjectiveScores] | None]], *, split: str) -> tuple[dict[DataId, RolloutOutput], dict[DataId, float], dict[DataId, ObjectiveScores] | None, int]
¶
Evaluate using cache, returning full results.
Returns (outputs_by_id, scores_by_id, objective_scores_by_id, num_actual_evals).