JavaScript · Receivers and Deferred Calls

Receivers and Deferred Calls

import * as uform from 'uform';import { ModelOn } from 'uform';import { ModelDeferredOn } from 'uform';import { TrainerDeferredOn } from 'uform';import { Deferred } from 'uform'; 4.0.0-rc.1 · 3ee5e534

The same verbs run on the calling thread with no receiver, and block on an executor through on:

const here = model.textEncode(["a small red panda"], arena);
const there = model.on(executor).textEncode(["a small red panda"], arena);

API

Types

ProgressCallbackHears a long call's advance; answering false stops it with cancelled.
uform.ts:23 ↗
type ProgressCallback = (completed: number, total: number) => boolean | void
MoodWhat an executor does with its threads or streams once it goes idle.
uform.ts:52 ↗
enum Mood

Values

Parked"parked"Idle threads sleep; the next call pays a wake-up.
Spinning"spinning"Idle threads stay hot, trading power for the next call's latency.
AnswerHow a receiver hands back what its verbs answer: as is, or as a Deferred of it.
uform.ts:494 ↗
type Answer<Receiving, Answered> = Receiving extends "deferred" ? Deferred<Answered> : Answered
ClassModelOnThe verbs of one model, blocking on one executor: model.on(executor).10
model.ts:81 ↗
class ModelOn extends ModelVerbs<"blocking">

Every call starts after every earlier submission to that executor, and returns with its outputs written.

ModelOnMade by model.on(executor), never directly.
model.ts:83 ↗
new ModelOn(
    compiled: CompiledModel,
    executor: Executor | undefined,
)
*× 2Reports the model's geometry and placement in one call.
model.ts:68 ↗

Inherited from ModelVerbs

describe(): Answer<Receiving, ModelDescription>

Calls uform_model_describe.

text*× 2Encodes texts through one forward; every UTF-8 byte is a token.
model.ts:368 ↗

Inherited from EncodeVerbs

textEncode(
    texts: readonly (string | Uint8Array)[] | Tape<Uint8Array>,
    arena: Arena,
    config: EncodeConfig = {},
): Answer<Receiving, Encoded>

Calls uform_text_encode.

Parameters

textsreadonly (string | Uint8Array)[] | Tape<Uint8Array>Strings, UTF-8 bytes already encoded, or a tape of them.
arenaArenaThe memory the outputs land in, rewound by the call.
configEncodeConfigThe surfaces, their scalar, and a progress handler.

Returns

The outputs, viewed inside arena.
text*× 2Scores each item's legal choices through one forward, a softmax over them alone at the item's group's calibrated inverse temperature; a model without the byte decoder reports unsupported.
model.ts:393 ↗

Inherited from EncodeVerbs

textChoose(
    texts: readonly (string | Uint8Array)[] | Tape<Uint8Array>,
    choices: readonly (string | Uint8Array)[] | Tape<Uint8Array>,
    arena: Arena,
    config: ChooseConfig = {},
): Answer<Receiving, Chosen>

Calls uform_text_choose.

Parameters

textsreadonly (string | Uint8Array)[] | Tape<Uint8Array>The states, each ending where its choice goes.
choicesreadonly (string | Uint8Array)[] | Tape<Uint8Array>Each item's legal choices, one byte each, like "yn".
arenaArenaThe memory the probabilities land in, rewound by the call.
configChooseConfigThe question types and a progress handler.

Returns

The probabilities, viewed inside arena.
image*× 2Decodes and encodes JPEG, PNG or WebP files; the browser build reports unsupported.
model.ts:433 ↗

Inherited from EncodeVerbs

imageEncode(
    images: readonly Uint8Array[] | Tape<Uint8Array>,
    arena: Arena,
    config: EncodeConfig = {},
): Answer<Receiving, Encoded>

Calls uform_image_encode.

Parameters

imagesreadonly Uint8Array[] | Tape<Uint8Array>One encoded file per item, or a tape of them.
arenaArenaThe memory the outputs land in, rewound by the call.
configEncodeConfigThe surfaces, their scalar, and a progress handler.
imageEncode*× 2Encodes decoded images, resized on the executor's side.
model.ts:454 ↗

Inherited from EncodeVerbs

imageEncodePixels(
    images: readonly Pixels[],
    arena: Arena,
    config: EncodeConfig = {},
): Answer<Receiving, Encoded>

Calls uform_image_encode_pixels.

Parameters

imagesreadonly Pixels[]ImageData, or RGB or RGBA bytes with their width and height.
arenaArenaThe memory the outputs land in, rewound by the call.
configEncodeConfigThe surfaces, their scalar, and a progress handler.
video*× 2Decodes and encodes MP4 or WebM clips; the browser build reports unsupported.
model.ts:481 ↗

Inherited from EncodeVerbs

videoEncode(
    videos: readonly Uint8Array[] | Tape<Uint8Array>,
    arena: Arena,
    config: EncodeConfig = {},
): Answer<Receiving, Encoded>

Calls uform_video_encode.

Parameters

videosreadonly Uint8Array[] | Tape<Uint8Array>One encoded file per item, or a tape of them.
arenaArenaThe memory the outputs land in, rewound by the call.
configEncodeConfigThe surfaces, their scalar, and a progress handler.
audio*× 2Decodes and encodes WAV, FLAC, MP3 or Opus files; the browser build reports unsupported.
model.ts:503 ↗

Inherited from EncodeVerbs

audioEncode(
    recordings: readonly Uint8Array[] | Tape<Uint8Array>,
    arena: Arena,
    config: EncodeConfig = {},
): Answer<Receiving, Encoded>

Calls uform_audio_encode.

Parameters

recordingsreadonly Uint8Array[] | Tape<Uint8Array>One encoded file per item, or a tape of them.
arenaArenaThe memory the outputs land in, rewound by the call.
configEncodeConfigThe surfaces, their scalar, and a progress handler.
audioEncode*× 2Encodes decoded mono recordings, resampled to the model's rate where sampleRate differs.
model.ts:526 ↗

Inherited from EncodeVerbs

audioEncodeSamples(
    recordings: readonly Float32Array[] | Tape<Float32Array>,
    sampleRate: number,
    arena: Arena,
    config: EncodeConfig = {},
): Answer<Receiving, Encoded>

Calls uform_audio_encode_samples.

Parameters

recordingsreadonly Float32Array[] | Tape<Float32Array>One run of samples per item, or a tape of them.
sampleRatenumberSamples per second shared by every recording.
arenaArenaThe memory the outputs land in, rewound by the call.
configEncodeConfigThe surfaces, their scalar, and a progress handler.
executorThe executor the verbs run on; absent runs them on the calling thread.
model.ts:326 ↗

Inherited from EncodeVerbs

readonly executor: Executor | undefined
ClassModelDeferredOnThe verbs of one model, submitted to one executor and answered as Deferred calls: model.deferred(executor).2
model.ts:93 ↗
class ModelDeferredOn extends ModelVerbs<"deferred">

A verb borrows its arena until final, and waits into the same views a blocking call answers.

ModelDeferredOnMade by model.deferred(executor), never directly.
model.ts:95 ↗
new ModelDeferredOn(compiled: CompiledModel, executor: Executor)
executorThe executor the verbs run on; absent runs them on the calling thread.
model.ts:326 ↗

Inherited from EncodeVerbs

readonly executor: Executor | undefined
ClassTrainerDeferredOnThe trainer's verbs, submitted to its executor and answered as Deferred (*) calls: trainer.deferred().3
train.ts:326 ↗
class TrainerDeferredOn extends TrainerVerbs<"deferred">
TrainerDeferredOnMade by trainer.deferred(), never directly.
train.ts:328 ↗
new TrainerDeferredOn(
    compiled: CompiledTrainer,
    executor: Executor,
)
stepApplies one optimizer step over this process's items and every peer's.
train.ts:266 ↗

Inherited from TrainerVerbs

step(
    batch: TrainerBatch,
    config: TrainerStepConfig = {},
): Answer<Receiving, Stepped>

Calls uform_trainer_step.

Parameters

batchTrainerBatchThis process's items, their modalities, bags and relations.
configTrainerStepConfigWhere the scored embeddings land.
saveWrites the weights and the step as a safetensors checkpoint; only process zero writes.
train.ts:315 ↗

Inherited from TrainerVerbs

save(path: string): Answer<Receiving, void>

Calls uform_trainer_save.

Parameters

pathstringThe destination, written whole and renamed into place.
ClassDeferredA call submitted by a deferred receiver, final once its executor finishes it.4
types.ts:425 ↗
class Deferred<T> implements PromiseLike<T>, Disposable

It keeps everything the library reads or writes alive until then - the outcome, the inputs, the outputs and every handle it names - so none of them is collected under the call. status polls without blocking, wait blocks and answers, and await runs that wait on the libuv pool; both answer the same cached result, or throw the same failure, however often they are asked. On the WebAssembly backend the call is final once submitted.

const encoded = await call; // or: call.wait()
DeferredMade by a verb of a deferred receiver, never directly.
types.ts:432 ↗
new Deferred(call: CompiledDeferred, answer: (raw: never) => T)
waitBlocks the calling thread until the call is final, then answers its result or throws its failure.
types.ts:446 ↗
wait(): T

Calls uform_outcome_wait.

thenWaits off the calling thread, which is what await reaches for.
types.ts:456 ↗
then<Fulfilled = T, Rejected = never>(
    onFulfilled?: ((value: T) => Fulfilled | PromiseLike<Fulfilled>) | null,
    onRejected?: ((reason: unknown) => Rejected | PromiseLike<Rejected>) | null,
): Promise<Fulfilled | Rejected>

Calls uform_outcome_wait on the libuv pool.

statusStatus.Deferred until the call is final, then Status.Success or its failure.
types.ts:440 ↗
readonly status: Status

Calls uform_outcome_status.