Go · Models

Models

import "github.com/unum-cloud/uform" 4.0.0-rc.1 · c58749fe

Ask your coding agent about this page, or add the docs server to it

curl -s 'https://www.unum.cloud/docs/uform/go/models.md' | claude -p "How would this fit my code?"

ModelLoadRam(path, config) and ModelLoadVram(path, config) copy a safetensors checkpoint into host memory or onto GPUs, and ModelLoadRamBuffer and ModelLoadVramBuffer take the checkpoint’s bytes instead. A nil config loads on the calling goroutine with BFloat16 blocks, and the config reaches the executor, the placement and its class ceiling, ScalarE4M3 quantization and a progress handler:

model, err := uform.ModelLoadVram("model.safetensors", &uform.ModelLoadVramConfig{
	Executor:     executor,
	Devices:      []int32{0},
	Quantization: uform.ScalarE4M3,
})
description, err := model.Describe() // geometry, placement, classes and heads

A description reports the CPUClass or GPUClass the model dispatched as, and the heads the checkpoint carries: a nonzero TokenWidth for token vectors, and a nonzero ChoiceTemperatureGroups for choices. Loads always block, and Close waits for every deferred call naming the model.

API

Types

ModelDescriptionModelDescription is what a loaded model reports about itself.
types.go:29 ↗
type ModelDescription struct {
    Dimensions uint
    Context uint
    Quantization Scalar
    MemoryUsage uint
    CPUClass CPUClass
    GPUClass GPUClass
    TokenWidth uint
    ChoiceTemperatureGroups uint
}

Mirrors uform_model_description_t field for field, so the library writes it in place.

Fields

DimensionsuintDimensions is the scalars per embedding row; Matryoshka prefixes of it are embeddings too.
ContextuintContext is the tokens one item may span before it is truncated: bytes of text, patches of an image, tubes of a clip, frames of a recording.
QuantizationScalarQuantization is the scalar the transformer blocks run in.
MemoryUsageuintMemoryUsage is the bytes the model holds; activations are the executor's.
CPUClassCPUClassCPUClass is the class a RAM model's tower was packed for, CPUClassUnknown for a VRAM model.
GPUClassGPUClassGPUClass is the class every replica of a VRAM model runs as, GPUClassUnknown for a RAM model.
TokenWidthuintTokenWidth is the scalars per token vector, zero when the checkpoint carries no token head.
ChoiceTemperatureGroupsuintChoiceTemperatureGroups counts the question types the choice temperatures were calibrated over: zero without the byte decoder, one when uncalibrated.
ModelLoadRamConfigModelLoadRamConfig is how ModelLoadRam and ModelLoadRamBuffer copy a checkpoint into host memory; nil derives every field.
types.go:54 ↗
type ModelLoadRamConfig struct {
    Executor *Executor
    MemoryDomains []int32
    CPUClassCeiling CPUClass
    Quantization Scalar
    Progress ProgressCallback
    ProgressSteps uint
}

Mirrors uform_model_load_ram_t and uform_model_load_ram_buffer_t beside their path or buffer.

Fields

Executor*ExecutorExecutor is the one the load runs on; nil loads on the calling goroutine.
MemoryDomains[]int32MemoryDomains are the NUMA nodes to place the weights in; empty derives every node.
CPUClassCeilingCPUClassCPUClassCeiling is the newest class to pack and dispatch as; zero sets no ceiling.
QuantizationScalarQuantization is the scalar the transformer blocks run in: ScalarBF16 as the checkpoint stores it, or ScalarE4M3 quantized at load; zero keeps ScalarBF16.
ProgressProgressCallbackProgress hears the tensors placed and may stop the load, which then creates no model.
ProgressStepsuintProgressSteps is the reports the load makes at most; zero derives ten.
ModelLoadVramConfigModelLoadVramConfig is how ModelLoadVram and ModelLoadVramBuffer copy a checkpoint onto GPUs; nil derives every field.
types.go:74 ↗
type ModelLoadVramConfig struct {
    Executor *Executor
    Devices []int32
    GPUClassCeiling GPUClass
    Quantization Scalar
    Progress ProgressCallback
    ProgressSteps uint
}

Mirrors uform_model_load_vram_t and uform_model_load_vram_buffer_t beside their path or buffer.

Fields

Executor*ExecutorExecutor is the one the upload runs on, one stream per device; nil uploads on the calling goroutine.
Devices[]int32Devices are the ordinals GPUDevices lists, each holding a replica; empty places one on every device of the executor.
GPUClassCeilingGPUClassGPUClassCeiling is the newest class every device dispatches as; zero sets no ceiling.
QuantizationScalarQuantization is the scalar the transformer blocks run in, as for ModelLoadRamConfig.
ProgressProgressCallbackProgress hears the tensors placed and may stop the load, which then creates no model.
ProgressStepsuintProgressSteps is the reports the load makes at most; zero derives ten.
ResidencyResidency is where an arena's outputs live, as the executor that made it decided.
types.go:564 ↗
type Residency int32

Values

ResidencyUnknownResidencyUnknown names no residency.
ResidencyRamResidencyRam is host pages, which Go code reads directly.
ResidencyVramResidencyVram is one GPU's memory, which Go code reads only where HostAccess lets it.
StructModelModel is a loaded encoder: its weights, their packed copies, and on a GPU the session its attention runs on, shared by every executor of its residency.15
model.go:111 ↗
type Model struct {
    ModelOn
    // contains filtered or unexported fields
}

Its embedded ModelOn runs every verb on the calling goroutine.

Mirrors uform_model_t; Close calls uform_model_free.

ModelLoadRamModelLoadRam copies a safetensors checkpoint file into host memory and packs it for the CPU.
model.go:130 ↗
func ModelLoadRam(
    path string,
    config *ModelLoadRamConfig,
) (*Model, error)

The checkpoint carries the model's geometry.

Calls uform_model_load_ram, blocking.

ModelLoadRamBufferModelLoadRamBuffer copies a checkpoint held in memory into host memory and packs it for the CPU; nothing of buffer is kept.
model.go:155 ↗
func ModelLoadRamBuffer(
    buffer []byte,
    config *ModelLoadRamConfig,
) (*Model, error)

Calls uform_model_load_ram_buffer, blocking.

ModelLoadVramModelLoadVram copies a checkpoint file onto the named GPUs and packs it there, replicated on each, since a model is small next to the activations it serves.
model.go:180 ↗
func ModelLoadVram(
    path string,
    config *ModelLoadVramConfig,
) (*Model, error)

Calls uform_model_load_vram, blocking.

ModelLoadVramBufferModelLoadVramBuffer copies a checkpoint held in memory onto the named GPUs and packs it there.
model.go:204 ↗
func ModelLoadVramBuffer(
    buffer []byte,
    config *ModelLoadVramConfig,
) (*Model, error)

Calls uform_model_load_vram_buffer, blocking.

CloseClose frees the model, waiting for every deferred call naming it.
model.go:227 ↗
func (model *Model) Close() error

It is idempotent, and a closed model refuses every later verb with StatusUninitialized.

AudioEncodeAudioEncode decodes and encodes WAV, FLAC, MP3 or Opus recordings, resampled to mono.
model.go:276 ↗

Inherited from ModelOn

func (on Model) AudioEncode(
    recordings Tape,
    outputs EncodeOutputs,
    outputsScalar Scalar,
    arena *Arena,
    config *AudioEncodeConfig,
) (Encoded, error)

Calls uform_audio_encode.

AudioEncodeSamplesAudioEncodeSamples encodes decoded mono ScalarF32 recordings sharing one sampleRate, resampled to the model's rate where it differs.
model.go:293 ↗

Inherited from ModelOn

func (on Model) AudioEncodeSamples(
    samples Tape,
    sampleRate uint32,
    outputs EncodeOutputs,
    outputsScalar Scalar,
    arena *Arena,
    config *AudioEncodeConfig,
) (Encoded, error)

Calls uform_audio_encode_samples.

DeferredDeferred is the receiver whose verbs submit their calls to executor, each answering a Deferred from the same arguments.
model.go:270 ↗

Inherited from ModelOn

func (on Model) Deferred(executor *Executor) ModelDeferredOn

Binding-only.

DescribeDescribe reports the model's geometry, placement, classes and heads in one call.
model.go:278 ↗

Inherited from ModelOn

func (on Model) Describe() (ModelDescription, error)

Calls uform_model_describe.

ImageEncodeImageEncode decodes and encodes JPEG, PNG or WebP files; an undecodable file fails the call with StatusMalformed.
model.go:227 ↗

Inherited from ModelOn

func (on Model) ImageEncode(
    images Tape,
    outputs EncodeOutputs,
    outputsScalar Scalar,
    arena *Arena,
    config *ImageEncodeConfig,
) (Encoded, error)

Calls uform_image_encode.

ImageEncodePixelsImageEncodePixels encodes decoded images of interleaved 8-bit RGB, item i holding heights[i] rows of widths[i] pixels; an item of another length fails with StatusShapeMismatch.
model.go:244 ↗

Inherited from ModelOn

func (on Model) ImageEncodePixels(
    pixels Tape,
    heights, widths []uint32,
    outputs EncodeOutputs,
    outputsScalar Scalar,
    arena *Arena,
    config *ImageEncodeConfig,
) (Encoded, error)

Calls uform_image_encode_pixels.

OnOn is the receiver whose verbs block on executor, failing StatusContended while another call holds it.
model.go:263 ↗

Inherited from ModelOn

func (on Model) On(executor *Executor) ModelOn

Binding-only.

TextChooseTextChoose scores each item's legal choices, one byte each, after its UTF-8 state in texts, through one forward, answering one ScalarF32 probability per choice in arena, a softmax over the item's choices alone.
model.go:212 ↗

Inherited from ModelOn

func (on Model) TextChoose(
    texts, choices Tape,
    arena *Arena,
    config *TextChooseConfig,
) (TapeView, error)

A model without the byte decoder fails it with StatusUnsupported.

Calls uform_text_choose.

TextEncodeTextEncode encodes UTF-8 texts through one forward, a token per byte, since models are tokenizer-free, keeping the surfaces outputs names as outputsScalar in arena.
model.go:194 ↗

Inherited from ModelOn

func (on Model) TextEncode(
    texts Tape,
    outputs EncodeOutputs,
    outputsScalar Scalar,
    arena *Arena,
    config *TextEncodeConfig,
) (Encoded, error)

Calls uform_text_encode.

VideoEncodeVideoEncode decodes and encodes MP4 or WebM clips.
model.go:260 ↗

Inherited from ModelOn

func (on Model) VideoEncode(
    videos Tape,
    outputs EncodeOutputs,
    outputsScalar Scalar,
    arena *Arena,
    config *VideoEncodeConfig,
) (Encoded, error)

Calls uform_video_encode.