Views
No views yet
MLState (Stateful Core ML) with fixed sequence length bounds.LIV Convolution state management dynamically concats cache tensors over time, an operation that is incompatible with the ANE's static memory requirements.conv_cache and standard attention key_value caches are allocated to fixed bounds (e.g. MAX_SEQ_LEN = 512) at initialization.tensor[:] = ... and tensor[:, :, cache_position, :] = ...).ct.StateType inputs/outputs during coremltools conversion so the Swift runtime can handle them efficiently as MLState opaque handles.MLState instead of passing the caches explicitly:1import CoreML
2
3let config = MLModelConfiguration()
4config.computeUnits = .cpuAndGPU // or .all, though ANE compile success may vary by iOS patch
5let model = try await LFM2_5_1_2B_Stateful(configuration: config)
6
7let state = model.makeState()
8
9// Token generation loop
10let input = LFM2_5_1_2B_StatefulInput(
11 input_ids: currentTokenArray,
12 cache_position: cachePositionArray,
13 attention_mask: attentionMaskArray
14)
15
16let output = try await model.prediction(input: input, using: state)tokenizer.json and a specific model_config.json designed for the app's ModelDownloadService.