ngxson HF Staff commited on
Commit
dc73656
·
verified ·
1 Parent(s): cf7c716

narrow widths for a smaller slice

Browse files
Files changed (4) hide show
  1. README.md +3 -3
  2. config.json +12 -12
  3. model.safetensors +2 -2
  4. slice_d1omni.py +21 -14
README.md CHANGED
@@ -20,10 +20,10 @@ GGUF version: [ggml-org-dev/tiny-d1-Omni-2B-for-testing-GGUF](https://huggingfac
20
 
21
  Sliced from the safetensors with [slice_d1omni.py](slice_d1omni.py), which follows the `slice-model` skill of llama.cpp:
22
 
23
- - Text model: 4 of 24 layers (0, 2, 3, 4), hidden size 2048 -> 256, heads 16 -> 2, KV heads 4 -> 1, FFN 7680 -> 256
24
- - Audio encoder: 3 of 17 layers (0, 2, 3), FFN 1792 -> 256
25
  - Depthformer: 1 of 3 layers, hidden size 1024 -> 128, heads 32 -> 4, KV heads 8 -> 1, FFN 2816 -> 256
26
- - Vision encoder: 2 of 14 layers (0, 2), hidden size 1024 -> 256, heads 16 -> 4, KV heads 8 -> 2, FFN 2560 -> 256, projector 4096 -> 256
27
  - The Python code of the original repo is not included
28
 
29
  ## License
 
20
 
21
  Sliced from the safetensors with [slice_d1omni.py](slice_d1omni.py), which follows the `slice-model` skill of llama.cpp:
22
 
23
+ - Text model: 4 of 24 layers (0, 2, 3, 4), hidden size 2048 -> 64, heads 16 -> 2, KV heads 4 -> 1, FFN 7680 -> 128
24
+ - Audio encoder: 3 of 17 layers (0, 2, 3), hidden size 768 -> 192, heads 8 -> 2, KV heads 4 -> 1, FFN 1792 -> 256, downsampler channels 256 -> 32
25
  - Depthformer: 1 of 3 layers, hidden size 1024 -> 128, heads 32 -> 4, KV heads 8 -> 1, FFN 2816 -> 256
26
+ - Vision encoder: 2 of 14 layers (0, 2), hidden size 1024 -> 128, heads 16 -> 2, KV heads 8 -> 1, FFN 2560 -> 128, projector 4096 -> 128
27
  - The Python code of the original repo is not included
28
 
29
  ## License
config.json CHANGED
@@ -3,9 +3,9 @@
3
  "D1Model"
4
  ],
5
  "audio_encoder_config": {
6
- "conv_channels": 256,
7
  "dtype": "bfloat16",
8
- "hidden_size": 768,
9
  "initializer_range": 0.02,
10
  "model_type": "lfm3_omni_encoder",
11
  "num_mel_bins": 128,
@@ -22,7 +22,7 @@
22
  "dtype": null,
23
  "eos_token_id": null,
24
  "full_attn_idxs": null,
25
- "hidden_size": 768,
26
  "id2label": {
27
  "0": "LABEL_0",
28
  "1": "LABEL_1"
@@ -42,9 +42,9 @@
42
  "max_position_embeddings": 128000,
43
  "model_type": "lfm2",
44
  "norm_eps": 1e-05,
45
- "num_attention_heads": 8,
46
  "num_hidden_layers": 3,
47
- "num_key_value_heads": 4,
48
  "output_attentions": false,
49
  "output_hidden_states": false,
50
  "pad_token_id": 0,
@@ -114,7 +114,7 @@
114
  "num_codebooks": 12,
115
  "projector_bias": true,
116
  "projector_hidden_act": "gelu",
117
- "projector_hidden_size": 256,
118
  "projector_layer_norm_eps": 1e-06,
119
  "text_config": {
120
  "bos_token_id": 124894,
@@ -123,9 +123,9 @@
123
  "dtype": "bfloat16",
124
  "eos_token_id": 124900,
125
  "head_dim": 128,
126
- "hidden_size": 256,
127
  "initializer_range": 0.02,
128
- "intermediate_size": 256,
129
  "layer_types": [
130
  "conv",
131
  "full_attention",
@@ -164,19 +164,19 @@
164
  "vision_config": {
165
  "conv_kernel_size": 3,
166
  "dtype": "bfloat16",
167
- "hidden_size": 256,
168
  "in_channels": 3,
169
  "initializer_range": 0.02,
170
- "intermediate_size": 256,
171
  "layer_types": [
172
  "conv",
173
  "full_attention"
174
  ],
175
  "model_type": "lfm3_vl_vision",
176
  "norm_eps": 1e-05,
177
- "num_attention_heads": 4,
178
  "num_hidden_layers": 2,
179
- "num_key_value_heads": 2,
180
  "patch_size": 16,
181
  "rope_parameters": {
182
  "rope_theta": 1000000.0,
 
3
  "D1Model"
4
  ],
5
  "audio_encoder_config": {
6
+ "conv_channels": 32,
7
  "dtype": "bfloat16",
8
+ "hidden_size": 192,
9
  "initializer_range": 0.02,
10
  "model_type": "lfm3_omni_encoder",
11
  "num_mel_bins": 128,
 
22
  "dtype": null,
23
  "eos_token_id": null,
24
  "full_attn_idxs": null,
25
+ "hidden_size": 192,
26
  "id2label": {
27
  "0": "LABEL_0",
28
  "1": "LABEL_1"
 
42
  "max_position_embeddings": 128000,
43
  "model_type": "lfm2",
44
  "norm_eps": 1e-05,
45
+ "num_attention_heads": 2,
46
  "num_hidden_layers": 3,
47
+ "num_key_value_heads": 1,
48
  "output_attentions": false,
49
  "output_hidden_states": false,
50
  "pad_token_id": 0,
 
114
  "num_codebooks": 12,
115
  "projector_bias": true,
116
  "projector_hidden_act": "gelu",
117
+ "projector_hidden_size": 128,
118
  "projector_layer_norm_eps": 1e-06,
119
  "text_config": {
120
  "bos_token_id": 124894,
 
123
  "dtype": "bfloat16",
124
  "eos_token_id": 124900,
125
  "head_dim": 128,
126
+ "hidden_size": 64,
127
  "initializer_range": 0.02,
128
+ "intermediate_size": 128,
129
  "layer_types": [
130
  "conv",
131
  "full_attention",
 
164
  "vision_config": {
165
  "conv_kernel_size": 3,
166
  "dtype": "bfloat16",
167
+ "hidden_size": 128,
168
  "in_channels": 3,
169
  "initializer_range": 0.02,
170
+ "intermediate_size": 128,
171
  "layer_types": [
172
  "conv",
173
  "full_attention"
174
  ],
175
  "model_type": "lfm3_vl_vision",
176
  "norm_eps": 1e-05,
177
+ "num_attention_heads": 2,
178
  "num_hidden_layers": 2,
179
+ "num_key_value_heads": 1,
180
  "patch_size": 16,
181
  "rope_parameters": {
182
  "rope_theta": 1000000.0,
model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:df1c9c45490846bb74d558cbc84a353c5bd18427fbc83f041e2f0adc682d89d5
3
- size 115435464
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e797ab67253810715e2e6ec9e46072f5d689c297e2a57792a03635679531e54c
3
+ size 29555272
slice_d1omni.py CHANGED
@@ -20,10 +20,11 @@ from safetensors.torch import save_file
20
  REPO = 'LiquidAI/d1-omni-2B'
21
  AUX = ['tokenizer.json', 'tokenizer_config.json', 'chat_template.jinja', 'processor_config.json', 'calibration.json', 'LICENSE']
22
 
23
- E, H, KV, FF = 256, 2, 1, 256 # text: hidden, heads, kv heads, ffn. head_dim stays 128
24
  D, DH, DKV, DFF = 128, 4, 1, 256 # depthformer, head_dim stays 32
25
- V, VH, VKV, VFF, VP = 256, 4, 2, 256, 256 # vision, head_dim stays 64, VP is the projector hidden size
26
- AFF = 256 # audio encoder ffn, the width stays 768
 
27
  CFF = 256 # codec ffn, width and layer count are hardcoded in clip.cpp
28
  N_CB = 12
29
  TEXT_LAYERS = [0, 2, 3, 4] # conv, full attn, conv, sliding attn
@@ -102,13 +103,18 @@ def narrow(name, t):
102
  if name.startswith('model.vision_tower.layers.'):
103
  return lfm_block(t, name, V, VFF, VH * 64, VKV * 64)
104
  if name.startswith('model.audio_encoder.lfm.layers.'):
105
- if name.endswith(('feed_forward.w1.weight', 'feed_forward.w3.weight')):
106
- return t[:AFF, :]
107
- if name.endswith('feed_forward.w2.weight'):
108
- return t[:, :AFF]
109
- return t
110
- if name.startswith(('model.audio_encoder.', )):
111
- return t
 
 
 
 
 
112
  table = {
113
  'model.language_model.embed_tokens.weight': lambda: t[:, :E],
114
  'model.language_model.embedding_norm.weight': lambda: t[:E],
@@ -117,9 +123,9 @@ def narrow(name, t):
117
  'model.depth_decoder.depth_linear.bias': lambda: t.reshape(N_CB, -1)[:, :D].reshape(-1),
118
  'model.depth_decoder.mask_embedding': lambda: t[:D],
119
  'model.depth_decoder.model.embedding_norm.weight': lambda: t[:D],
120
- 'model.audio_projector.layer_norm.weight': lambda: t,
121
- 'model.audio_projector.layer_norm.bias': lambda: t,
122
- 'model.audio_projector.linear_1.weight': lambda: t[:E, :],
123
  'model.audio_projector.linear_1.bias': lambda: t[:E],
124
  'model.audio_projector.linear_2.weight': lambda: t[:E, :E],
125
  'model.audio_projector.linear_2.bias': lambda: t[:E],
@@ -175,8 +181,9 @@ def narrow_codec(name, t):
175
  def patch_config(c):
176
  t = c['text_config']
177
  t.update(hidden_size=E, intermediate_size=FF, num_attention_heads=H, num_key_value_heads=KV, num_hidden_layers=len(TEXT_LAYERS), layer_types=[t['layer_types'][i] for i in TEXT_LAYERS])
 
178
  a = c['audio_encoder_config']['text_config']
179
- a.update(intermediate_size=AUDIO_INTERMEDIATE, num_hidden_layers=len(AUDIO_LAYERS), layer_types=[a['layer_types'][i] for i in AUDIO_LAYERS])
180
  d = c['depth_config']
181
  d.update(hidden_size=D, intermediate_size=DFF, num_attention_heads=DH, num_key_value_heads=DKV, num_hidden_layers=len(DEPTH_LAYERS), layer_types=[d['layer_types'][i] for i in DEPTH_LAYERS])
182
  v = c['vision_config']
 
20
  REPO = 'LiquidAI/d1-omni-2B'
21
  AUX = ['tokenizer.json', 'tokenizer_config.json', 'chat_template.jinja', 'processor_config.json', 'calibration.json', 'LICENSE']
22
 
23
+ E, H, KV, FF = 64, 2, 1, 128 # text: hidden, heads, kv heads, ffn. head_dim stays 128
24
  D, DH, DKV, DFF = 128, 4, 1, 256 # depthformer, head_dim stays 32
25
+ V, VH, VKV, VFF, VP = 128, 2, 1, 128, 128 # vision, head_dim stays 64, VP is the projector hidden size
26
+ A, AH, AKV, AFF = 192, 2, 1, 256 # audio encoder: width, heads, kv heads, ffn. head_dim stays 96
27
+ AC = 32 # audio downsampler channels, 256 -> 32
28
  CFF = 256 # codec ffn, width and layer count are hardcoded in clip.cpp
29
  N_CB = 12
30
  TEXT_LAYERS = [0, 2, 3, 4] # conv, full attn, conv, sliding attn
 
103
  if name.startswith('model.vision_tower.layers.'):
104
  return lfm_block(t, name, V, VFF, VH * 64, VKV * 64)
105
  if name.startswith('model.audio_encoder.lfm.layers.'):
106
+ return lfm_block(t, name, A, AFF, AH * 96, AKV * 96)
107
+ if name == 'model.audio_encoder.lfm.embedding_norm.weight':
108
+ return t[:A]
109
+ if name.startswith('model.audio_encoder.downsample.'):
110
+ # conv_in, conv_mid, conv_end: [ch, 1, 3, 3] (conv_in has 1 input channel, the others are depthwise), lin_*: [ch, ch, 1, 1]
111
+ if name.endswith(('lin_mid.weight', 'lin_end.weight')):
112
+ return t[:AC, :AC]
113
+ if name.endswith('lin_out.weight'): # [A, ch * n_mel / 8, 1], the input is channel-major
114
+ return t.reshape(t.shape[0], 256, -1, 1)[:A, :AC].reshape(A, -1, 1)
115
+ if name.endswith('lin_out.bias'):
116
+ return t[:A]
117
+ return t[:AC]
118
  table = {
119
  'model.language_model.embed_tokens.weight': lambda: t[:, :E],
120
  'model.language_model.embedding_norm.weight': lambda: t[:E],
 
123
  'model.depth_decoder.depth_linear.bias': lambda: t.reshape(N_CB, -1)[:, :D].reshape(-1),
124
  'model.depth_decoder.mask_embedding': lambda: t[:D],
125
  'model.depth_decoder.model.embedding_norm.weight': lambda: t[:D],
126
+ 'model.audio_projector.layer_norm.weight': lambda: t[:A],
127
+ 'model.audio_projector.layer_norm.bias': lambda: t[:A],
128
+ 'model.audio_projector.linear_1.weight': lambda: t[:E, :A],
129
  'model.audio_projector.linear_1.bias': lambda: t[:E],
130
  'model.audio_projector.linear_2.weight': lambda: t[:E, :E],
131
  'model.audio_projector.linear_2.bias': lambda: t[:E],
 
181
  def patch_config(c):
182
  t = c['text_config']
183
  t.update(hidden_size=E, intermediate_size=FF, num_attention_heads=H, num_key_value_heads=KV, num_hidden_layers=len(TEXT_LAYERS), layer_types=[t['layer_types'][i] for i in TEXT_LAYERS])
184
+ c['audio_encoder_config'].update(hidden_size=A, conv_channels=AC)
185
  a = c['audio_encoder_config']['text_config']
186
+ a.update(hidden_size=A, num_attention_heads=AH, num_key_value_heads=AKV, intermediate_size=AUDIO_INTERMEDIATE, num_hidden_layers=len(AUDIO_LAYERS), layer_types=[a['layer_types'][i] for i in AUDIO_LAYERS])
187
  d = c['depth_config']
188
  d.update(hidden_size=D, intermediate_size=DFF, num_attention_heads=DH, num_key_value_heads=DKV, num_hidden_layers=len(DEPTH_LAYERS), layer_types=[d['layer_types'][i] for i in DEPTH_LAYERS])
189
  v = c['vision_config']