addProjected method
Invalid rows/context overflow are rejected before model state changes. Calls are serialized; concurrent calls fail instead of mixing recordings. Any forward-pass failure terminates this prefill; start a new one to retry.
Implementation
Future<void> addProjected(Float32List rows) async {
_checkOpen();
final h = _template.hiddenSize;
if (rows.length % h != 0 || rows.any((v) => !v.isFinite)) {
throw ArgumentError('expected finite projected audio rows');
}
final count = rows.length ~/ h;
if (promptTokens + count + reservedTokens > _model.maxSeq) {
throw ArgumentError('audio rows and token reserve exceed context');
}
if (count == 0) return;
final owned = Float32List.fromList(rows);
final id = _template.ids[_template.audioStart];
_busy = true;
try {
await _model.forward(
List.filled(count, id),
computeLogits: false,
embeddingOverrides: {
for (var t = 0; t < count; t++)
t: Float32List.sublistView(owned, t * h, (t + 1) * h),
},
);
if (_closed) throw StateError('Audio prefill was closed');
_audioTokens += count;
} catch (_) {
_closed = true;
rethrow;
} finally {
_busy = false;
}
}