use uform::Blocking;use uform::Deferred;use uform::Deferring;use uform::Mood;use uform::On;use uform::Wait;use uform::*;4.0.0-rc.1 · 3ee5e534
The receiver decides where a verb runs and how it completes, while the verb and its arguments stay the same:
model.text_encode(..) runs on the calling thread, through &Model.
model.on(&executor).text_encode(..) blocks on the executor, failing Contended while another call holds it.
model.deferred(&executor).text_encode(..) submits the call and answers a Deferred.
ModelVerbs and EncodeVerbs write every verb once for all three, and TrainVerbs does so for a trainer’s two receivers.
A blocking verb returns its Result directly, so nothing about asynchrony reaches a caller who never asks for it.
An On borrows the model and the executor, so neither it nor a Deferred it submits can outlive them.
let texts = vec![String::from("a cat on a mat"), String::from("a dog in the fog")];let call = model.deferred(&executor).text_encode(texts, Outputs::EMBEDDINGS, Scalar::F32, &mut arena)?;if call.status() == Err(Status::Deferred) { // other work}let encoded = call.await?; // or: call.wait()?
A Deferred owns the inputs the library reads until the call is final, and borrows the model and the arena, as a blocking call does. status answers Ok(()) once the call succeeded, Err(Status::Deferred) while it is not final, and its failure otherwise.
Inside an async block, .await polls the call’s status until it is final, so other tasks run meanwhile, while wait blocks the thread without spinning.
The crate starts no thread, so waiting off-thread goes through a scoped thread, as std::thread::scope(|scope| scope.spawn(move || call.wait()).join()) does.
Dropping an unfinished Deferred waits for the call, and a panic a progress handler raised resurfaces from wait, .await, or a drop outside unwinding.
The library reads a deferred call’s inputs after the verb returns, so a deferred receiver takes owned inputs: items in a Vec or an array of owned or 'static values, a tape as (Vec<_>, Vec<usize>), a PathBuf, String or 'static path, and 'static configs and handlers.
Lending &Vec<String> fails to compile with “a deferred receiver needs owned inputs”, and a config borrowing a local fails as “does not live long enough”.
A deferred call allocates one box holding its outcome, argument struct and inputs until it is final.
An executor without threads of its own may hold a deferred call until its wait, its next drain or blocking call, or the drop of what it names, so drain it before an .await there.
A call finding another one holding its executor finishes at once with Status::Contended.
API
Types
ProgressCallbackA periodic report of finished and total units; Break stops the call at the next slice.
It runs on whichever thread advanced the work, never on two at once, so it owes Send and
may be FnMut. A panic inside it stops the call like a Break and is re-raised once the
call is final.
Mirrors uform_progress_callback_t.
StructBlockingThe completion of a blocking receiver, whose verbs return once their call is final and answer what it produced.
StructDeferredA submitted call, which owns its outcome, argument struct and inputs in one box the library reads until the call is final, and borrows its arena as a blocking call does.2
Deferred::status polls without blocking, and Deferred::wait blocks until the call is
final and hands back what it produced, while .await polls it from async code. Dropping an
unfinished one waits for it, then frees the box.
A panic a handler raised resurfaces from wait, .await, or a drop outside unwinding.
'handle is the borrow of the On that submitted it.
Rust-only; waiting and dropping call uform_outcome_wait.
Implements
Drop, Debug, Send, IntoFuture
statusErr(Status::Deferred) until the call is final, then its final status, read without blocking.
text_chooseScores each item's legal choices through one forward: texts are UTF-8 states, each ending where its choice goes, and choices holds each item's legal bytes, one choice per byte.
image_encode_pixelsEncodes decoded images of interleaved 8-bit RGB, item i holding heights[i] rows of widths[i] pixels; an item of another length fails with Status::ShapeMismatch.
Every process of the run calls it
once per step, with one modality per item and each item's bytes in contents.
Answers the pooled embeddings when the config names an arena.
Calls uform_trainer_step.
saveWrites the weights and the step, which the model loads serve and Trainer::init_vram resumes; only the process of index zero writes, the rest return at once.
The C library has no wake-up, so an executor re-polls it while other tasks run, spinning only
when nothing else is ready; Deferred::wait blocks without spinning.
Rust-only; the final poll calls uform_outcome_wait, which returns at once.