Python · Receivers and Deferred Calls

Receivers and Deferred Calls

import uformfrom uform import Deferred, On, DeferredOn 4.0.0-rc.1 · 3ee5e534

A receiver carries what every C argument structure puts before its inputs: the executor and the completion. The model runs a verb on the calling thread, model.on(executor) answers a uform.On whose verbs block on that executor, and model.deferred(executor) answers a uform.DeferredOn whose verbs submit there and answer a uform.Deferred. The receiver’s type alone chooses the completion, so all three offer the same verbs with the same arguments. In a coroutine, await a deferred call; anywhere else, wait() blocks the thread with its state detached:

call = model.deferred(executor).image_encode(files, uform.Arena(executor))
encoded = await call  # or: call.wait()

call.status polls without waiting, reading Status.DEFERRED until the call is final. Dropping a Deferred waits for its call first, since the library still reads the inputs it holds. A trainer runs step and save blocking on the executor it was created on, and trainer.on(...) and trainer.deferred(...) choose another completion.

API

Types

MoodWhat an executor does once it goes idle, valued as uform_mood_t: sleep, or keep polling.
__init__.py:90 ↗
class Mood(IntEnum)

Values

PARKED0
SPINNING1
ClassDeferredA call a DeferredOn submitted: await it, or wait() for it; dropping it waits.4
lib.pyi:377 ↗
class Deferred[AnswerT]
__class_getitem__Names what wait() answers, as Deferred[Encoded].
lib.pyi:382 ↗
def __class_getitem__(item: Any, /) -> GenericAlias
waitBlocks until the call is final, then answers or raises.
lib.pyi:391 ↗
def wait() -> AnswerT

Calls uform_outcome_wait.

__await__Runs wait() on the running event loop's default executor, suspending the task meanwhile.
lib.pyi:395 ↗
def __await__() -> Generator[Any, None, AnswerT]
statusStatus.DEFERRED until the call is final, then the final one.
lib.pyi:387 ↗
status: Status

Calls uform_outcome_status.

ClassOnA model or trainer bound to the executor its verbs block on, as model.on(executor) answers it.6
lib.pyi:1098 ↗
class On[TargetT]
__class_getitem__Names the target the receiver addresses, as On[Model].
lib.pyi:1103 ↗
def __class_getitem__(item: Any, /) -> GenericAlias
*× 6
lib.pyi:1107 ↗
def describe() -> ModelDescription
Symbol
describe
step
save
describe
step
save
*_encode× 8
lib.pyi:1108 ↗
def text_encode(
    texts: _Texts,
    arena: Arena,
    /,
    *,
    outputs: Outputs = ...,
    outputs_scalar: Scalar = ...,
    progress: _Progress | None = None,
    progress_steps: int = 0,
    stats: TextEncodeStats | None = None,
) -> Encoded
Symbol
text_encode
image_encode
video_encode
audio_encode
text_encode
image_encode
video_encode
audio_encode
image_encode_*_encode_pixels× 2
lib.pyi:1132 ↗
def image_encode__encode_pixels(
    pixels: Sequence[Buffer],
    arena: Arena,
    /,
    *,
    outputs: Outputs = ...,
    outputs_scalar: Scalar = ...,
    progress: _Progress | None = None,
    progress_steps: int = 0,
    stats: ImageEncodeStats | None = None,
) -> Encoded
audio_encode_*_encode_samples× 2
lib.pyi:1168 ↗
def audio_encode__encode_samples(
    samples: Sequence[Buffer] | _Tape,
    sample_rate: int,
    arena: Arena,
    /,
    *,
    outputs: Outputs = ...,
    outputs_scalar: Scalar = ...,
    progress: _Progress | None = None,
    progress_steps: int = 0,
    stats: AudioEncodeStats | None = None,
) -> Encoded
text_*_choose× 2
lib.pyi:1181 ↗
def text__choose(
    texts: _Texts,
    choices: _Texts,
    arena: Arena,
    /,
    *,
    temperature_groups: _Words | None = None,
    progress: _Progress | None = None,
    progress_steps: int = 0,
    stats: TextEncodeStats | None = None,
) -> RowsTape
ClassDeferredOnA model or trainer bound to the executor its verbs submit to, each answering a Deferred at once.1
lib.pyi:1213 ↗
class DeferredOn[TargetT]
__class_getitem__Names the target the receiver addresses, as DeferredOn[Model].
lib.pyi:1218 ↗
def __class_getitem__(item: Any, /) -> GenericAlias