GpuForward class final

Constructors

GpuForward.create({String? libPath, required String modelDir, required Lfm3Config config, required Q8Cache cache, required int maxSeq, required int maxChunk})
Starts the GPU of the kernels asset, or with libPath of the library there, and prepares cache's weights for it. The native CPU kernels must already be loaded: they map the cache.
factory

Properties

calls ↔ int
Totals since the last clearStats: forward calls and tokens.
getter/setter pair
config → Lfm3Config
final
dispatches ↔ int
Totals since the last clearStats: forward calls and tokens.
getter/setter pair
encodeMicros ↔ int
Totals since the last clearStats: forward calls and tokens.
getter/setter pair
gpuMicros ↔ int
Totals since the last clearStats: forward calls and tokens.
getter/setter pair
hashCode → int
The hash code for this object.
no setterinherited
lastHiddenState → Float32List
Final-normalized state of the last token computed with logits.
no setter
logits → Float32List
Logits of the last token of the last forward with logits, or of logitsOf.
no setter
maxChunk → int
Most tokens one forward call takes.
final
maxSeq → int
final
q8VectorHeadDefaultEligible ↔ bool
Whether this instance's Q4-cache LM head is registered for the validated Pixel 8 vector-load default. Overrides still take precedence.
latefinal
residual → Float32List
The residual stream entering the next forward, maxChunk rows of hidden size: write the tokens' embeddings here.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
steers → bool
Whether the GPU library applies control vectors (setControlVector).
final
tokens ↔ int
Totals since the last clearStats: forward calls and tokens.
getter/setter pair
weightSegments → int
How many GPU buffers the weights were split into.
no setter

Methods

benchmarkDecodeMatrices({int repetitions = 32, bool q8WorkgroupSweep = false, bool q8VectorSweep = false, void onSample(Map<String, Object?> sample)?}) → List<Map<String, Object?>>
Isolates representative real weight matrices from model orchestration. Each sample reuses fixed inputs for repetitions products in one command buffer (one input quantization). This is a cache-reuse probe, not an estimate of a complete token's memory traffic or latency. q8WorkgroupSweep instead isolates the LM head with four rows per subgroup and 64/128/256 invocations per workgroup, in six rounds. q8VectorSweep instead alternates scalar/vector loads at 128 invocations, four rows per subgroup, for six rounds.
captured(int slot, int n) → Float32List
After a forward of n tokens with capture: the residual entering layer 0 (slot 0) and leaving each layer (slot i + 1), n rows each.
clearStats() → void
dispose() → void
Releases every GPU buffer this forward pass made. The cache it wraps stays mapped: unmap it after this, never before. Using the forward pass afterwards throws.
forward(int n, int position, {required bool withLogits, required bool capture, void meanwhile()?}) → void
Runs n tokens at positions position, ... whose embeddings are already in residual: every layer, and with withLogits the final norm and LM head of the last token into logits. With capture, the residual stream is copied after every layer (see captured).
logitsOf(Float32List residualOut) → Float32List
The final norm and LM head of residualOut (a residual leaving the last layer) into logits.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reset() → void
Clears the conv histories for a new sequence. KV cache rows are written before they are read, so they need no reset.
restoreState(List<Float32List> state) → void
Puts back conv histories from saveState.
saveState() → List<Float32List>
A copy of the conv histories (see LayerShard.saveState).
setControlVector(ControlVector? vector) → void
Applies vector in every following forward, after each layer it steers and before that layer's capture, or stops with null. Uploads its vectors to a buffer of its own, released when replaced, cleared or disposed. Callers make sure no state computed under another vector is reused (Lfm3Model.setControlVector).
stateBlocks(int position) → List<Float32List>
Views of the state the first position tokens left behind, in the order of LayerShard.stateBlocks: conv histories, then each attention layer's key and value rows before position.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

decodeRows ← int
Rows per subgroup (SIMD group on Metal) of the decode kernels: 1, 2 or 4. Zero selects the reference: the old int8 GEMM on Vulkan, one row on Metal. On Metal every setting computes the same bits. The default is 4 on Vulkan and 2 on Metal (restoreDecodeRowsDefault).
no getter
deviceFacts → Map<String, Object>
Device facts for a measurement record, once a GpuForward exists.
no setter
deviceName → String
The GPU's name, once a GpuForward exists.
no setter
liveBuffers → int
GPU buffers in the process not yet released, for leak checks.
no setter
profiling ← bool
Times every dispatch on the GPU while on, for takeProfile. Vulkan writes timestamps around each; Metal, which has none inside a command buffer, commits and waits for every dispatch separately, so a forward pass takes far longer on the wall clock while this is on.
no getter
thermalState → int
0 nominal, 1 fair, 2 serious, 3 critical.
no setter

Static Methods

copyBandwidth(int megabytes) → double
GPU copy throughput in GB/s, bytes read plus written, over buffers of megabytes: roughly what the matrix products could reach.
restoreDecodeRowsDefault() → void
Returns decodeRows to the backend's default.
restoreQ8VectorDefault() → bool
Restores automatic selection for registered, validated LM heads.
setQ8Vector(bool on) → bool
Overrides scoped automatic selection with scalar/vector Q8 loads. False if unavailable (including Metal).
setQ8Workgroup(int invocations) → bool
Q8 decode workgroup size on Vulkan; false if unsupported (Metal too).
takeProfile() → Map<String, (double, int)>
GPU milliseconds and dispatch counts per kernel kind since the last call; empty if nothing was dispatched while profiling.

Constants

kernelKinds → const List<String>
The kernel kinds takeProfile reports, in the C layer's order.