C · Models

Models

#include <uform/types.h>#include <uform/model.h> 4.0.0-rc.1 · 3ee5e534

Residency is in the verb name, as in USearch and UStore, so a residency a build lacks has no verb to call:

  • RAM: uform_model_load_ram and uform_model_load_ram_buffer place the weights in host memory, on the NUMA nodes uform_ram_options_t names, and every build carries them.
  • NVIDIA: uform_model_load_vram and uform_model_load_vram_buffer place them on the CUDA devices uform_vram_options_t names, in builds with UFORM_CUDA_ARCH.
  • AMD: the same VRAM verbs place them on ROCm devices, in builds with UFORM_ROCM_ARCH.

On NVIDIA, text and JPEG images never leave the device; container demux, PNG and WebP, audio, and every modality on AMD decode on host threads the executor spawns beside its streams. uform_capabilities_compiled and uform_capabilities_available report what the binary was built with and what the machine offers.

uform_model_describe reports the model’s dimensions, context, quantization, memory usage and the CPU or GPU class it dispatched to. It also reports the cpu_class a RAM model was packed for or the gpu_class a VRAM model runs as, the token_width of its token head, and the choice_temperature_groups of its byte decoder, each zero when the checkpoint carries no such part.

API

Types

uform_residency_tWhere an arena's outputs live, as the executor that made it decided.
types.h:847 ↗
enum uform_residency_t

Values

uform_residency_unknown_k0No residency named.
uform_residency_ram_k1Host pages, which the host reads directly.
uform_residency_vram_k2One GPU's memory, which only device code reads.
uform_model_tA loaded encoder: its weights, their packed copies, and on a GPU the session its attention runs on.
model.h:57 ↗
typedef struct uform_model_handle_t * uform_model_t;

Shared by every executor of its residency; calls through different executors take turns on its session.

uform_model_description_tWhat a loaded model reports about itself.
model.h:190 ↗
struct uform_model_description_t

Fields

dimensionssize_tScalars per embedding row; Matryoshka prefixes of it are embeddings too.
contextsize_tTokens one item may span before it is truncated: bytes of text, patches of an image, tubes of a clip, frames of a recording.
quantizationuform_scalar_tThe scalar the transformer blocks run in.
memory_usagesize_tBytes the model holds; activations are the executor's.
cpu_classuform_cpu_class_tThe class a RAM model's tower was packed for; uform_cpu_class_unknown_k for a VRAM model.
gpu_classuform_gpu_class_tThe class every replica of a VRAM model runs as; uform_gpu_class_unknown_k for a RAM model, and for one on its vendor's generic kernels, whose devices have no class of their own.
token_widthsize_tScalars per token vector; zero when the checkpoint carries no token head.
choice_temperature_groupssize_tQuestion types the choice temperatures were calibrated over: zero without the byte decoder, one when uncalibrated.

Functions

uform_model_load_ramCopies a checkpoint file into host memory and packs its products for the CPU.
model.h:91 ↗
void uform_model_load_ram(uform_model_load_ram_t *arguments);

The checkpoint carries the model's geometry.

Parameters

modeluform_model_t *Output for the new model, written once the call completes.
executoruform_executor_tThe executor the load runs on.
outcomeuform_outcome_t *Output for the outcome, final once its status leaves uform_status_deferred_k.
completionuform_completion_tWhether the call blocks or returns once queued; zero blocks.
pathuform_bytes_view_tPath to a safetensors checkpoint, read in full and closed before the load completes.
ramuform_ram_options_tThe memory domains to place the weights in.
quantizationuform_scalar_tThe scalar the transformer blocks run in: uform_scalar_bf16_k as the checkpoint stores it, or uform_scalar_e4m3_k quantized at load, with BFloat16 entries, attention pool and head.
progressuform_progress_tThe optional handler, called with tensors placed.
uform_model_load_ram_bufferCopies a checkpoint held in memory into host memory and packs its products for the CPU.
model.h:123 ↗
void uform_model_load_ram_buffer(
    uform_model_load_ram_buffer_t *arguments);

Parameters

modeluform_model_t *Output for the new model, written once the call completes.
executoruform_executor_tThe executor the load runs on.
outcomeuform_outcome_t *Output for the outcome, final once its status leaves uform_status_deferred_k.
completionuform_completion_tWhether the call blocks or returns once queued; zero blocks.
bufferuform_bytes_view_tThe safetensors checkpoint itself, copied before the load completes; nothing of it is kept.
ramuform_ram_options_tThe memory domains to place the weights in.
quantizationuform_scalar_tThe scalar the transformer blocks run in, as for uform_model_load_ram.
progressuform_progress_tThe optional handler, called with tensors placed.
uform_model_load_vramCopies a checkpoint file onto the named GPUs and packs its products there.
model.h:155 ↗
void uform_model_load_vram(uform_model_load_vram_t *arguments);

Parameters

modeluform_model_t *Output for the new model, written once the call completes.
executoruform_executor_tThe executor the upload runs on, one stream per device.
outcomeuform_outcome_t *Output for the outcome, final once its status leaves uform_status_deferred_k.
completionuform_completion_tWhether the call blocks or returns once queued; zero blocks.
pathuform_bytes_view_tPath to a safetensors checkpoint, read in full and closed before the load completes.
vramuform_vram_options_tThe devices to place the weights on, replicated on each, since a model is small next to the activations it serves.
quantizationuform_scalar_tThe scalar the transformer blocks run in, as for uform_model_load_ram.
progressuform_progress_tThe optional handler, called with tensors placed.
uform_model_load_vram_bufferCopies a checkpoint held in memory onto the named GPUs and packs its products there.
model.h:187 ↗
void uform_model_load_vram_buffer(
    uform_model_load_vram_buffer_t *arguments);

Parameters

modeluform_model_t *Output for the new model, written once the call completes.
executoruform_executor_tThe executor the upload runs on, one stream per device.
outcomeuform_outcome_t *Output for the outcome, final once its status leaves uform_status_deferred_k.
completionuform_completion_tWhether the call blocks or returns once queued; zero blocks.
bufferuform_bytes_view_tThe safetensors checkpoint itself, in host or device memory, copied before the load completes.
vramuform_vram_options_tThe devices to place the weights on, replicated on each.
quantizationuform_scalar_tThe scalar the transformer blocks run in, as for uform_model_load_ram.
progressuform_progress_tThe optional handler, called with tensors placed.
uform_model_describeReports a model's geometry and placement in one call.
model.h:242 ↗
void uform_model_describe(uform_model_describe_t *arguments);

Parameters

modeluform_model_tThe model to be described.
executoruform_executor_tThe executor the report runs on.
outcomeuform_outcome_t *Output for the outcome, final once its status leaves uform_status_deferred_k.
completionuform_completion_tWhether the call blocks or returns once queued; zero blocks.
descriptionuform_model_description_t *Output, filled whole.
uform_model_freeFrees a model; NULL is safe, and it cannot fail, so takes no outcome.
model.h:246 ↗
void uform_model_free(uform_model_t model);

Every call using it must be final.