Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
library_name: coreml
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
tags:
|
| 7 |
+
- lfm
|
| 8 |
+
- liquid
|
| 9 |
+
- coreml
|
| 10 |
+
- apple-neural-engine
|
| 11 |
+
- ane
|
| 12 |
+
- on-device
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# LFM 2.5 1.2B Instruct - Core ML (ANE)
|
| 16 |
+
|
| 17 |
+
This is an experimental Core ML export of [LiquidAI/LFM2.5-1.2B-Instruct](https://huggingface.co/LiquidAI/LFM2.5-1.2B-Instruct), specifically optimized and structured for the Apple Neural Engine (ANE) using Core ML 7's Stateful API.
|
| 18 |
+
|
| 19 |
+
## Model Details
|
| 20 |
+
- **Architecture**: Liquid Foundation Model (LFM) - LIV Convolution + Full Attention Hybrid
|
| 21 |
+
- **Size**: 1.2B Parameters
|
| 22 |
+
- **Quantization**: 4-bit Linear Symmetric (INT4 weights)
|
| 23 |
+
- **Target Runtime**: Core ML / Apple Neural Engine (iOS 18+ / macOS 15+)
|
| 24 |
+
- **Cache Handling**: Native `MLState` (Stateful Core ML) with fixed sequence length bounds.
|
| 25 |
+
|
| 26 |
+
## Integration & Export Details
|
| 27 |
+
This model has been adapted from its original PyTorch format because the native `LIV Convolution` state management dynamically concats cache tensors over time, an operation that is incompatible with the ANE's static memory requirements.
|
| 28 |
+
|
| 29 |
+
To solve this, the export pipeline applied the following transformations:
|
| 30 |
+
1. **Static Buffer Allocation**: The rolling `conv_cache` and standard attention `key_value` caches are allocated to fixed bounds (e.g. `MAX_SEQ_LEN = 512`) at initialization.
|
| 31 |
+
2. **In-Place Updates**: Dynamic slice concatenation was monkey-patched to use in-place slice assignment (`tensor[:] = ...` and `tensor[:, :, cache_position, :] = ...`).
|
| 32 |
+
3. **Core ML 7 State Mapping**: These buffers are registered as `ct.StateType` inputs/outputs during `coremltools` conversion so the Swift runtime can handle them efficiently as `MLState` opaque handles.
|
| 33 |
+
4. **INT4 Quantization**: The linear layers have been quantized to 4-bit to fit within strict iOS Jetsam limits on 8GB devices.
|
| 34 |
+
|
| 35 |
+
## Usage in Swift
|
| 36 |
+
This model must be invoked using `MLState` instead of passing the caches explicitly:
|
| 37 |
+
|
| 38 |
+
```swift
|
| 39 |
+
import CoreML
|
| 40 |
+
|
| 41 |
+
let config = MLModelConfiguration()
|
| 42 |
+
config.computeUnits = .cpuAndGPU // or .all, though ANE compile success may vary by iOS patch
|
| 43 |
+
let model = try await LFM2_5_1_2B_Stateful(configuration: config)
|
| 44 |
+
|
| 45 |
+
let state = model.makeState()
|
| 46 |
+
|
| 47 |
+
// Token generation loop
|
| 48 |
+
let input = LFM2_5_1_2B_StatefulInput(
|
| 49 |
+
input_ids: currentTokenArray,
|
| 50 |
+
cache_position: cachePositionArray,
|
| 51 |
+
attention_mask: attentionMaskArray
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
let output = try await model.prediction(input: input, using: state)
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
## Intended Use
|
| 58 |
+
This repository was compiled for use inside [iMLX](https://github.com/alan13367/iMLX) (an experimental local inference chat app for iOS). It includes the original Hugging Face `tokenizer.json` and a specific `model_config.json` designed for the app's `ModelDownloadService`.
|