Mojo · Quickstart

Quickstart

4.0.0-rc.1 · 3ee5e534

from uform import Arena, Executor, Library, Model, Outputs, ScalarKind, TapeView, EncodeConfig

def main() raises:
    var library = Library()
    var executor = Executor.for_ram(library, threads=8)
    var model = Model.load_ram(executor, "model.safetensors")  # BFloat16 blocks, as the checkpoint stores them

    var texts = "a cata dog".as_bytes()  # two texts end to end
    var offsets: List[UInt] = [0, 5, 10]  # one more offset than texts
    var arena = Arena(executor)
    var encoded = model.on(executor).text_encode(TapeView.of(texts, offsets), Outputs.EMBEDDINGS, arena)
    var embeddings = encoded.embeddings().value()
    print(len(embeddings), embeddings.columns(), embeddings.row[DType.float32](0)[0])

A model owns its weights; an Executor owns the threads or streams a call runs on; an Arena owns the outputs a call writes. Library() opens the engine once, and every handle created through it keeps it mapped.