mlboydaisuke commited on
Commit
25f89bc
·
verified ·
1 Parent(s): f3686df

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: LiquidAI/LFM2.5-350M
4
+ tags:
5
+ - coreml
6
+ - ane
7
+ - lfm2
8
+ - on-device
9
+ - iphone
10
+ language:
11
+ - en
12
+ - ja
13
+ library_name: coreml
14
+ pipeline_tag: text-generation
15
+ ---
16
+
17
+ # LFM2.5 350M — CoreML build for Apple Neural Engine
18
+
19
+ CoreML port of [LiquidAI/LFM2.5-350M](https://huggingface.co/LiquidAI/LFM2.5-350M)
20
+ for the [CoreML-LLM](https://github.com/john-rocky/CoreML-LLM) iOS / macOS
21
+ runtime. fp16 weights, 97.8 % ANE-resident on iPhone 17 Pro,
22
+ **52 tok/s** decode in CoreMLLLMChat.
23
+
24
+ ## Files
25
+
26
+ ```
27
+ model.mlmodelc/ # compiled — ready to MLModel(contentsOf:)
28
+ model_config.json # context_length, num_hidden_layers, lfm2_conv_l_pad …
29
+ hf_model/ # tokenizer (ChatML, sanitised for swift-transformers)
30
+ ├── tokenizer.json
31
+ ├── tokenizer_config.json
32
+ ├── config.json
33
+ └── generation_config.json
34
+ ```
35
+
36
+ ## How to use
37
+
38
+ ### Sideload to CoreMLLLMChat
39
+
40
+ ```bash
41
+ DEVICE=$(xcrun devicectl list devices | awk '/connected/{print $3}' | head -1)
42
+ xcrun devicectl device copy to --device "$DEVICE" \
43
+ --domain-type appDataContainer \
44
+ --domain-identifier com.example.CoreMLLLMChat \
45
+ --source ./lfm2.5-350m-coreml \
46
+ --destination Documents/Models/lfm2.5-350m \
47
+ --remove-existing-content true
48
+ ```
49
+
50
+ The chat app's model picker will surface "LFM2.5 350M (ANE)" once the
51
+ folder is in place.
52
+
53
+ ### Direct CoreML load
54
+
55
+ ```python
56
+ import coremltools as ct, numpy as np
57
+ m = ct.models.CompiledMLModel("model.mlmodelc",
58
+ compute_units=ct.ComputeUnit.CPU_AND_NE)
59
+ state = m.make_state()
60
+ ctx = 2048
61
+ conv = np.zeros((10, 1024, 3), dtype=np.float16) # n_conv × hidden × L_cache
62
+ # … feed input_ids / position_ids / causal_mask / update_mask / conv_state_in,
63
+ # carry conv_state_out forward as the next conv_state_in.
64
+ ```
65
+
66
+ ## Architecture notes
67
+
68
+ * Hybrid: 6 attention layers (GQA + RoPE + QK-norm) + 10 short-conv
69
+ layers (depthwise causal Conv1d, kernel = 3).
70
+ * The conv-state rolling window is passed as an **input/output tensor**,
71
+ not via MLState — the M-series ANE planner rejects the dual-state
72
+ combination (kv_cache + conv_cache) at predict-time.
73
+ * `L_pad = conv_L_cache = 3`. An earlier 16-wide padding fed enough
74
+ fp16 noise into the depthwise reduction that autoregressive output
75
+ collapsed to "kingkingking…" within a few tokens.
76
+ * Compute precision is the default fp16; no fp32 fallback needed once
77
+ the padding is fixed.
78
+ * Chat template: ChatML (`<|im_start|>role\n…<|im_end|>\n`) wrapped in
79
+ `<|startoftext|>`. EOS = `<|im_end|>` (id 7) and `<|endoftext|>` (id 2).
80
+
81
+ Full conversion + ANE-residency + drift writeup:
82
+ [docs/LFM2_CONVERSION_FINDINGS.md](https://github.com/john-rocky/CoreML-LLM/blob/main/docs/LFM2_CONVERSION_FINDINGS.md).
83
+
84
+ ## License
85
+
86
+ Apache 2.0 (inherited from the base model).
hf_model/config.json ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Lfm2ForCausalLM"
4
+ ],
5
+ "block_auto_adjust_ff_dim": true,
6
+ "block_dim": 1024,
7
+ "block_ff_dim": 6656,
8
+ "block_ffn_dim_multiplier": 1.0,
9
+ "block_mlp_init_scale": 1.0,
10
+ "block_multiple_of": 256,
11
+ "block_norm_eps": 1e-05,
12
+ "block_out_init_scale": 1.0,
13
+ "block_use_swiglu": true,
14
+ "block_use_xavier_init": true,
15
+ "bos_token_id": 1,
16
+ "conv_L_cache": 3,
17
+ "conv_bias": false,
18
+ "conv_dim": 1024,
19
+ "conv_use_xavier_init": true,
20
+ "dtype": "bfloat16",
21
+ "eos_token_id": 7,
22
+ "hidden_size": 1024,
23
+ "initializer_range": 0.02,
24
+ "intermediate_size": 6656,
25
+ "layer_types": [
26
+ "conv",
27
+ "conv",
28
+ "full_attention",
29
+ "conv",
30
+ "conv",
31
+ "full_attention",
32
+ "conv",
33
+ "conv",
34
+ "full_attention",
35
+ "conv",
36
+ "full_attention",
37
+ "conv",
38
+ "full_attention",
39
+ "conv",
40
+ "full_attention",
41
+ "conv"
42
+ ],
43
+ "max_position_embeddings": 128000,
44
+ "model_type": "lfm2",
45
+ "norm_eps": 1e-05,
46
+ "num_attention_heads": 16,
47
+ "num_heads": 16,
48
+ "num_hidden_layers": 16,
49
+ "num_key_value_heads": 8,
50
+ "pad_token_id": 0,
51
+ "rope_parameters": {
52
+ "rope_theta": 1000000.0,
53
+ "rope_type": "default"
54
+ },
55
+ "tie_embedding": true,
56
+ "transformers_version": "5.0.0rc1",
57
+ "use_cache": true,
58
+ "use_pos_enc": true,
59
+ "vocab_size": 65536
60
+ }
hf_model/generation_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": 7,
5
+ "pad_token_id": 0,
6
+ "transformers_version": "5.0.0rc1"
7
+ }
hf_model/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
hf_model/tokenizer_config.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": null,
3
+ "bos_token": "<|startoftext|>",
4
+ "clean_up_tokenization_spaces": false,
5
+ "eos_token": "<|im_end|>",
6
+ "extra_special_tokens": [],
7
+ "is_local": true,
8
+ "legacy": false,
9
+ "model_input_names": [
10
+ "input_ids",
11
+ "attention_mask"
12
+ ],
13
+ "model_max_length": 1000000000000000019884624838656,
14
+ "model_specific_special_tokens": {},
15
+ "pad_token": "<|pad|>",
16
+ "sp_model_kwargs": {},
17
+ "spaces_between_special_tokens": false,
18
+ "tokenizer_class": "PreTrainedTokenizerFast",
19
+ "use_default_system_prompt": false,
20
+ "use_fast": true
21
+ }
model.mlmodelc/analytics/coremldata.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:09f06c44cf914efb67d7e6a53bc758708cab426ecd9ebdaa14974dea1086e02d
3
+ size 243
model.mlmodelc/coremldata.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ad46897b7e9d632356a272d0ef2c3d3ca1c63242b09c640838944cc638f618e7
3
+ size 581
model.mlmodelc/metadata.json ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "metadataOutputVersion" : "3.0",
4
+ "storagePrecision" : "Float16",
5
+ "outputSchema" : [
6
+ {
7
+ "hasShapeFlexibility" : "0",
8
+ "isOptional" : "0",
9
+ "dataType" : "Int32",
10
+ "formattedType" : "MultiArray (Int32 1)",
11
+ "shortDescription" : "",
12
+ "shape" : "[1]",
13
+ "name" : "token_id",
14
+ "type" : "MultiArray"
15
+ },
16
+ {
17
+ "hasShapeFlexibility" : "0",
18
+ "isOptional" : "0",
19
+ "dataType" : "Float16",
20
+ "formattedType" : "MultiArray (Float16 1)",
21
+ "shortDescription" : "",
22
+ "shape" : "[1]",
23
+ "name" : "token_logit",
24
+ "type" : "MultiArray"
25
+ },
26
+ {
27
+ "hasShapeFlexibility" : "0",
28
+ "isOptional" : "0",
29
+ "dataType" : "Float16",
30
+ "formattedType" : "MultiArray (Float16 10 × 1024 × 3)",
31
+ "shortDescription" : "",
32
+ "shape" : "[10, 1024, 3]",
33
+ "name" : "conv_state_out",
34
+ "type" : "MultiArray"
35
+ }
36
+ ],
37
+ "modelParameters" : [
38
+
39
+ ],
40
+ "specificationVersion" : 10,
41
+ "mlProgramOperationTypeHistogram" : {
42
+ "Ios18.softmax" : 6,
43
+ "Ios19.mul" : 192,
44
+ "Ios18.matmul" : 12,
45
+ "Ios19.sliceUpdate" : 12,
46
+ "Ios19.stack" : 1,
47
+ "Ios18.gatherAlongAxis" : 1,
48
+ "Ios19.squeeze" : 61,
49
+ "Ios18.readState" : 12,
50
+ "Tile" : 24,
51
+ "Ios18.gather" : 3,
52
+ "Ios19.add" : 63,
53
+ "Ios18.layerNorm" : 45,
54
+ "Ios18.writeState" : 12,
55
+ "Ios19.concat" : 67,
56
+ "Ios19.transpose" : 132,
57
+ "Ios18.reduceArgmax" : 1,
58
+ "Ios19.expandDims" : 66,
59
+ "Ios18.conv" : 103,
60
+ "Ios18.silu" : 16,
61
+ "Ios18.cast" : 1,
62
+ "Ios19.split" : 67,
63
+ "Ios19.sliceByIndex" : 32,
64
+ "Ios19.sub" : 1,
65
+ "Ios19.select" : 1,
66
+ "Ios19.greaterEqual" : 1,
67
+ "Ios19.reshape" : 50
68
+ },
69
+ "computePrecision" : "Mixed (Float16, Int32, UInt16)",
70
+ "isUpdatable" : "0",
71
+ "stateSchema" : [
72
+ {
73
+ "dataType" : "Float16",
74
+ "isOptional" : "0",
75
+ "formattedType" : "State (Float16 12 × 8 × 2048 × 64)",
76
+ "shortDescription" : "",
77
+ "shape" : "[12, 8, 2048, 64]",
78
+ "name" : "kv_cache_0",
79
+ "type" : "State"
80
+ }
81
+ ],
82
+ "availability" : {
83
+ "macOS" : "16.0",
84
+ "tvOS" : "19.0",
85
+ "visionOS" : "3.0",
86
+ "watchOS" : "12.0",
87
+ "iOS" : "19.0",
88
+ "macCatalyst" : "19.0"
89
+ },
90
+ "modelType" : {
91
+ "name" : "MLModelType_mlProgram"
92
+ },
93
+ "userDefinedMetadata" : {
94
+ "com.github.apple.coremltools.conversion_date" : "2026-04-28",
95
+ "com.github.apple.coremltools.source" : "torch==2.11.0",
96
+ "com.github.apple.coremltools.version" : "9.0",
97
+ "com.github.apple.coremltools.source_dialect" : "TorchScript"
98
+ },
99
+ "inputSchema" : [
100
+ {
101
+ "hasShapeFlexibility" : "0",
102
+ "isOptional" : "0",
103
+ "dataType" : "Int32",
104
+ "formattedType" : "MultiArray (Int32 1 × 1)",
105
+ "shortDescription" : "",
106
+ "shape" : "[1, 1]",
107
+ "name" : "input_ids",
108
+ "type" : "MultiArray"
109
+ },
110
+ {
111
+ "hasShapeFlexibility" : "0",
112
+ "isOptional" : "0",
113
+ "dataType" : "Int32",
114
+ "formattedType" : "MultiArray (Int32 1)",
115
+ "shortDescription" : "",
116
+ "shape" : "[1]",
117
+ "name" : "position_ids",
118
+ "type" : "MultiArray"
119
+ },
120
+ {
121
+ "hasShapeFlexibility" : "0",
122
+ "isOptional" : "0",
123
+ "dataType" : "Float16",
124
+ "formattedType" : "MultiArray (Float16 1 × 1 × 1 × 2048)",
125
+ "shortDescription" : "",
126
+ "shape" : "[1, 1, 1, 2048]",
127
+ "name" : "causal_mask",
128
+ "type" : "MultiArray"
129
+ },
130
+ {
131
+ "hasShapeFlexibility" : "0",
132
+ "isOptional" : "0",
133
+ "dataType" : "Float16",
134
+ "formattedType" : "MultiArray (Float16 1 × 1 × 2048 × 1)",
135
+ "shortDescription" : "",
136
+ "shape" : "[1, 1, 2048, 1]",
137
+ "name" : "update_mask",
138
+ "type" : "MultiArray"
139
+ },
140
+ {
141
+ "hasShapeFlexibility" : "0",
142
+ "isOptional" : "0",
143
+ "dataType" : "Float16",
144
+ "formattedType" : "MultiArray (Float16 10 × 1024 × 3)",
145
+ "shortDescription" : "",
146
+ "shape" : "[10, 1024, 3]",
147
+ "name" : "conv_state_in",
148
+ "type" : "MultiArray"
149
+ }
150
+ ],
151
+ "generatedClassName" : "model",
152
+ "method" : "predict"
153
+ }
154
+ ]
model.mlmodelc/model.mil ADDED
The diff for this file is too large to render. See raw diff
 
model.mlmodelc/weights/weight.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7c8fdbdae27808c26bb067e2c267aa8aee85cf153bb903ece94175623ee3650e
3
+ size 844243968
model_config.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_name": "hf_model",
3
+ "architecture": "lfm2",
4
+ "hidden_size": 1024,
5
+ "num_hidden_layers": 16,
6
+ "num_attention_heads": 16,
7
+ "num_key_value_heads": 8,
8
+ "head_dim": 64,
9
+ "vocab_size": 65536,
10
+ "context_length": 2048,
11
+ "rms_norm_eps": 1e-05,
12
+ "bos_token_id": 1,
13
+ "eos_token_id": 7,
14
+ "quantization": "int4",
15
+ "compute_units": "ALL",
16
+ "parts": {
17
+ "model": "model.mlpackage"
18
+ },
19
+ "tokenizer_repo": "hf_model",
20
+ "lfm2_conv_l_pad": 3
21
+ }