Imp.Optimizer.GEPA.BatchSampler behaviour (Imp v0.5.0)

Copy Markdown View Source

Stateful minibatch selection for GEPA.

The built-in epoch-shuffled strategy matches the pinned source default. A custom strategy is a struct whose module implements this behaviour. Its identity and state are checkpointed so resume cannot silently substitute or reset the consumer's sampling policy.

Summary

Types

context()

@type context() :: %{iteration: non_neg_integer(), call_index: non_neg_integer()}

rng_state()

@type rng_state() :: Imp.Optimizer.GEPA.Random.state()

t()

@type t() :: %Imp.Optimizer.GEPA.BatchSampler{
  calls_in_iteration: non_neg_integer(),
  current_iteration: non_neg_integer() | nil,
  custom_identity: term() | nil,
  custom_strategy: struct() | nil,
  epoch: integer(),
  id_freqs: %{optional(non_neg_integer()) => pos_integer()},
  last_trainset_size: non_neg_integer(),
  minibatch_size: pos_integer() | nil,
  shuffled_ids: [non_neg_integer()],
  trainset_identity: String.t() | nil
}

Callbacks

dump_state(struct)

@callback dump_state(struct()) :: map()

identity(struct)

@callback identity(struct()) :: term()

load_state(struct, map)

@callback load_state(struct(), map()) :: struct()

minibatch_size(struct)

@callback minibatch_size(struct()) :: pos_integer()

next_minibatch_ids(struct, list, context, rng_state)

@callback next_minibatch_ids(struct(), [term()], context(), rng_state()) ::
  {[non_neg_integer()], struct(), rng_state()}

Functions

dump(sampler)

@spec dump(t()) :: map()

load!(state)

@spec load!(map()) :: t()

new(minibatch_size \\ nil)

@spec new(pos_integer() | nil) :: t()

next_batches(sampler, trainset, size, count, iteration, rng_state)

@spec next_batches(
  t(),
  [term()],
  pos_integer(),
  pos_integer(),
  non_neg_integer(),
  :rand.state()
) ::
  {[{[term()], [non_neg_integer()]}], t(), :rand.state()}