romerocruzsa commited on
Commit
5d969db
·
verified ·
1 Parent(s): ff9f2b1

Publish Cellpose-SAM WQuant W2A16-G64

Browse files
Files changed (7) hide show
  1. README.md +43 -0
  2. config.json +1921 -0
  3. model.safetensors +3 -0
  4. model_registry.json +9 -0
  5. requirements.txt +4 -0
  6. results.json +13 -0
  7. runtime_loader.py +169 -0
README.md ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: cellpose
3
+ pipeline_tag: image-segmentation
4
+ base_model: mouseland/cellpose-sam
5
+ base_model_relation: quantized
6
+ license: bsd-3-clause
7
+ tags:
8
+ - cellpose
9
+ - cellpose-sam
10
+ - microscopy
11
+ - quantization
12
+ - image-segmentation
13
+ ---
14
+
15
+ # Cellpose-SAM WQuant — W2A16-G64
16
+
17
+ Ready-to-load `W2A16-G64` quantized variant of
18
+ [Cellpose-SAM cpsam_v2](https://huggingface.co/mouseland/cellpose-sam).
19
+
20
+ ## Load
21
+
22
+ ```python
23
+ import runpy
24
+ from huggingface_hub import hf_hub_download
25
+
26
+ loader = runpy.run_path(
27
+ hf_hub_download("capicu-ai/cellpose-sam-wquant-w2a16-g64", "runtime_loader.py")
28
+ )
29
+ model = loader["load_model"]()
30
+ ```
31
+
32
+ Pass `device="cuda"` to `load_model` for CUDA.
33
+
34
+ ## Result
35
+
36
+ - Weight size: 96.3 MiB
37
+ - Compression versus FP32: 12.08x
38
+ - Evaluated paired samples: 20
39
+ - Complete bounded-panel criterion met: No
40
+ - Reload verification normalized RMSE: 0.0
41
+
42
+ `results.json` and `model_registry.json` contain the compact machine-readable
43
+ record.
config.json ADDED
@@ -0,0 +1,1921 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "schema_version": 1,
3
+ "base_model": "cpsam_v2",
4
+ "scheme": "W2A16-G64",
5
+ "replacements": [
6
+ {
7
+ "activation_bits": null,
8
+ "kind": "conv2d",
9
+ "name": "encoder.patch_embed.proj",
10
+ "quant_state": {
11
+ "bits": 2,
12
+ "code_count": 196608,
13
+ "group_size": 64,
14
+ "inner": 192,
15
+ "n_groups": 3,
16
+ "original_shape": [
17
+ 1024,
18
+ 3,
19
+ 8,
20
+ 8
21
+ ],
22
+ "padded_inner": 192,
23
+ "qmax": 1,
24
+ "rows": 1024
25
+ }
26
+ },
27
+ {
28
+ "activation_bits": null,
29
+ "kind": "linear",
30
+ "name": "encoder.blocks.0.attn.qkv",
31
+ "quant_state": {
32
+ "bits": 2,
33
+ "code_count": 3145728,
34
+ "group_size": 64,
35
+ "inner": 1024,
36
+ "n_groups": 16,
37
+ "original_shape": [
38
+ 3072,
39
+ 1024
40
+ ],
41
+ "padded_inner": 1024,
42
+ "qmax": 1,
43
+ "rows": 3072
44
+ }
45
+ },
46
+ {
47
+ "activation_bits": null,
48
+ "kind": "linear",
49
+ "name": "encoder.blocks.0.attn.proj",
50
+ "quant_state": {
51
+ "bits": 2,
52
+ "code_count": 1048576,
53
+ "group_size": 64,
54
+ "inner": 1024,
55
+ "n_groups": 16,
56
+ "original_shape": [
57
+ 1024,
58
+ 1024
59
+ ],
60
+ "padded_inner": 1024,
61
+ "qmax": 1,
62
+ "rows": 1024
63
+ }
64
+ },
65
+ {
66
+ "activation_bits": null,
67
+ "kind": "linear",
68
+ "name": "encoder.blocks.0.mlp.lin1",
69
+ "quant_state": {
70
+ "bits": 2,
71
+ "code_count": 4194304,
72
+ "group_size": 64,
73
+ "inner": 1024,
74
+ "n_groups": 16,
75
+ "original_shape": [
76
+ 4096,
77
+ 1024
78
+ ],
79
+ "padded_inner": 1024,
80
+ "qmax": 1,
81
+ "rows": 4096
82
+ }
83
+ },
84
+ {
85
+ "activation_bits": null,
86
+ "kind": "linear",
87
+ "name": "encoder.blocks.0.mlp.lin2",
88
+ "quant_state": {
89
+ "bits": 2,
90
+ "code_count": 4194304,
91
+ "group_size": 64,
92
+ "inner": 4096,
93
+ "n_groups": 64,
94
+ "original_shape": [
95
+ 1024,
96
+ 4096
97
+ ],
98
+ "padded_inner": 4096,
99
+ "qmax": 1,
100
+ "rows": 1024
101
+ }
102
+ },
103
+ {
104
+ "activation_bits": null,
105
+ "kind": "linear",
106
+ "name": "encoder.blocks.1.attn.qkv",
107
+ "quant_state": {
108
+ "bits": 2,
109
+ "code_count": 3145728,
110
+ "group_size": 64,
111
+ "inner": 1024,
112
+ "n_groups": 16,
113
+ "original_shape": [
114
+ 3072,
115
+ 1024
116
+ ],
117
+ "padded_inner": 1024,
118
+ "qmax": 1,
119
+ "rows": 3072
120
+ }
121
+ },
122
+ {
123
+ "activation_bits": null,
124
+ "kind": "linear",
125
+ "name": "encoder.blocks.1.attn.proj",
126
+ "quant_state": {
127
+ "bits": 2,
128
+ "code_count": 1048576,
129
+ "group_size": 64,
130
+ "inner": 1024,
131
+ "n_groups": 16,
132
+ "original_shape": [
133
+ 1024,
134
+ 1024
135
+ ],
136
+ "padded_inner": 1024,
137
+ "qmax": 1,
138
+ "rows": 1024
139
+ }
140
+ },
141
+ {
142
+ "activation_bits": null,
143
+ "kind": "linear",
144
+ "name": "encoder.blocks.1.mlp.lin1",
145
+ "quant_state": {
146
+ "bits": 2,
147
+ "code_count": 4194304,
148
+ "group_size": 64,
149
+ "inner": 1024,
150
+ "n_groups": 16,
151
+ "original_shape": [
152
+ 4096,
153
+ 1024
154
+ ],
155
+ "padded_inner": 1024,
156
+ "qmax": 1,
157
+ "rows": 4096
158
+ }
159
+ },
160
+ {
161
+ "activation_bits": null,
162
+ "kind": "linear",
163
+ "name": "encoder.blocks.1.mlp.lin2",
164
+ "quant_state": {
165
+ "bits": 2,
166
+ "code_count": 4194304,
167
+ "group_size": 64,
168
+ "inner": 4096,
169
+ "n_groups": 64,
170
+ "original_shape": [
171
+ 1024,
172
+ 4096
173
+ ],
174
+ "padded_inner": 4096,
175
+ "qmax": 1,
176
+ "rows": 1024
177
+ }
178
+ },
179
+ {
180
+ "activation_bits": null,
181
+ "kind": "linear",
182
+ "name": "encoder.blocks.2.attn.qkv",
183
+ "quant_state": {
184
+ "bits": 2,
185
+ "code_count": 3145728,
186
+ "group_size": 64,
187
+ "inner": 1024,
188
+ "n_groups": 16,
189
+ "original_shape": [
190
+ 3072,
191
+ 1024
192
+ ],
193
+ "padded_inner": 1024,
194
+ "qmax": 1,
195
+ "rows": 3072
196
+ }
197
+ },
198
+ {
199
+ "activation_bits": null,
200
+ "kind": "linear",
201
+ "name": "encoder.blocks.2.attn.proj",
202
+ "quant_state": {
203
+ "bits": 2,
204
+ "code_count": 1048576,
205
+ "group_size": 64,
206
+ "inner": 1024,
207
+ "n_groups": 16,
208
+ "original_shape": [
209
+ 1024,
210
+ 1024
211
+ ],
212
+ "padded_inner": 1024,
213
+ "qmax": 1,
214
+ "rows": 1024
215
+ }
216
+ },
217
+ {
218
+ "activation_bits": null,
219
+ "kind": "linear",
220
+ "name": "encoder.blocks.2.mlp.lin1",
221
+ "quant_state": {
222
+ "bits": 2,
223
+ "code_count": 4194304,
224
+ "group_size": 64,
225
+ "inner": 1024,
226
+ "n_groups": 16,
227
+ "original_shape": [
228
+ 4096,
229
+ 1024
230
+ ],
231
+ "padded_inner": 1024,
232
+ "qmax": 1,
233
+ "rows": 4096
234
+ }
235
+ },
236
+ {
237
+ "activation_bits": null,
238
+ "kind": "linear",
239
+ "name": "encoder.blocks.2.mlp.lin2",
240
+ "quant_state": {
241
+ "bits": 2,
242
+ "code_count": 4194304,
243
+ "group_size": 64,
244
+ "inner": 4096,
245
+ "n_groups": 64,
246
+ "original_shape": [
247
+ 1024,
248
+ 4096
249
+ ],
250
+ "padded_inner": 4096,
251
+ "qmax": 1,
252
+ "rows": 1024
253
+ }
254
+ },
255
+ {
256
+ "activation_bits": null,
257
+ "kind": "linear",
258
+ "name": "encoder.blocks.3.attn.qkv",
259
+ "quant_state": {
260
+ "bits": 2,
261
+ "code_count": 3145728,
262
+ "group_size": 64,
263
+ "inner": 1024,
264
+ "n_groups": 16,
265
+ "original_shape": [
266
+ 3072,
267
+ 1024
268
+ ],
269
+ "padded_inner": 1024,
270
+ "qmax": 1,
271
+ "rows": 3072
272
+ }
273
+ },
274
+ {
275
+ "activation_bits": null,
276
+ "kind": "linear",
277
+ "name": "encoder.blocks.3.attn.proj",
278
+ "quant_state": {
279
+ "bits": 2,
280
+ "code_count": 1048576,
281
+ "group_size": 64,
282
+ "inner": 1024,
283
+ "n_groups": 16,
284
+ "original_shape": [
285
+ 1024,
286
+ 1024
287
+ ],
288
+ "padded_inner": 1024,
289
+ "qmax": 1,
290
+ "rows": 1024
291
+ }
292
+ },
293
+ {
294
+ "activation_bits": null,
295
+ "kind": "linear",
296
+ "name": "encoder.blocks.3.mlp.lin1",
297
+ "quant_state": {
298
+ "bits": 2,
299
+ "code_count": 4194304,
300
+ "group_size": 64,
301
+ "inner": 1024,
302
+ "n_groups": 16,
303
+ "original_shape": [
304
+ 4096,
305
+ 1024
306
+ ],
307
+ "padded_inner": 1024,
308
+ "qmax": 1,
309
+ "rows": 4096
310
+ }
311
+ },
312
+ {
313
+ "activation_bits": null,
314
+ "kind": "linear",
315
+ "name": "encoder.blocks.3.mlp.lin2",
316
+ "quant_state": {
317
+ "bits": 2,
318
+ "code_count": 4194304,
319
+ "group_size": 64,
320
+ "inner": 4096,
321
+ "n_groups": 64,
322
+ "original_shape": [
323
+ 1024,
324
+ 4096
325
+ ],
326
+ "padded_inner": 4096,
327
+ "qmax": 1,
328
+ "rows": 1024
329
+ }
330
+ },
331
+ {
332
+ "activation_bits": null,
333
+ "kind": "linear",
334
+ "name": "encoder.blocks.4.attn.qkv",
335
+ "quant_state": {
336
+ "bits": 2,
337
+ "code_count": 3145728,
338
+ "group_size": 64,
339
+ "inner": 1024,
340
+ "n_groups": 16,
341
+ "original_shape": [
342
+ 3072,
343
+ 1024
344
+ ],
345
+ "padded_inner": 1024,
346
+ "qmax": 1,
347
+ "rows": 3072
348
+ }
349
+ },
350
+ {
351
+ "activation_bits": null,
352
+ "kind": "linear",
353
+ "name": "encoder.blocks.4.attn.proj",
354
+ "quant_state": {
355
+ "bits": 2,
356
+ "code_count": 1048576,
357
+ "group_size": 64,
358
+ "inner": 1024,
359
+ "n_groups": 16,
360
+ "original_shape": [
361
+ 1024,
362
+ 1024
363
+ ],
364
+ "padded_inner": 1024,
365
+ "qmax": 1,
366
+ "rows": 1024
367
+ }
368
+ },
369
+ {
370
+ "activation_bits": null,
371
+ "kind": "linear",
372
+ "name": "encoder.blocks.4.mlp.lin1",
373
+ "quant_state": {
374
+ "bits": 2,
375
+ "code_count": 4194304,
376
+ "group_size": 64,
377
+ "inner": 1024,
378
+ "n_groups": 16,
379
+ "original_shape": [
380
+ 4096,
381
+ 1024
382
+ ],
383
+ "padded_inner": 1024,
384
+ "qmax": 1,
385
+ "rows": 4096
386
+ }
387
+ },
388
+ {
389
+ "activation_bits": null,
390
+ "kind": "linear",
391
+ "name": "encoder.blocks.4.mlp.lin2",
392
+ "quant_state": {
393
+ "bits": 2,
394
+ "code_count": 4194304,
395
+ "group_size": 64,
396
+ "inner": 4096,
397
+ "n_groups": 64,
398
+ "original_shape": [
399
+ 1024,
400
+ 4096
401
+ ],
402
+ "padded_inner": 4096,
403
+ "qmax": 1,
404
+ "rows": 1024
405
+ }
406
+ },
407
+ {
408
+ "activation_bits": null,
409
+ "kind": "linear",
410
+ "name": "encoder.blocks.5.attn.qkv",
411
+ "quant_state": {
412
+ "bits": 2,
413
+ "code_count": 3145728,
414
+ "group_size": 64,
415
+ "inner": 1024,
416
+ "n_groups": 16,
417
+ "original_shape": [
418
+ 3072,
419
+ 1024
420
+ ],
421
+ "padded_inner": 1024,
422
+ "qmax": 1,
423
+ "rows": 3072
424
+ }
425
+ },
426
+ {
427
+ "activation_bits": null,
428
+ "kind": "linear",
429
+ "name": "encoder.blocks.5.attn.proj",
430
+ "quant_state": {
431
+ "bits": 2,
432
+ "code_count": 1048576,
433
+ "group_size": 64,
434
+ "inner": 1024,
435
+ "n_groups": 16,
436
+ "original_shape": [
437
+ 1024,
438
+ 1024
439
+ ],
440
+ "padded_inner": 1024,
441
+ "qmax": 1,
442
+ "rows": 1024
443
+ }
444
+ },
445
+ {
446
+ "activation_bits": null,
447
+ "kind": "linear",
448
+ "name": "encoder.blocks.5.mlp.lin1",
449
+ "quant_state": {
450
+ "bits": 2,
451
+ "code_count": 4194304,
452
+ "group_size": 64,
453
+ "inner": 1024,
454
+ "n_groups": 16,
455
+ "original_shape": [
456
+ 4096,
457
+ 1024
458
+ ],
459
+ "padded_inner": 1024,
460
+ "qmax": 1,
461
+ "rows": 4096
462
+ }
463
+ },
464
+ {
465
+ "activation_bits": null,
466
+ "kind": "linear",
467
+ "name": "encoder.blocks.5.mlp.lin2",
468
+ "quant_state": {
469
+ "bits": 2,
470
+ "code_count": 4194304,
471
+ "group_size": 64,
472
+ "inner": 4096,
473
+ "n_groups": 64,
474
+ "original_shape": [
475
+ 1024,
476
+ 4096
477
+ ],
478
+ "padded_inner": 4096,
479
+ "qmax": 1,
480
+ "rows": 1024
481
+ }
482
+ },
483
+ {
484
+ "activation_bits": null,
485
+ "kind": "linear",
486
+ "name": "encoder.blocks.6.attn.qkv",
487
+ "quant_state": {
488
+ "bits": 2,
489
+ "code_count": 3145728,
490
+ "group_size": 64,
491
+ "inner": 1024,
492
+ "n_groups": 16,
493
+ "original_shape": [
494
+ 3072,
495
+ 1024
496
+ ],
497
+ "padded_inner": 1024,
498
+ "qmax": 1,
499
+ "rows": 3072
500
+ }
501
+ },
502
+ {
503
+ "activation_bits": null,
504
+ "kind": "linear",
505
+ "name": "encoder.blocks.6.attn.proj",
506
+ "quant_state": {
507
+ "bits": 2,
508
+ "code_count": 1048576,
509
+ "group_size": 64,
510
+ "inner": 1024,
511
+ "n_groups": 16,
512
+ "original_shape": [
513
+ 1024,
514
+ 1024
515
+ ],
516
+ "padded_inner": 1024,
517
+ "qmax": 1,
518
+ "rows": 1024
519
+ }
520
+ },
521
+ {
522
+ "activation_bits": null,
523
+ "kind": "linear",
524
+ "name": "encoder.blocks.6.mlp.lin1",
525
+ "quant_state": {
526
+ "bits": 2,
527
+ "code_count": 4194304,
528
+ "group_size": 64,
529
+ "inner": 1024,
530
+ "n_groups": 16,
531
+ "original_shape": [
532
+ 4096,
533
+ 1024
534
+ ],
535
+ "padded_inner": 1024,
536
+ "qmax": 1,
537
+ "rows": 4096
538
+ }
539
+ },
540
+ {
541
+ "activation_bits": null,
542
+ "kind": "linear",
543
+ "name": "encoder.blocks.6.mlp.lin2",
544
+ "quant_state": {
545
+ "bits": 2,
546
+ "code_count": 4194304,
547
+ "group_size": 64,
548
+ "inner": 4096,
549
+ "n_groups": 64,
550
+ "original_shape": [
551
+ 1024,
552
+ 4096
553
+ ],
554
+ "padded_inner": 4096,
555
+ "qmax": 1,
556
+ "rows": 1024
557
+ }
558
+ },
559
+ {
560
+ "activation_bits": null,
561
+ "kind": "linear",
562
+ "name": "encoder.blocks.7.attn.qkv",
563
+ "quant_state": {
564
+ "bits": 2,
565
+ "code_count": 3145728,
566
+ "group_size": 64,
567
+ "inner": 1024,
568
+ "n_groups": 16,
569
+ "original_shape": [
570
+ 3072,
571
+ 1024
572
+ ],
573
+ "padded_inner": 1024,
574
+ "qmax": 1,
575
+ "rows": 3072
576
+ }
577
+ },
578
+ {
579
+ "activation_bits": null,
580
+ "kind": "linear",
581
+ "name": "encoder.blocks.7.attn.proj",
582
+ "quant_state": {
583
+ "bits": 2,
584
+ "code_count": 1048576,
585
+ "group_size": 64,
586
+ "inner": 1024,
587
+ "n_groups": 16,
588
+ "original_shape": [
589
+ 1024,
590
+ 1024
591
+ ],
592
+ "padded_inner": 1024,
593
+ "qmax": 1,
594
+ "rows": 1024
595
+ }
596
+ },
597
+ {
598
+ "activation_bits": null,
599
+ "kind": "linear",
600
+ "name": "encoder.blocks.7.mlp.lin1",
601
+ "quant_state": {
602
+ "bits": 2,
603
+ "code_count": 4194304,
604
+ "group_size": 64,
605
+ "inner": 1024,
606
+ "n_groups": 16,
607
+ "original_shape": [
608
+ 4096,
609
+ 1024
610
+ ],
611
+ "padded_inner": 1024,
612
+ "qmax": 1,
613
+ "rows": 4096
614
+ }
615
+ },
616
+ {
617
+ "activation_bits": null,
618
+ "kind": "linear",
619
+ "name": "encoder.blocks.7.mlp.lin2",
620
+ "quant_state": {
621
+ "bits": 2,
622
+ "code_count": 4194304,
623
+ "group_size": 64,
624
+ "inner": 4096,
625
+ "n_groups": 64,
626
+ "original_shape": [
627
+ 1024,
628
+ 4096
629
+ ],
630
+ "padded_inner": 4096,
631
+ "qmax": 1,
632
+ "rows": 1024
633
+ }
634
+ },
635
+ {
636
+ "activation_bits": null,
637
+ "kind": "linear",
638
+ "name": "encoder.blocks.8.attn.qkv",
639
+ "quant_state": {
640
+ "bits": 2,
641
+ "code_count": 3145728,
642
+ "group_size": 64,
643
+ "inner": 1024,
644
+ "n_groups": 16,
645
+ "original_shape": [
646
+ 3072,
647
+ 1024
648
+ ],
649
+ "padded_inner": 1024,
650
+ "qmax": 1,
651
+ "rows": 3072
652
+ }
653
+ },
654
+ {
655
+ "activation_bits": null,
656
+ "kind": "linear",
657
+ "name": "encoder.blocks.8.attn.proj",
658
+ "quant_state": {
659
+ "bits": 2,
660
+ "code_count": 1048576,
661
+ "group_size": 64,
662
+ "inner": 1024,
663
+ "n_groups": 16,
664
+ "original_shape": [
665
+ 1024,
666
+ 1024
667
+ ],
668
+ "padded_inner": 1024,
669
+ "qmax": 1,
670
+ "rows": 1024
671
+ }
672
+ },
673
+ {
674
+ "activation_bits": null,
675
+ "kind": "linear",
676
+ "name": "encoder.blocks.8.mlp.lin1",
677
+ "quant_state": {
678
+ "bits": 2,
679
+ "code_count": 4194304,
680
+ "group_size": 64,
681
+ "inner": 1024,
682
+ "n_groups": 16,
683
+ "original_shape": [
684
+ 4096,
685
+ 1024
686
+ ],
687
+ "padded_inner": 1024,
688
+ "qmax": 1,
689
+ "rows": 4096
690
+ }
691
+ },
692
+ {
693
+ "activation_bits": null,
694
+ "kind": "linear",
695
+ "name": "encoder.blocks.8.mlp.lin2",
696
+ "quant_state": {
697
+ "bits": 2,
698
+ "code_count": 4194304,
699
+ "group_size": 64,
700
+ "inner": 4096,
701
+ "n_groups": 64,
702
+ "original_shape": [
703
+ 1024,
704
+ 4096
705
+ ],
706
+ "padded_inner": 4096,
707
+ "qmax": 1,
708
+ "rows": 1024
709
+ }
710
+ },
711
+ {
712
+ "activation_bits": null,
713
+ "kind": "linear",
714
+ "name": "encoder.blocks.9.attn.qkv",
715
+ "quant_state": {
716
+ "bits": 2,
717
+ "code_count": 3145728,
718
+ "group_size": 64,
719
+ "inner": 1024,
720
+ "n_groups": 16,
721
+ "original_shape": [
722
+ 3072,
723
+ 1024
724
+ ],
725
+ "padded_inner": 1024,
726
+ "qmax": 1,
727
+ "rows": 3072
728
+ }
729
+ },
730
+ {
731
+ "activation_bits": null,
732
+ "kind": "linear",
733
+ "name": "encoder.blocks.9.attn.proj",
734
+ "quant_state": {
735
+ "bits": 2,
736
+ "code_count": 1048576,
737
+ "group_size": 64,
738
+ "inner": 1024,
739
+ "n_groups": 16,
740
+ "original_shape": [
741
+ 1024,
742
+ 1024
743
+ ],
744
+ "padded_inner": 1024,
745
+ "qmax": 1,
746
+ "rows": 1024
747
+ }
748
+ },
749
+ {
750
+ "activation_bits": null,
751
+ "kind": "linear",
752
+ "name": "encoder.blocks.9.mlp.lin1",
753
+ "quant_state": {
754
+ "bits": 2,
755
+ "code_count": 4194304,
756
+ "group_size": 64,
757
+ "inner": 1024,
758
+ "n_groups": 16,
759
+ "original_shape": [
760
+ 4096,
761
+ 1024
762
+ ],
763
+ "padded_inner": 1024,
764
+ "qmax": 1,
765
+ "rows": 4096
766
+ }
767
+ },
768
+ {
769
+ "activation_bits": null,
770
+ "kind": "linear",
771
+ "name": "encoder.blocks.9.mlp.lin2",
772
+ "quant_state": {
773
+ "bits": 2,
774
+ "code_count": 4194304,
775
+ "group_size": 64,
776
+ "inner": 4096,
777
+ "n_groups": 64,
778
+ "original_shape": [
779
+ 1024,
780
+ 4096
781
+ ],
782
+ "padded_inner": 4096,
783
+ "qmax": 1,
784
+ "rows": 1024
785
+ }
786
+ },
787
+ {
788
+ "activation_bits": null,
789
+ "kind": "linear",
790
+ "name": "encoder.blocks.10.attn.qkv",
791
+ "quant_state": {
792
+ "bits": 2,
793
+ "code_count": 3145728,
794
+ "group_size": 64,
795
+ "inner": 1024,
796
+ "n_groups": 16,
797
+ "original_shape": [
798
+ 3072,
799
+ 1024
800
+ ],
801
+ "padded_inner": 1024,
802
+ "qmax": 1,
803
+ "rows": 3072
804
+ }
805
+ },
806
+ {
807
+ "activation_bits": null,
808
+ "kind": "linear",
809
+ "name": "encoder.blocks.10.attn.proj",
810
+ "quant_state": {
811
+ "bits": 2,
812
+ "code_count": 1048576,
813
+ "group_size": 64,
814
+ "inner": 1024,
815
+ "n_groups": 16,
816
+ "original_shape": [
817
+ 1024,
818
+ 1024
819
+ ],
820
+ "padded_inner": 1024,
821
+ "qmax": 1,
822
+ "rows": 1024
823
+ }
824
+ },
825
+ {
826
+ "activation_bits": null,
827
+ "kind": "linear",
828
+ "name": "encoder.blocks.10.mlp.lin1",
829
+ "quant_state": {
830
+ "bits": 2,
831
+ "code_count": 4194304,
832
+ "group_size": 64,
833
+ "inner": 1024,
834
+ "n_groups": 16,
835
+ "original_shape": [
836
+ 4096,
837
+ 1024
838
+ ],
839
+ "padded_inner": 1024,
840
+ "qmax": 1,
841
+ "rows": 4096
842
+ }
843
+ },
844
+ {
845
+ "activation_bits": null,
846
+ "kind": "linear",
847
+ "name": "encoder.blocks.10.mlp.lin2",
848
+ "quant_state": {
849
+ "bits": 2,
850
+ "code_count": 4194304,
851
+ "group_size": 64,
852
+ "inner": 4096,
853
+ "n_groups": 64,
854
+ "original_shape": [
855
+ 1024,
856
+ 4096
857
+ ],
858
+ "padded_inner": 4096,
859
+ "qmax": 1,
860
+ "rows": 1024
861
+ }
862
+ },
863
+ {
864
+ "activation_bits": null,
865
+ "kind": "linear",
866
+ "name": "encoder.blocks.11.attn.qkv",
867
+ "quant_state": {
868
+ "bits": 2,
869
+ "code_count": 3145728,
870
+ "group_size": 64,
871
+ "inner": 1024,
872
+ "n_groups": 16,
873
+ "original_shape": [
874
+ 3072,
875
+ 1024
876
+ ],
877
+ "padded_inner": 1024,
878
+ "qmax": 1,
879
+ "rows": 3072
880
+ }
881
+ },
882
+ {
883
+ "activation_bits": null,
884
+ "kind": "linear",
885
+ "name": "encoder.blocks.11.attn.proj",
886
+ "quant_state": {
887
+ "bits": 2,
888
+ "code_count": 1048576,
889
+ "group_size": 64,
890
+ "inner": 1024,
891
+ "n_groups": 16,
892
+ "original_shape": [
893
+ 1024,
894
+ 1024
895
+ ],
896
+ "padded_inner": 1024,
897
+ "qmax": 1,
898
+ "rows": 1024
899
+ }
900
+ },
901
+ {
902
+ "activation_bits": null,
903
+ "kind": "linear",
904
+ "name": "encoder.blocks.11.mlp.lin1",
905
+ "quant_state": {
906
+ "bits": 2,
907
+ "code_count": 4194304,
908
+ "group_size": 64,
909
+ "inner": 1024,
910
+ "n_groups": 16,
911
+ "original_shape": [
912
+ 4096,
913
+ 1024
914
+ ],
915
+ "padded_inner": 1024,
916
+ "qmax": 1,
917
+ "rows": 4096
918
+ }
919
+ },
920
+ {
921
+ "activation_bits": null,
922
+ "kind": "linear",
923
+ "name": "encoder.blocks.11.mlp.lin2",
924
+ "quant_state": {
925
+ "bits": 2,
926
+ "code_count": 4194304,
927
+ "group_size": 64,
928
+ "inner": 4096,
929
+ "n_groups": 64,
930
+ "original_shape": [
931
+ 1024,
932
+ 4096
933
+ ],
934
+ "padded_inner": 4096,
935
+ "qmax": 1,
936
+ "rows": 1024
937
+ }
938
+ },
939
+ {
940
+ "activation_bits": null,
941
+ "kind": "linear",
942
+ "name": "encoder.blocks.12.attn.qkv",
943
+ "quant_state": {
944
+ "bits": 2,
945
+ "code_count": 3145728,
946
+ "group_size": 64,
947
+ "inner": 1024,
948
+ "n_groups": 16,
949
+ "original_shape": [
950
+ 3072,
951
+ 1024
952
+ ],
953
+ "padded_inner": 1024,
954
+ "qmax": 1,
955
+ "rows": 3072
956
+ }
957
+ },
958
+ {
959
+ "activation_bits": null,
960
+ "kind": "linear",
961
+ "name": "encoder.blocks.12.attn.proj",
962
+ "quant_state": {
963
+ "bits": 2,
964
+ "code_count": 1048576,
965
+ "group_size": 64,
966
+ "inner": 1024,
967
+ "n_groups": 16,
968
+ "original_shape": [
969
+ 1024,
970
+ 1024
971
+ ],
972
+ "padded_inner": 1024,
973
+ "qmax": 1,
974
+ "rows": 1024
975
+ }
976
+ },
977
+ {
978
+ "activation_bits": null,
979
+ "kind": "linear",
980
+ "name": "encoder.blocks.12.mlp.lin1",
981
+ "quant_state": {
982
+ "bits": 2,
983
+ "code_count": 4194304,
984
+ "group_size": 64,
985
+ "inner": 1024,
986
+ "n_groups": 16,
987
+ "original_shape": [
988
+ 4096,
989
+ 1024
990
+ ],
991
+ "padded_inner": 1024,
992
+ "qmax": 1,
993
+ "rows": 4096
994
+ }
995
+ },
996
+ {
997
+ "activation_bits": null,
998
+ "kind": "linear",
999
+ "name": "encoder.blocks.12.mlp.lin2",
1000
+ "quant_state": {
1001
+ "bits": 2,
1002
+ "code_count": 4194304,
1003
+ "group_size": 64,
1004
+ "inner": 4096,
1005
+ "n_groups": 64,
1006
+ "original_shape": [
1007
+ 1024,
1008
+ 4096
1009
+ ],
1010
+ "padded_inner": 4096,
1011
+ "qmax": 1,
1012
+ "rows": 1024
1013
+ }
1014
+ },
1015
+ {
1016
+ "activation_bits": null,
1017
+ "kind": "linear",
1018
+ "name": "encoder.blocks.13.attn.qkv",
1019
+ "quant_state": {
1020
+ "bits": 2,
1021
+ "code_count": 3145728,
1022
+ "group_size": 64,
1023
+ "inner": 1024,
1024
+ "n_groups": 16,
1025
+ "original_shape": [
1026
+ 3072,
1027
+ 1024
1028
+ ],
1029
+ "padded_inner": 1024,
1030
+ "qmax": 1,
1031
+ "rows": 3072
1032
+ }
1033
+ },
1034
+ {
1035
+ "activation_bits": null,
1036
+ "kind": "linear",
1037
+ "name": "encoder.blocks.13.attn.proj",
1038
+ "quant_state": {
1039
+ "bits": 2,
1040
+ "code_count": 1048576,
1041
+ "group_size": 64,
1042
+ "inner": 1024,
1043
+ "n_groups": 16,
1044
+ "original_shape": [
1045
+ 1024,
1046
+ 1024
1047
+ ],
1048
+ "padded_inner": 1024,
1049
+ "qmax": 1,
1050
+ "rows": 1024
1051
+ }
1052
+ },
1053
+ {
1054
+ "activation_bits": null,
1055
+ "kind": "linear",
1056
+ "name": "encoder.blocks.13.mlp.lin1",
1057
+ "quant_state": {
1058
+ "bits": 2,
1059
+ "code_count": 4194304,
1060
+ "group_size": 64,
1061
+ "inner": 1024,
1062
+ "n_groups": 16,
1063
+ "original_shape": [
1064
+ 4096,
1065
+ 1024
1066
+ ],
1067
+ "padded_inner": 1024,
1068
+ "qmax": 1,
1069
+ "rows": 4096
1070
+ }
1071
+ },
1072
+ {
1073
+ "activation_bits": null,
1074
+ "kind": "linear",
1075
+ "name": "encoder.blocks.13.mlp.lin2",
1076
+ "quant_state": {
1077
+ "bits": 2,
1078
+ "code_count": 4194304,
1079
+ "group_size": 64,
1080
+ "inner": 4096,
1081
+ "n_groups": 64,
1082
+ "original_shape": [
1083
+ 1024,
1084
+ 4096
1085
+ ],
1086
+ "padded_inner": 4096,
1087
+ "qmax": 1,
1088
+ "rows": 1024
1089
+ }
1090
+ },
1091
+ {
1092
+ "activation_bits": null,
1093
+ "kind": "linear",
1094
+ "name": "encoder.blocks.14.attn.qkv",
1095
+ "quant_state": {
1096
+ "bits": 2,
1097
+ "code_count": 3145728,
1098
+ "group_size": 64,
1099
+ "inner": 1024,
1100
+ "n_groups": 16,
1101
+ "original_shape": [
1102
+ 3072,
1103
+ 1024
1104
+ ],
1105
+ "padded_inner": 1024,
1106
+ "qmax": 1,
1107
+ "rows": 3072
1108
+ }
1109
+ },
1110
+ {
1111
+ "activation_bits": null,
1112
+ "kind": "linear",
1113
+ "name": "encoder.blocks.14.attn.proj",
1114
+ "quant_state": {
1115
+ "bits": 2,
1116
+ "code_count": 1048576,
1117
+ "group_size": 64,
1118
+ "inner": 1024,
1119
+ "n_groups": 16,
1120
+ "original_shape": [
1121
+ 1024,
1122
+ 1024
1123
+ ],
1124
+ "padded_inner": 1024,
1125
+ "qmax": 1,
1126
+ "rows": 1024
1127
+ }
1128
+ },
1129
+ {
1130
+ "activation_bits": null,
1131
+ "kind": "linear",
1132
+ "name": "encoder.blocks.14.mlp.lin1",
1133
+ "quant_state": {
1134
+ "bits": 2,
1135
+ "code_count": 4194304,
1136
+ "group_size": 64,
1137
+ "inner": 1024,
1138
+ "n_groups": 16,
1139
+ "original_shape": [
1140
+ 4096,
1141
+ 1024
1142
+ ],
1143
+ "padded_inner": 1024,
1144
+ "qmax": 1,
1145
+ "rows": 4096
1146
+ }
1147
+ },
1148
+ {
1149
+ "activation_bits": null,
1150
+ "kind": "linear",
1151
+ "name": "encoder.blocks.14.mlp.lin2",
1152
+ "quant_state": {
1153
+ "bits": 2,
1154
+ "code_count": 4194304,
1155
+ "group_size": 64,
1156
+ "inner": 4096,
1157
+ "n_groups": 64,
1158
+ "original_shape": [
1159
+ 1024,
1160
+ 4096
1161
+ ],
1162
+ "padded_inner": 4096,
1163
+ "qmax": 1,
1164
+ "rows": 1024
1165
+ }
1166
+ },
1167
+ {
1168
+ "activation_bits": null,
1169
+ "kind": "linear",
1170
+ "name": "encoder.blocks.15.attn.qkv",
1171
+ "quant_state": {
1172
+ "bits": 2,
1173
+ "code_count": 3145728,
1174
+ "group_size": 64,
1175
+ "inner": 1024,
1176
+ "n_groups": 16,
1177
+ "original_shape": [
1178
+ 3072,
1179
+ 1024
1180
+ ],
1181
+ "padded_inner": 1024,
1182
+ "qmax": 1,
1183
+ "rows": 3072
1184
+ }
1185
+ },
1186
+ {
1187
+ "activation_bits": null,
1188
+ "kind": "linear",
1189
+ "name": "encoder.blocks.15.attn.proj",
1190
+ "quant_state": {
1191
+ "bits": 2,
1192
+ "code_count": 1048576,
1193
+ "group_size": 64,
1194
+ "inner": 1024,
1195
+ "n_groups": 16,
1196
+ "original_shape": [
1197
+ 1024,
1198
+ 1024
1199
+ ],
1200
+ "padded_inner": 1024,
1201
+ "qmax": 1,
1202
+ "rows": 1024
1203
+ }
1204
+ },
1205
+ {
1206
+ "activation_bits": null,
1207
+ "kind": "linear",
1208
+ "name": "encoder.blocks.15.mlp.lin1",
1209
+ "quant_state": {
1210
+ "bits": 2,
1211
+ "code_count": 4194304,
1212
+ "group_size": 64,
1213
+ "inner": 1024,
1214
+ "n_groups": 16,
1215
+ "original_shape": [
1216
+ 4096,
1217
+ 1024
1218
+ ],
1219
+ "padded_inner": 1024,
1220
+ "qmax": 1,
1221
+ "rows": 4096
1222
+ }
1223
+ },
1224
+ {
1225
+ "activation_bits": null,
1226
+ "kind": "linear",
1227
+ "name": "encoder.blocks.15.mlp.lin2",
1228
+ "quant_state": {
1229
+ "bits": 2,
1230
+ "code_count": 4194304,
1231
+ "group_size": 64,
1232
+ "inner": 4096,
1233
+ "n_groups": 64,
1234
+ "original_shape": [
1235
+ 1024,
1236
+ 4096
1237
+ ],
1238
+ "padded_inner": 4096,
1239
+ "qmax": 1,
1240
+ "rows": 1024
1241
+ }
1242
+ },
1243
+ {
1244
+ "activation_bits": null,
1245
+ "kind": "linear",
1246
+ "name": "encoder.blocks.16.attn.qkv",
1247
+ "quant_state": {
1248
+ "bits": 2,
1249
+ "code_count": 3145728,
1250
+ "group_size": 64,
1251
+ "inner": 1024,
1252
+ "n_groups": 16,
1253
+ "original_shape": [
1254
+ 3072,
1255
+ 1024
1256
+ ],
1257
+ "padded_inner": 1024,
1258
+ "qmax": 1,
1259
+ "rows": 3072
1260
+ }
1261
+ },
1262
+ {
1263
+ "activation_bits": null,
1264
+ "kind": "linear",
1265
+ "name": "encoder.blocks.16.attn.proj",
1266
+ "quant_state": {
1267
+ "bits": 2,
1268
+ "code_count": 1048576,
1269
+ "group_size": 64,
1270
+ "inner": 1024,
1271
+ "n_groups": 16,
1272
+ "original_shape": [
1273
+ 1024,
1274
+ 1024
1275
+ ],
1276
+ "padded_inner": 1024,
1277
+ "qmax": 1,
1278
+ "rows": 1024
1279
+ }
1280
+ },
1281
+ {
1282
+ "activation_bits": null,
1283
+ "kind": "linear",
1284
+ "name": "encoder.blocks.16.mlp.lin1",
1285
+ "quant_state": {
1286
+ "bits": 2,
1287
+ "code_count": 4194304,
1288
+ "group_size": 64,
1289
+ "inner": 1024,
1290
+ "n_groups": 16,
1291
+ "original_shape": [
1292
+ 4096,
1293
+ 1024
1294
+ ],
1295
+ "padded_inner": 1024,
1296
+ "qmax": 1,
1297
+ "rows": 4096
1298
+ }
1299
+ },
1300
+ {
1301
+ "activation_bits": null,
1302
+ "kind": "linear",
1303
+ "name": "encoder.blocks.16.mlp.lin2",
1304
+ "quant_state": {
1305
+ "bits": 2,
1306
+ "code_count": 4194304,
1307
+ "group_size": 64,
1308
+ "inner": 4096,
1309
+ "n_groups": 64,
1310
+ "original_shape": [
1311
+ 1024,
1312
+ 4096
1313
+ ],
1314
+ "padded_inner": 4096,
1315
+ "qmax": 1,
1316
+ "rows": 1024
1317
+ }
1318
+ },
1319
+ {
1320
+ "activation_bits": null,
1321
+ "kind": "linear",
1322
+ "name": "encoder.blocks.17.attn.qkv",
1323
+ "quant_state": {
1324
+ "bits": 2,
1325
+ "code_count": 3145728,
1326
+ "group_size": 64,
1327
+ "inner": 1024,
1328
+ "n_groups": 16,
1329
+ "original_shape": [
1330
+ 3072,
1331
+ 1024
1332
+ ],
1333
+ "padded_inner": 1024,
1334
+ "qmax": 1,
1335
+ "rows": 3072
1336
+ }
1337
+ },
1338
+ {
1339
+ "activation_bits": null,
1340
+ "kind": "linear",
1341
+ "name": "encoder.blocks.17.attn.proj",
1342
+ "quant_state": {
1343
+ "bits": 2,
1344
+ "code_count": 1048576,
1345
+ "group_size": 64,
1346
+ "inner": 1024,
1347
+ "n_groups": 16,
1348
+ "original_shape": [
1349
+ 1024,
1350
+ 1024
1351
+ ],
1352
+ "padded_inner": 1024,
1353
+ "qmax": 1,
1354
+ "rows": 1024
1355
+ }
1356
+ },
1357
+ {
1358
+ "activation_bits": null,
1359
+ "kind": "linear",
1360
+ "name": "encoder.blocks.17.mlp.lin1",
1361
+ "quant_state": {
1362
+ "bits": 2,
1363
+ "code_count": 4194304,
1364
+ "group_size": 64,
1365
+ "inner": 1024,
1366
+ "n_groups": 16,
1367
+ "original_shape": [
1368
+ 4096,
1369
+ 1024
1370
+ ],
1371
+ "padded_inner": 1024,
1372
+ "qmax": 1,
1373
+ "rows": 4096
1374
+ }
1375
+ },
1376
+ {
1377
+ "activation_bits": null,
1378
+ "kind": "linear",
1379
+ "name": "encoder.blocks.17.mlp.lin2",
1380
+ "quant_state": {
1381
+ "bits": 2,
1382
+ "code_count": 4194304,
1383
+ "group_size": 64,
1384
+ "inner": 4096,
1385
+ "n_groups": 64,
1386
+ "original_shape": [
1387
+ 1024,
1388
+ 4096
1389
+ ],
1390
+ "padded_inner": 4096,
1391
+ "qmax": 1,
1392
+ "rows": 1024
1393
+ }
1394
+ },
1395
+ {
1396
+ "activation_bits": null,
1397
+ "kind": "linear",
1398
+ "name": "encoder.blocks.18.attn.qkv",
1399
+ "quant_state": {
1400
+ "bits": 2,
1401
+ "code_count": 3145728,
1402
+ "group_size": 64,
1403
+ "inner": 1024,
1404
+ "n_groups": 16,
1405
+ "original_shape": [
1406
+ 3072,
1407
+ 1024
1408
+ ],
1409
+ "padded_inner": 1024,
1410
+ "qmax": 1,
1411
+ "rows": 3072
1412
+ }
1413
+ },
1414
+ {
1415
+ "activation_bits": null,
1416
+ "kind": "linear",
1417
+ "name": "encoder.blocks.18.attn.proj",
1418
+ "quant_state": {
1419
+ "bits": 2,
1420
+ "code_count": 1048576,
1421
+ "group_size": 64,
1422
+ "inner": 1024,
1423
+ "n_groups": 16,
1424
+ "original_shape": [
1425
+ 1024,
1426
+ 1024
1427
+ ],
1428
+ "padded_inner": 1024,
1429
+ "qmax": 1,
1430
+ "rows": 1024
1431
+ }
1432
+ },
1433
+ {
1434
+ "activation_bits": null,
1435
+ "kind": "linear",
1436
+ "name": "encoder.blocks.18.mlp.lin1",
1437
+ "quant_state": {
1438
+ "bits": 2,
1439
+ "code_count": 4194304,
1440
+ "group_size": 64,
1441
+ "inner": 1024,
1442
+ "n_groups": 16,
1443
+ "original_shape": [
1444
+ 4096,
1445
+ 1024
1446
+ ],
1447
+ "padded_inner": 1024,
1448
+ "qmax": 1,
1449
+ "rows": 4096
1450
+ }
1451
+ },
1452
+ {
1453
+ "activation_bits": null,
1454
+ "kind": "linear",
1455
+ "name": "encoder.blocks.18.mlp.lin2",
1456
+ "quant_state": {
1457
+ "bits": 2,
1458
+ "code_count": 4194304,
1459
+ "group_size": 64,
1460
+ "inner": 4096,
1461
+ "n_groups": 64,
1462
+ "original_shape": [
1463
+ 1024,
1464
+ 4096
1465
+ ],
1466
+ "padded_inner": 4096,
1467
+ "qmax": 1,
1468
+ "rows": 1024
1469
+ }
1470
+ },
1471
+ {
1472
+ "activation_bits": null,
1473
+ "kind": "linear",
1474
+ "name": "encoder.blocks.19.attn.qkv",
1475
+ "quant_state": {
1476
+ "bits": 2,
1477
+ "code_count": 3145728,
1478
+ "group_size": 64,
1479
+ "inner": 1024,
1480
+ "n_groups": 16,
1481
+ "original_shape": [
1482
+ 3072,
1483
+ 1024
1484
+ ],
1485
+ "padded_inner": 1024,
1486
+ "qmax": 1,
1487
+ "rows": 3072
1488
+ }
1489
+ },
1490
+ {
1491
+ "activation_bits": null,
1492
+ "kind": "linear",
1493
+ "name": "encoder.blocks.19.attn.proj",
1494
+ "quant_state": {
1495
+ "bits": 2,
1496
+ "code_count": 1048576,
1497
+ "group_size": 64,
1498
+ "inner": 1024,
1499
+ "n_groups": 16,
1500
+ "original_shape": [
1501
+ 1024,
1502
+ 1024
1503
+ ],
1504
+ "padded_inner": 1024,
1505
+ "qmax": 1,
1506
+ "rows": 1024
1507
+ }
1508
+ },
1509
+ {
1510
+ "activation_bits": null,
1511
+ "kind": "linear",
1512
+ "name": "encoder.blocks.19.mlp.lin1",
1513
+ "quant_state": {
1514
+ "bits": 2,
1515
+ "code_count": 4194304,
1516
+ "group_size": 64,
1517
+ "inner": 1024,
1518
+ "n_groups": 16,
1519
+ "original_shape": [
1520
+ 4096,
1521
+ 1024
1522
+ ],
1523
+ "padded_inner": 1024,
1524
+ "qmax": 1,
1525
+ "rows": 4096
1526
+ }
1527
+ },
1528
+ {
1529
+ "activation_bits": null,
1530
+ "kind": "linear",
1531
+ "name": "encoder.blocks.19.mlp.lin2",
1532
+ "quant_state": {
1533
+ "bits": 2,
1534
+ "code_count": 4194304,
1535
+ "group_size": 64,
1536
+ "inner": 4096,
1537
+ "n_groups": 64,
1538
+ "original_shape": [
1539
+ 1024,
1540
+ 4096
1541
+ ],
1542
+ "padded_inner": 4096,
1543
+ "qmax": 1,
1544
+ "rows": 1024
1545
+ }
1546
+ },
1547
+ {
1548
+ "activation_bits": null,
1549
+ "kind": "linear",
1550
+ "name": "encoder.blocks.20.attn.qkv",
1551
+ "quant_state": {
1552
+ "bits": 2,
1553
+ "code_count": 3145728,
1554
+ "group_size": 64,
1555
+ "inner": 1024,
1556
+ "n_groups": 16,
1557
+ "original_shape": [
1558
+ 3072,
1559
+ 1024
1560
+ ],
1561
+ "padded_inner": 1024,
1562
+ "qmax": 1,
1563
+ "rows": 3072
1564
+ }
1565
+ },
1566
+ {
1567
+ "activation_bits": null,
1568
+ "kind": "linear",
1569
+ "name": "encoder.blocks.20.attn.proj",
1570
+ "quant_state": {
1571
+ "bits": 2,
1572
+ "code_count": 1048576,
1573
+ "group_size": 64,
1574
+ "inner": 1024,
1575
+ "n_groups": 16,
1576
+ "original_shape": [
1577
+ 1024,
1578
+ 1024
1579
+ ],
1580
+ "padded_inner": 1024,
1581
+ "qmax": 1,
1582
+ "rows": 1024
1583
+ }
1584
+ },
1585
+ {
1586
+ "activation_bits": null,
1587
+ "kind": "linear",
1588
+ "name": "encoder.blocks.20.mlp.lin1",
1589
+ "quant_state": {
1590
+ "bits": 2,
1591
+ "code_count": 4194304,
1592
+ "group_size": 64,
1593
+ "inner": 1024,
1594
+ "n_groups": 16,
1595
+ "original_shape": [
1596
+ 4096,
1597
+ 1024
1598
+ ],
1599
+ "padded_inner": 1024,
1600
+ "qmax": 1,
1601
+ "rows": 4096
1602
+ }
1603
+ },
1604
+ {
1605
+ "activation_bits": null,
1606
+ "kind": "linear",
1607
+ "name": "encoder.blocks.20.mlp.lin2",
1608
+ "quant_state": {
1609
+ "bits": 2,
1610
+ "code_count": 4194304,
1611
+ "group_size": 64,
1612
+ "inner": 4096,
1613
+ "n_groups": 64,
1614
+ "original_shape": [
1615
+ 1024,
1616
+ 4096
1617
+ ],
1618
+ "padded_inner": 4096,
1619
+ "qmax": 1,
1620
+ "rows": 1024
1621
+ }
1622
+ },
1623
+ {
1624
+ "activation_bits": null,
1625
+ "kind": "linear",
1626
+ "name": "encoder.blocks.21.attn.qkv",
1627
+ "quant_state": {
1628
+ "bits": 2,
1629
+ "code_count": 3145728,
1630
+ "group_size": 64,
1631
+ "inner": 1024,
1632
+ "n_groups": 16,
1633
+ "original_shape": [
1634
+ 3072,
1635
+ 1024
1636
+ ],
1637
+ "padded_inner": 1024,
1638
+ "qmax": 1,
1639
+ "rows": 3072
1640
+ }
1641
+ },
1642
+ {
1643
+ "activation_bits": null,
1644
+ "kind": "linear",
1645
+ "name": "encoder.blocks.21.attn.proj",
1646
+ "quant_state": {
1647
+ "bits": 2,
1648
+ "code_count": 1048576,
1649
+ "group_size": 64,
1650
+ "inner": 1024,
1651
+ "n_groups": 16,
1652
+ "original_shape": [
1653
+ 1024,
1654
+ 1024
1655
+ ],
1656
+ "padded_inner": 1024,
1657
+ "qmax": 1,
1658
+ "rows": 1024
1659
+ }
1660
+ },
1661
+ {
1662
+ "activation_bits": null,
1663
+ "kind": "linear",
1664
+ "name": "encoder.blocks.21.mlp.lin1",
1665
+ "quant_state": {
1666
+ "bits": 2,
1667
+ "code_count": 4194304,
1668
+ "group_size": 64,
1669
+ "inner": 1024,
1670
+ "n_groups": 16,
1671
+ "original_shape": [
1672
+ 4096,
1673
+ 1024
1674
+ ],
1675
+ "padded_inner": 1024,
1676
+ "qmax": 1,
1677
+ "rows": 4096
1678
+ }
1679
+ },
1680
+ {
1681
+ "activation_bits": null,
1682
+ "kind": "linear",
1683
+ "name": "encoder.blocks.21.mlp.lin2",
1684
+ "quant_state": {
1685
+ "bits": 2,
1686
+ "code_count": 4194304,
1687
+ "group_size": 64,
1688
+ "inner": 4096,
1689
+ "n_groups": 64,
1690
+ "original_shape": [
1691
+ 1024,
1692
+ 4096
1693
+ ],
1694
+ "padded_inner": 4096,
1695
+ "qmax": 1,
1696
+ "rows": 1024
1697
+ }
1698
+ },
1699
+ {
1700
+ "activation_bits": null,
1701
+ "kind": "linear",
1702
+ "name": "encoder.blocks.22.attn.qkv",
1703
+ "quant_state": {
1704
+ "bits": 2,
1705
+ "code_count": 3145728,
1706
+ "group_size": 64,
1707
+ "inner": 1024,
1708
+ "n_groups": 16,
1709
+ "original_shape": [
1710
+ 3072,
1711
+ 1024
1712
+ ],
1713
+ "padded_inner": 1024,
1714
+ "qmax": 1,
1715
+ "rows": 3072
1716
+ }
1717
+ },
1718
+ {
1719
+ "activation_bits": null,
1720
+ "kind": "linear",
1721
+ "name": "encoder.blocks.22.attn.proj",
1722
+ "quant_state": {
1723
+ "bits": 2,
1724
+ "code_count": 1048576,
1725
+ "group_size": 64,
1726
+ "inner": 1024,
1727
+ "n_groups": 16,
1728
+ "original_shape": [
1729
+ 1024,
1730
+ 1024
1731
+ ],
1732
+ "padded_inner": 1024,
1733
+ "qmax": 1,
1734
+ "rows": 1024
1735
+ }
1736
+ },
1737
+ {
1738
+ "activation_bits": null,
1739
+ "kind": "linear",
1740
+ "name": "encoder.blocks.22.mlp.lin1",
1741
+ "quant_state": {
1742
+ "bits": 2,
1743
+ "code_count": 4194304,
1744
+ "group_size": 64,
1745
+ "inner": 1024,
1746
+ "n_groups": 16,
1747
+ "original_shape": [
1748
+ 4096,
1749
+ 1024
1750
+ ],
1751
+ "padded_inner": 1024,
1752
+ "qmax": 1,
1753
+ "rows": 4096
1754
+ }
1755
+ },
1756
+ {
1757
+ "activation_bits": null,
1758
+ "kind": "linear",
1759
+ "name": "encoder.blocks.22.mlp.lin2",
1760
+ "quant_state": {
1761
+ "bits": 2,
1762
+ "code_count": 4194304,
1763
+ "group_size": 64,
1764
+ "inner": 4096,
1765
+ "n_groups": 64,
1766
+ "original_shape": [
1767
+ 1024,
1768
+ 4096
1769
+ ],
1770
+ "padded_inner": 4096,
1771
+ "qmax": 1,
1772
+ "rows": 1024
1773
+ }
1774
+ },
1775
+ {
1776
+ "activation_bits": null,
1777
+ "kind": "linear",
1778
+ "name": "encoder.blocks.23.attn.qkv",
1779
+ "quant_state": {
1780
+ "bits": 2,
1781
+ "code_count": 3145728,
1782
+ "group_size": 64,
1783
+ "inner": 1024,
1784
+ "n_groups": 16,
1785
+ "original_shape": [
1786
+ 3072,
1787
+ 1024
1788
+ ],
1789
+ "padded_inner": 1024,
1790
+ "qmax": 1,
1791
+ "rows": 3072
1792
+ }
1793
+ },
1794
+ {
1795
+ "activation_bits": null,
1796
+ "kind": "linear",
1797
+ "name": "encoder.blocks.23.attn.proj",
1798
+ "quant_state": {
1799
+ "bits": 2,
1800
+ "code_count": 1048576,
1801
+ "group_size": 64,
1802
+ "inner": 1024,
1803
+ "n_groups": 16,
1804
+ "original_shape": [
1805
+ 1024,
1806
+ 1024
1807
+ ],
1808
+ "padded_inner": 1024,
1809
+ "qmax": 1,
1810
+ "rows": 1024
1811
+ }
1812
+ },
1813
+ {
1814
+ "activation_bits": null,
1815
+ "kind": "linear",
1816
+ "name": "encoder.blocks.23.mlp.lin1",
1817
+ "quant_state": {
1818
+ "bits": 2,
1819
+ "code_count": 4194304,
1820
+ "group_size": 64,
1821
+ "inner": 1024,
1822
+ "n_groups": 16,
1823
+ "original_shape": [
1824
+ 4096,
1825
+ 1024
1826
+ ],
1827
+ "padded_inner": 1024,
1828
+ "qmax": 1,
1829
+ "rows": 4096
1830
+ }
1831
+ },
1832
+ {
1833
+ "activation_bits": null,
1834
+ "kind": "linear",
1835
+ "name": "encoder.blocks.23.mlp.lin2",
1836
+ "quant_state": {
1837
+ "bits": 2,
1838
+ "code_count": 4194304,
1839
+ "group_size": 64,
1840
+ "inner": 4096,
1841
+ "n_groups": 64,
1842
+ "original_shape": [
1843
+ 1024,
1844
+ 4096
1845
+ ],
1846
+ "padded_inner": 4096,
1847
+ "qmax": 1,
1848
+ "rows": 1024
1849
+ }
1850
+ },
1851
+ {
1852
+ "activation_bits": null,
1853
+ "kind": "conv2d",
1854
+ "name": "encoder.neck.0",
1855
+ "quant_state": {
1856
+ "bits": 2,
1857
+ "code_count": 262144,
1858
+ "group_size": 64,
1859
+ "inner": 1024,
1860
+ "n_groups": 16,
1861
+ "original_shape": [
1862
+ 256,
1863
+ 1024,
1864
+ 1,
1865
+ 1
1866
+ ],
1867
+ "padded_inner": 1024,
1868
+ "qmax": 1,
1869
+ "rows": 256
1870
+ }
1871
+ },
1872
+ {
1873
+ "activation_bits": null,
1874
+ "kind": "conv2d",
1875
+ "name": "encoder.neck.2",
1876
+ "quant_state": {
1877
+ "bits": 2,
1878
+ "code_count": 589824,
1879
+ "group_size": 64,
1880
+ "inner": 2304,
1881
+ "n_groups": 36,
1882
+ "original_shape": [
1883
+ 256,
1884
+ 256,
1885
+ 3,
1886
+ 3
1887
+ ],
1888
+ "padded_inner": 2304,
1889
+ "qmax": 1,
1890
+ "rows": 256
1891
+ }
1892
+ },
1893
+ {
1894
+ "activation_bits": null,
1895
+ "kind": "conv2d",
1896
+ "name": "out",
1897
+ "quant_state": {
1898
+ "bits": 2,
1899
+ "code_count": 49152,
1900
+ "group_size": 64,
1901
+ "inner": 256,
1902
+ "n_groups": 4,
1903
+ "original_shape": [
1904
+ 192,
1905
+ 256,
1906
+ 1,
1907
+ 1
1908
+ ],
1909
+ "padded_inner": 256,
1910
+ "qmax": 1,
1911
+ "rows": 192
1912
+ }
1913
+ }
1914
+ ],
1915
+ "weights": {
1916
+ "bytes": 100926616,
1917
+ "file": "model.safetensors",
1918
+ "sha256": "edae03a6cacce60ad6e3078a50febdd306ffb3f717041d8c059c373cf236d6d2",
1919
+ "tensor_count": 450
1920
+ }
1921
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:edae03a6cacce60ad6e3078a50febdd306ffb3f717041d8c059c373cf236d6d2
3
+ size 100926616
model_registry.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "scheme": "W2A16-G64",
3
+ "path": "models/W2A16-G64",
4
+ "weights_bytes": 100926616,
5
+ "sha256": "edae03a6cacce60ad6e3078a50febdd306ffb3f717041d8c059c373cf236d6d2",
6
+ "verified": true,
7
+ "verification_normalized_rmse": 0.0,
8
+ "public_output_files": 20
9
+ }
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ cellpose>=4.2.1.1
2
+ huggingface_hub>=0.24
3
+ safetensors>=0.4
4
+ torch
results.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "all_datasets_covered": true,
3
+ "paired_samples": 20,
4
+ "f1_CIs_above_margin": false,
5
+ "all_strict_endpoint_CIs_above_margin": false,
6
+ "catastrophic_rate": 0.85,
7
+ "bounded_panel_claim_supported": false,
8
+ "replaced_operators": 100.0,
9
+ "model_storage_mib": 96.20679473876953,
10
+ "fp32_storage_mib": 1162.0671463012695,
11
+ "compression_ratio": 12.078846919873303,
12
+ "build_seconds": 0.35267456097062677
13
+ }
runtime_loader.py ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Runtime-only loader for Capicu's quantized Cellpose-SAM exports."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import hashlib
6
+ import json
7
+ from pathlib import Path
8
+
9
+ import torch
10
+ import torch.nn.functional as F
11
+ from huggingface_hub import snapshot_download
12
+ from safetensors.torch import load_file
13
+ from torch import nn
14
+
15
+ REPO_ID = "capicu-ai/cellpose-sam-wquant-w2a16-g64"
16
+
17
+
18
+ def _digest(path: Path) -> str:
19
+ value = hashlib.sha256()
20
+ with path.open("rb") as handle:
21
+ for block in iter(lambda: handle.read(8 * 1024 * 1024), b""):
22
+ value.update(block)
23
+ return value.hexdigest()
24
+
25
+
26
+ def _restore(packed: torch.Tensor, scales: torch.Tensor, state: dict, device):
27
+ bits = int(state["bits"])
28
+ per_byte = 8 // bits
29
+ packed = packed.to(device=device, dtype=torch.uint8).flatten()
30
+ mask = (1 << bits) - 1
31
+ codes = torch.stack(
32
+ [(packed >> (index * bits)) & mask for index in range(per_byte)],
33
+ dim=1,
34
+ ).flatten()[: int(state["code_count"])]
35
+ signed = codes.to(torch.int16) - int(state["qmax"])
36
+ grouped = signed.reshape(
37
+ int(state["rows"]),
38
+ int(state["n_groups"]),
39
+ int(state["group_size"]),
40
+ )
41
+ restored = grouped.float() * scales.to(device).unsqueeze(-1)
42
+ restored = restored.reshape(int(state["rows"]), int(state["padded_inner"]))
43
+ return restored[..., : int(state["inner"])].reshape(state["original_shape"])
44
+
45
+
46
+ def _activation(tensor: torch.Tensor, bits: int | None) -> torch.Tensor:
47
+ if bits is None:
48
+ return tensor
49
+ qmax = (1 << (bits - 1)) - 1
50
+ scale = tensor.detach().abs().amax().clamp_min(1e-12) / qmax
51
+ return torch.round(tensor / scale).clamp(-qmax, qmax) * scale
52
+
53
+
54
+ class _Packed(nn.Module):
55
+ def _setup(self, packed, scales, bias, state, activation_bits):
56
+ self.register_buffer("packed_weight", packed.cpu())
57
+ self.register_buffer("weight_scales", scales.cpu())
58
+ self.register_buffer("bias", None if bias is None else bias.cpu())
59
+ self.state = state
60
+ self.activation_bits = activation_bits
61
+
62
+ def _weight(self, tensor):
63
+ return _restore(
64
+ self.packed_weight,
65
+ self.weight_scales,
66
+ self.state,
67
+ tensor.device,
68
+ ).to(dtype=tensor.dtype)
69
+
70
+
71
+ class _Linear(_Packed):
72
+ def __init__(self, source, **payload):
73
+ super().__init__()
74
+ self.in_features = source.in_features
75
+ self.out_features = source.out_features
76
+ self._setup(**payload)
77
+
78
+ def forward(self, tensor):
79
+ tensor = _activation(tensor, self.activation_bits)
80
+ bias = None if self.bias is None else self.bias.to(tensor.device, tensor.dtype)
81
+ return F.linear(tensor, self._weight(tensor), bias)
82
+
83
+
84
+ class _Conv2d(_Packed):
85
+ def __init__(self, source, **payload):
86
+ super().__init__()
87
+ self.stride = source.stride
88
+ self.padding = source.padding
89
+ self.dilation = source.dilation
90
+ self.groups = source.groups
91
+ self._setup(**payload)
92
+
93
+ def forward(self, tensor):
94
+ tensor = _activation(tensor, self.activation_bits)
95
+ bias = None if self.bias is None else self.bias.to(tensor.device, tensor.dtype)
96
+ return F.conv2d(
97
+ tensor,
98
+ self._weight(tensor),
99
+ bias,
100
+ self.stride,
101
+ self.padding,
102
+ self.dilation,
103
+ self.groups,
104
+ )
105
+
106
+
107
+ def _replace(root: nn.Module, name: str, module: nn.Module) -> None:
108
+ parent_name, _, child_name = name.rpartition(".")
109
+ parent = root.get_submodule(parent_name) if parent_name else root
110
+ if child_name.isdigit() and isinstance(parent, (nn.Sequential, nn.ModuleList)):
111
+ parent[int(child_name)] = module
112
+ else:
113
+ setattr(parent, child_name, module)
114
+
115
+
116
+ def load_model(
117
+ device: str | torch.device = "cpu",
118
+ local_repo: str | Path | None = None,
119
+ ):
120
+ """Download and load the ready-to-run quantized Cellpose-SAM model."""
121
+ root = (
122
+ Path(local_repo)
123
+ if local_repo is not None
124
+ else Path(
125
+ snapshot_download(
126
+ REPO_ID,
127
+ allow_patterns=[
128
+ "config.json",
129
+ "model.safetensors",
130
+ ],
131
+ )
132
+ )
133
+ )
134
+ manifest = json.loads((root / "config.json").read_text())
135
+ weights_path = root / "model.safetensors"
136
+ if _digest(weights_path) != manifest["weights"]["sha256"]:
137
+ raise ValueError("model checksum mismatch")
138
+
139
+ from cellpose import models as cellpose_models
140
+
141
+ target = torch.device(device)
142
+ model = cellpose_models.CellposeModel(
143
+ gpu=target.type == "cuda",
144
+ pretrained_model=manifest["base_model"],
145
+ device=target,
146
+ use_bfloat16=False,
147
+ )
148
+ state = load_file(str(weights_path), device="cpu")
149
+ network = model.net.cpu().eval()
150
+ for item in manifest["replacements"]:
151
+ name = item["name"]
152
+ source = network.get_submodule(name)
153
+ prefix = f"{name}."
154
+ payload = {
155
+ "packed": state[f"{prefix}packed_weight"],
156
+ "scales": state[f"{prefix}weight_scales"],
157
+ "bias": state.get(f"{prefix}bias"),
158
+ "state": item["quant_state"],
159
+ "activation_bits": item.get("activation_bits"),
160
+ }
161
+ replacement = (
162
+ _Linear(source, **payload)
163
+ if item["kind"] == "linear"
164
+ else _Conv2d(source, **payload)
165
+ )
166
+ _replace(network, name, replacement)
167
+ network.load_state_dict(state, strict=True)
168
+ model.net = network.to(target).eval()
169
+ return model