JavaScript · Models

Models

import * as uform from 'uform';import { Model } from 'uform'; 4.0.0-rc.1 · 3ee5e534

Dispatch picks a CPU or GPU class on its own, and cpuClass or gpuClass pins one by its name:

for (const { name, gpuClass, memoryBytes } of gpuDevices()) console.log(name, gpuClass, memoryBytes);
const portable = Model.loadRam("model.safetensors", { cpuClass: "intel-haswell" });
console.log(portable.describe().cpuClass); // "intel-haswell"

API

Types

ModelLoadRamConfigWhere a checkpoint loaded into host memory lands.
uform.ts:13 ↗
interface ModelLoadRamConfig

Mirrors uform_model_load_ram_t.

Fields

executor?ExecutorThe executor the load runs on; absent loads on the calling thread.
memoryDomains?number[]NUMA node IDs to place the weights in; absent derives every node.
cpuClass?stringThe CPU class to pack the tower for, spelled like "intel-haswell"; absent derives the CPU's own.
quantization?ScalarThe scalar the transformer blocks run in: bf16 as the checkpoint stores it, the default, or e4m3.
ModelLoadVramConfigWhere a checkpoint loaded into device memory lands.
uform.ts:27 ↗
interface ModelLoadVramConfig

Mirrors uform_model_load_vram_t.

Fields

executor?ExecutorThe executor the upload runs on, one stream per device; absent uploads on the calling thread.
devices?number[]Device ordinals, positions in gpuDevices(), to replicate the weights on; absent takes one free device.
gpuClass?stringThe GPU class every replica runs as, spelled like "nvidia-hopper"; absent derives the devices' own.
quantization?ScalarThe scalar the transformer blocks run in: bf16 as the checkpoint stores it, the default, or e4m3.
ModelDescriptionWhat a loaded model reports about itself.
uform.ts:43 ↗
interface ModelDescription

Mirrors uform_model_description_t.

Fields

dimensionsnumberScalars per embedding row; Matryoshka prefixes of it are embeddings too.
contextnumberTokens one item may span before it is truncated.
quantizationScalarThe scalar the transformer blocks run in.
memoryUsagenumberBytes the model holds; activations are the executor's.
cpuClassstring | nullThe CPU class a RAM model's tower was packed for, like "intel-haswell"; null for a VRAM model.
gpuClassstring | nullThe GPU class every replica of a VRAM model runs as, like "nvidia-hopper"; null for a RAM model.
tokenWidthnumberScalars per token vector; zero when the checkpoint carries no token head.
choiceTemperatureGroupsnumberQuestion types the choice temperatures were calibrated over: zero without the byte decoder, one uncalibrated.
ClassModelA loaded encoder, running every verb on the calling thread.16
model.ts:115 ↗
class Model extends ModelOn implements Disposable

on(executor) and deferred(executor) reach the same verbs on an executor. One model serves every modality it was trained on.

loadRamCopies a safetensors checkpoint file into host memory and packs it for the CPU.
model.ts:157 ↗
static loadRam(
    path: string,
    config: ModelLoadRamConfig = {},
): Model

Calls uform_model_load_ram.

Parameters

pathstringThe checkpoint, read in full and closed before the load completes.
configModelLoadRamConfigThe executor, the NUMA nodes, and the block scalar.
loadRamBufferCopies a checkpoint held in memory into host memory, which is how a page loads one it fetched.
model.ts:176 ↗
static loadRamBuffer(
    buffer: ArrayBuffer | ArrayBufferView,
    config: ModelLoadRamConfig = {},
): Model

Calls uform_model_load_ram_buffer.

Parameters

bufferArrayBuffer | ArrayBufferViewThe checkpoint bytes, copied before the load completes.
configModelLoadRamConfigThe executor, the NUMA nodes, and the block scalar.
loadVramCopies a checkpoint file onto the named GPUs and packs it there.
model.ts:195 ↗
static loadVram(
    path: string,
    config: ModelLoadVramConfig = {},
): Model

Calls uform_model_load_vram.

Parameters

pathstringThe checkpoint, read in full and closed before the load completes.
configModelLoadVramConfigThe executor, the devices, and the block scalar.
loadVramBufferCopies a checkpoint held in memory onto the named GPUs.
model.ts:213 ↗
static loadVramBuffer(
    buffer: ArrayBuffer | ArrayBufferView,
    config: ModelLoadVramConfig = {},
): Model

Calls uform_model_load_vram_buffer.

Parameters

bufferArrayBuffer | ArrayBufferViewThe checkpoint bytes, copied before the load completes.
configModelLoadVramConfigThe executor, the devices, and the block scalar.
onThe same verbs, each blocking on executor, after every earlier submission to it.
model.ts:128 ↗
on(executor: Executor): ModelOn

Binding-only.

Parameters

executorExecutorThe threads or streams to run on; its residency must match the model's.
deferredThe same verbs, each submitted to executor and answered as a Deferred.
model.ts:136 ↗
deferred(executor: Executor): ModelDeferredOn

Binding-only.

Parameters

executorExecutorThe threads or streams to run on; its residency must match the model's.
freeReleases the weights now, waiting for every deferred call naming the model; a second free does nothing.
model.ts:143 ↗
free(): void

Calls uform_model_free.

describeReports the model's geometry and placement in one call.
model.ts:68 ↗

Inherited from ModelVerbs

describe(): Answer<Receiving, ModelDescription>

Calls uform_model_describe.

textEncodeEncodes texts through one forward; every UTF-8 byte is a token.
model.ts:368 ↗

Inherited from EncodeVerbs

textEncode(
    texts: readonly (string | Uint8Array)[] | Tape<Uint8Array>,
    arena: Arena,
    config: EncodeConfig = {},
): Answer<Receiving, Encoded>

Calls uform_text_encode.

Parameters

textsreadonly (string | Uint8Array)[] | Tape<Uint8Array>Strings, UTF-8 bytes already encoded, or a tape of them.
arenaArenaThe memory the outputs land in, rewound by the call.
configEncodeConfigThe surfaces, their scalar, and a progress handler.

Returns

The outputs, viewed inside arena.
textChooseScores each item's legal choices through one forward, a softmax over them alone at the item's group's calibrated inverse temperature; a model without the byte decoder reports unsupported.
model.ts:393 ↗

Inherited from EncodeVerbs

textChoose(
    texts: readonly (string | Uint8Array)[] | Tape<Uint8Array>,
    choices: readonly (string | Uint8Array)[] | Tape<Uint8Array>,
    arena: Arena,
    config: ChooseConfig = {},
): Answer<Receiving, Chosen>

Calls uform_text_choose.

Parameters

textsreadonly (string | Uint8Array)[] | Tape<Uint8Array>The states, each ending where its choice goes.
choicesreadonly (string | Uint8Array)[] | Tape<Uint8Array>Each item's legal choices, one byte each, like "yn".
arenaArenaThe memory the probabilities land in, rewound by the call.
configChooseConfigThe question types and a progress handler.

Returns

The probabilities, viewed inside arena.
imageEncodeDecodes and encodes JPEG, PNG or WebP files; the browser build reports unsupported.
model.ts:433 ↗

Inherited from EncodeVerbs

imageEncode(
    images: readonly Uint8Array[] | Tape<Uint8Array>,
    arena: Arena,
    config: EncodeConfig = {},
): Answer<Receiving, Encoded>

Calls uform_image_encode.

Parameters

imagesreadonly Uint8Array[] | Tape<Uint8Array>One encoded file per item, or a tape of them.
arenaArenaThe memory the outputs land in, rewound by the call.
configEncodeConfigThe surfaces, their scalar, and a progress handler.
imageEncodePixelsEncodes decoded images, resized on the executor's side.
model.ts:454 ↗

Inherited from EncodeVerbs

imageEncodePixels(
    images: readonly Pixels[],
    arena: Arena,
    config: EncodeConfig = {},
): Answer<Receiving, Encoded>

Calls uform_image_encode_pixels.

Parameters

imagesreadonly Pixels[]ImageData, or RGB or RGBA bytes with their width and height.
arenaArenaThe memory the outputs land in, rewound by the call.
configEncodeConfigThe surfaces, their scalar, and a progress handler.
videoEncodeDecodes and encodes MP4 or WebM clips; the browser build reports unsupported.
model.ts:481 ↗

Inherited from EncodeVerbs

videoEncode(
    videos: readonly Uint8Array[] | Tape<Uint8Array>,
    arena: Arena,
    config: EncodeConfig = {},
): Answer<Receiving, Encoded>

Calls uform_video_encode.

Parameters

videosreadonly Uint8Array[] | Tape<Uint8Array>One encoded file per item, or a tape of them.
arenaArenaThe memory the outputs land in, rewound by the call.
configEncodeConfigThe surfaces, their scalar, and a progress handler.
audioEncodeDecodes and encodes WAV, FLAC, MP3 or Opus files; the browser build reports unsupported.
model.ts:503 ↗

Inherited from EncodeVerbs

audioEncode(
    recordings: readonly Uint8Array[] | Tape<Uint8Array>,
    arena: Arena,
    config: EncodeConfig = {},
): Answer<Receiving, Encoded>

Calls uform_audio_encode.

Parameters

recordingsreadonly Uint8Array[] | Tape<Uint8Array>One encoded file per item, or a tape of them.
arenaArenaThe memory the outputs land in, rewound by the call.
configEncodeConfigThe surfaces, their scalar, and a progress handler.
audioEncodeSamplesEncodes decoded mono recordings, resampled to the model's rate where sampleRate differs.
model.ts:526 ↗

Inherited from EncodeVerbs

audioEncodeSamples(
    recordings: readonly Float32Array[] | Tape<Float32Array>,
    sampleRate: number,
    arena: Arena,
    config: EncodeConfig = {},
): Answer<Receiving, Encoded>

Calls uform_audio_encode_samples.

Parameters

recordingsreadonly Float32Array[] | Tape<Float32Array>One run of samples per item, or a tape of them.
sampleRatenumberSamples per second shared by every recording.
arenaArenaThe memory the outputs land in, rewound by the call.
configEncodeConfigThe surfaces, their scalar, and a progress handler.
executorThe executor the verbs run on; absent runs them on the calling thread.
model.ts:326 ↗

Inherited from EncodeVerbs

readonly executor: Executor | undefined