EvSys

batch_utils

Small shared helpers for turning backend forward-backward / sampling outputs into plain Python, used by the SFT / SDFT algorithms' step_metrics and batch construction.

Kept backend-agnostic: MockBackend emits Python lists; the real TinkerBackend emits tinker.TensorData (with .to_torch()) and tinker SamplingResponse objects. These helpers normalize both.

attribute__all__
= ['coerce_floats', 'extract_weights', 'extract_completion_tokens_from_response']
funccoerce_floats(value) -> list[float] | None

Best-effort: turn a TensorData / list / torch.Tensor into list[float].

Returns None when the value can't be coerced (so callers can skip it).

paramvalueAny

Returns

list[float] | None
func_flatten_floats(seq) -> list[float] | None

Flatten an arbitrarily-nested list of numbers to list[float]. Returns None if a leaf isn't coercible to float.

paramseqAny

Returns

list[float] | None
funcextract_weights(datum) -> Any

Pull the per-position weight mask out of a Datum's loss_fn_inputs.

paramdatumtinker.Datum

Returns

typing.Any
funcextract_completion_tokens_from_response(response) -> list[int]

Pull the token-id list out of a tinker SamplingResponse-shape object.

Real tinker exposes .sequences[0].tokens; MockSamplingClient does the same; either way we get a list of ints back.

paramresponseAny

Returns

list[int]