Lfm3VisionEncoder class final
Correctness-first, synchronous inference. Weights are widened to f32 on the Dart heap, except matrices given as native Q4/Q8 blocks, whose products run in the native kernels with float inputs, or on the GPU after useGpu; the rest stays on the CPU. This is a lab API, not the optimized on-device path. Images are encoded independently; no cross-image attention or video state. close frees native matrices.
Constructors
-
Lfm3VisionEncoder.fromWeights(Lfm3VlConfig config, Map<
String, Float32List> weights, {Map<String, NativeMatrix> native = const {}}) -
Uses already widened weights, keyed by the checkpoint names of
lfm3VisionTensorShapes. Every tensor must be in exactly one of
weightsandnative;nativeholds only 2D linear weights, and the encoder takes ownership of them.factory - Lfm3VisionEncoder.load(String modelDir, {bool quantize = false})
-
Reads the vision/projector tensors of the checkpoint in
modelDir. Withquantize, every linear weight but the patchifier's whose width is a multiple of 32 is quantized to Q8 in native memory as it is read (the native kernels must be loaded), so its products run in the native kernels or, after useGpu, on the GPU, at a quarter of float32's memory. Quantizing changes the outputs; without it every weight stays float32 on the Dart heap.factory
Properties
- config → Lfm3VlConfig
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- onGpu → bool
-
Whether the native matrices' products run on the GPU (useGpu).
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
close(
) → void - Frees native matrices and their GPU copies. The encoder cannot be used afterwards.
-
encode(
VisionImageInput image, {void capture(String stage, Float32List rows)?}) → Float32List -
Returns
image.imageTokens, config.text.hiddenSizeprojected rows, ready for Lfm3Model.forward's embeddingOverrides.capturegets owned snapshots after embedding norm, each layer and projection. -
encodeAsync(
VisionImageInput image, {void capture(String stage, Float32List rows)?, void checkCancelled()?, void onProgress(int completed, int total)?}) → Future< Float32List> -
Same arithmetic as encode, yielding to the event loop between stages.
checkCancelledmay throw to abort before the next stage is computed. A stage itself is synchronous CPU work; run inference in a worker isolate when integrating with a UI. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
useGpu(
) → bool - Moves the products of the native (Q4 or Q8) matrices to the GPU, copying them into GPU memory; the CPU copies stay as they are. Returns whether it did: false without native matrices or where the GPU does not start. The rest of the encoder stays on the CPU. Outputs then differ from the CPU kernels' in the last bits. Encode only while no other isolate runs a GPU forward pass (see GpuLinear).
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited