class Scalar(IntEnum) Values
F64 | 1 | |
|---|---|---|
F32 | 2 | |
BF16 | 3 | |
F16 | 4 | |
E5M2 | 5 | |
E4M3 | 6 | |
E3M2 | 7 | |
E2M3 | 8 | |
I8 | 10 | |
I4X2 | 11 | |
I32 | 12 | |
U8 | 20 | |
U4X2 | 21 | |
U1X8 | 22 |
One verb per input form, each spelled as in C:
text_encode(texts, arena) takes UTF-8 texts, a byte per token, since models are tokenizer-free.image_encode(files, arena) takes JPEG, PNG or WebP files.image_encode_pixels(pixels, arena) takes C-contiguous [height, width, 3] uint8 buffers.video_encode(files, arena) takes MP4 or WebM clips.audio_encode(files, arena) takes WAV, FLAC, MP3 or Opus recordings.audio_encode_samples(samples, sample_rate, arena) takes 1-D float32 buffers.A batch is a sequence of separate objects, str or bytes-like for texts and bytes-like for files, gathered into one tape with one copy.
A (data, offsets) tuple of buffers, the data and count + 1 size_t offsets, is lent to the library as a tape without a copy:
data = b"first documentthe second"
offsets = np.array([0, 14, 24], dtype=np.uint64)
encoded = model.text_encode((data, offsets), arena)outputs names the surfaces a call keeps, and decides which C output pointers the binding passes:
encoded = model.text_encode(texts, arena, outputs=uform.Outputs.EMBEDDINGS | uform.Outputs.STATES)
embeddings, states, token_vectors = encoded # an `ArenaBuffer` of (count, dimensions), a `RowsTape`, and None
offsets = np.asarray(states.offsets) # item `i` spans rows `offsets[i]` up to `offsets[i + 1]`Outputs.EMBEDDINGS is the default, and a surface left out answers None and costs nothing past the final norm. Outputs.TOKEN_VECTORS keeps the token head’s unit vectors, a RowsTape of (tokens, token_width) on the states’ offsets, for late-interaction reranking; a model whose describe().token_width is zero raises UnsupportedError. outputs_scalar picks the scalar every output lands as, Scalar.F32 by default; Scalar.BF16 outputs export as raw bytes, a (count, row_bytes) run of 'B'. stats=uform.TextEncodeStats() and its siblings are overwritten with the truncated items and the encoded tokens. progress=handler is called with (completed, total) items, and a handler returning False stops the call, which raises uform.CancelledError; one that raises stops it too, and its own exception reaches the caller.
ScalarA scalar type a model computes in or its outputs land as, valued as uform_scalar_t.class Scalar(IntEnum) F64 | 1 | |
|---|---|---|
F32 | 2 | |
BF16 | 3 | |
F16 | 4 | |
E5M2 | 5 | |
E4M3 | 6 | |
E3M2 | 7 | |
E2M3 | 8 | |
I8 | 10 | |
I4X2 | 11 | |
I32 | 12 | |
U8 | 20 | |
U4X2 | 21 | |
U1X8 | 22 |
OutputsWhich surfaces an encoding keeps, deciding which of the C output pointers the binding passes.RowsTapeA ragged run of rows in an Arena, one per token each item kept or one value per choice, split by offsets.1class RowsTape(ArenaBuffer) offsets(count + 1,) Apache Arrow offsets into the rows.offsets: ArenaBuffer EncodedWhat an encoding wrote into its arena, unpacking as embeddings, states, token_vectors = encoded.3class Encoded(structseq[Any], tuple[ArenaBuffer | None, RowsTape | None, RowsTape | None]) embeddingsThe (count, dimensions) pooled embeddings, or None when not asked for.embeddings: ArenaBuffer | None statesThe (tokens, dimensions) final-norm states and their offsets, or None when not asked for.states: RowsTape | None token_vectorsThe (tokens, token_width) unit vectors of the token head, offset as the states, or None.token_vectors: RowsTape | None TextEncodeStatsWhat text_encode and text_choose report, overwritten by every call it is passed to.2class TextEncodeStats truncatedItems cut at the model's context.tokensTokens the call encoded, after truncation.ImageEncodeStatsWhat image_encode and image_encode_pixels report, overwritten by every call it is passed to.2class ImageEncodeStats truncatedItems cut at the model's context.tokensTokens the call encoded, after truncation.VideoEncodeStatsWhat video_encode reports, overwritten by every call it is passed to.2class VideoEncodeStats truncatedItems cut at the model's context.tokensTokens the call encoded, after truncation.AudioEncodeStatsWhat audio_encode and audio_encode_samples report, overwritten by every call it is passed to.2class AudioEncodeStats truncatedItems cut at the model's context.tokensTokens the call encoded, after truncation.