Repository navigation
Expand file tree
/
Copy pathdownload_model.sh
More file actions
executable file
·821 lines (743 loc) · 28.4 KB
/
Copy pathdownload_model.sh
File metadata and controls
executable file
·821 lines (743 loc) · 28.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
#!/bin/sh
set -e
GLM_UNSLOTH_REPO="unsloth/GLM-5.2-GGUF"
GLM_ANTIREZ_REPO="antirez/GLM-5.2-GGUF"
GLM53_REPO="antirez/glm-5.3-flash-gguf"
GLM53_FULL_REPO="antirez/glm-5.3-gguf"
QWEN38_REPO="antirez/qwen3.8-flash-next-gguf"
QWEN38_MMPROJ_REPO="ggml-org/Qwen3.8-Flash-Next-GGUF"
REPO="antirez/deepseek-v4-gguf"
DS41_REPO="antirez/deepseek-v4.1-flash-gguf"
DS41_Q2_FILE="DeepSeek-V4.1-Flash-1017-IQ2_XXS-Q2_K-imatrix.gguf"
DS41_Q4_FILE="DeepSeek-V4.1-Flash-Q4.gguf"
DS41_MXFP4_BASE="DeepSeek-V4.1-Flash-1017-MXFP4-experts"
DS41_VISION_FILE="DeepSeek-V4.1-Flash-Vision.gguf"
DS4F_Q2_FILE="DeepSeek-V4-Flash-IQ2XXS-w2Q2K-AProjQ8-SExpQ8-OutQ8-chat-v2-imatrix-0731.gguf"
DS4F_Q4_FILE="DeepSeek-V4-Flash-Q4KExperts-F16HC-F16Compressor-F16Indexer-Q8Attn-Q8Shared-Q8Out-chat-v2-imatrix-0731.gguf"
DS4F_MXFP4_FILE="DeepSeek-V4-Flash-MXFP4Experts-F16HC-F16Compressor-F16Indexer-Q8Attn-Q8Shared-Q8Out-chat-v2-mxfp4-0731.gguf"
DS4F_Q2_Q4_FILE="DeepSeek-V4-Flash-Layers37-42Q4KExperts-OtherExpertLayersIQ2XXSGateUp-Q2KDown-AProjQ8-SExpQ8-OutQ8-chat-v2-imatrix-fixed-0731.gguf"
PRO_Q2_IMATRIX_FILE="DeepSeek-V4-Pro-IQ2XXS-w2Q2K-AProjQ8-SExpQ8-OutQ8-Instruct-imatrix-0813.gguf"
PRO_Q4_LAYERS00_30_FILE="DeepSeek-V4-Pro-Q4K-Layers00-30.gguf"
PRO_Q4_LAYERS31_OUTPUT_FILE="DeepSeek-V4-Pro-Q4K-Layers-31-output.gguf"
DS4F_DSPARK_FILE="DeepSeek-V4-Flash-DSpark-support-0731.gguf"
DS4F_VISION_Q2_FILE="DeepSeek-V4-Flash-Vision-Exp-IQ2XXS-w2Q2K-AProjQ8-SExpQ8-OutQ8.gguf"
DS4F_VISION_Q2_Q4_FILE="DeepSeek-V4-Flash-Vision-Exp-Layers37-42Q4KExperts-OtherExpertLayersIQ2XXSGateUp-Q2KDown-AProjQ8-SExpQ8-OutQ8.gguf"
DS4F_VISION_MXFP4_FILE="DeepSeek-V4-Flash-Vision-Exp-MXFP4Experts-F16HC-F16Compressor-F16Indexer-Q8Attn-Q8Shared-Q8Out.gguf"
DS4F_VISION_ENCODER_FILE="DeepSeek-V4-Flash-Vision-Encoder.gguf"
DS4F_VISION_DSPARK_FILE="DeepSeek-V4-Flash-Vision-Exp-DSpark-support.gguf"
GLM_UNSLOTH_Q4_REMOTE_BASE="UD-Q4_K_XL/GLM-5.2-UD-Q4_K_XL"
GLM_UNSLOTH_Q4_LOCAL_BASE="GLM-5.2-UD-Q4_K_XL"
GLM_UNSLOTH_Q4_FIRST_FILE="$GLM_UNSLOTH_Q4_LOCAL_BASE-00001-of-00011.gguf"
GLM_ANTIREZ_IQ2XXS_FILE="GLM-5.2-UD-IQ2_XXS_RoutedIQ2XXS_blk78Q2K.gguf"
GLM_ANTIREZ_Q2_FILE="GLM-5.2-UD-Q2_K_RoutedQ2K.gguf"
GLM_ANTIREZ_Q4_FILE="GLM-5.2-UD-Q4_K_RoutedQ4K.gguf"
GLM53_FULL_Q2_FILE="GLM-5.3-UD-IQ2_XXS_RoutedIQ2XXS_blk78Q2K.gguf"
GLM53_Q2_FILE="GLM-5.3-Flash-Q2.gguf"
GLM53_Q4_FILE="GLM-5.3-Flash-Q4_K.gguf"
GLM53_FP8_FILE="GLM-5.3-Flash-FP8.gguf"
GLM53_VISION_FILE="GLM-5.3-Flash-Vision-Encoder.gguf"
QWEN38_Q4_FILE="Qwen3.8-Flash-Next-Q4.gguf"
QWEN38_Q2_FILE="Qwen3.8-Flash-Next-Q2.gguf"
QWEN38_VISION_FILE="mmproj-Qwen3.8-Flash-Next-Q8_0.gguf"
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
OUT_DIR=${DS4_GGUF_DIR:-"$ROOT/gguf"}
case "$OUT_DIR" in
/*) ;;
*) OUT_DIR="$ROOT/$OUT_DIR" ;;
esac
TOKEN=${HF_TOKEN:-}
usage() {
cat <<EOF
DwarfStar GGUF downloader
Usage:
./download_model.sh ds4f-q2 [--token TOKEN]
./download_model.sh ds4f-q2-q4 [--token TOKEN]
./download_model.sh ds4f-q4 [--token TOKEN]
./download_model.sh ds4f-mxfp4 [--token TOKEN]
./download_model.sh ds4f-dspark [--token TOKEN]
./download_model.sh ds4f-vision-q2 [--token TOKEN]
./download_model.sh ds4f-vision-q2-q4 [--token TOKEN]
./download_model.sh ds4f-vision-mxfp4 [--token TOKEN]
./download_model.sh ds4f-vision-encoder [--token TOKEN]
./download_model.sh ds4f-vision-dspark [--token TOKEN]
./download_model.sh ds41f-q2 [--token TOKEN]
./download_model.sh ds41f-q4 [--token TOKEN]
./download_model.sh ds41f-mxfp4 [--token TOKEN]
./download_model.sh ds41f-vision [--token TOKEN]
./download_model.sh pro-q2-imatrix [--token TOKEN]
./download_model.sh pro-q4-layers00-30 [--token TOKEN]
./download_model.sh pro-q4-layers31-output [--token TOKEN]
./download_model.sh pro-q4-split [--token TOKEN]
./download_model.sh glm-unsloth-q4 [--token TOKEN]
./download_model.sh glm-antirez-iq2xxs [--token TOKEN]
./download_model.sh glm-antirez-q2 [--token TOKEN]
./download_model.sh glm-antirez-q4 [--token TOKEN]
./download_model.sh glm53-full-q2 [--token TOKEN]
./download_model.sh glm53-q2 [--token TOKEN]
./download_model.sh glm53-q4 [--token TOKEN]
./download_model.sh glm53-fp8 [--token TOKEN]
./download_model.sh glm53-vision [--token TOKEN]
./download_model.sh qwen38-q2 [--token TOKEN]
./download_model.sh qwen38-q4k [--token TOKEN]
./download_model.sh qwen38-vision [--token TOKEN]
Targets:
ds4f-q2
2-bit routed experts, about 81 GB on disk.
Recommended model for 96 and 128 GB RAM machines.
ds4f-q2-q4
Mixed Flash quant: mostly q2 routed experts, with the last 6 layers
using q4 routed experts. About 98 GB on disk. Good for higher
quality inference for 128 GB MacBooks. Works on DGX Spark but loading
may struggle compared to ds4f-q2.
ds4f-q4
4-bit routed experts, about 153 GB on disk.
Recommended model for machines with 256 GB RAM or more.
ds4f-mxfp4
Native DeepSeek V4 Flash MXFP4 routed experts, about 156 GB on disk.
Supported by Metal and CUDA; Blackwell uses FP4 tensor cores for batched
expert work, while CUDA decode keeps Q8 activations.
ds4f-dspark
Optional DSpark speculative decoding support GGUF for Flash 0731, about
6 GB. Enable it with --dspark and --mtp-model when running ds4 or ds4-server.
ds4f-vision-q2
DeepSeek V4 Flash Vision Experimental with 2-bit routed experts, about
81 GiB, plus its vision encoder. Recommended for 96 and 128 GB Macs.
ds4f-vision-q2-q4
Mixed Vision Experimental quant with routed experts in layers 37-42 at
Q4_K and the others at 2 bits, about 91 GiB, plus its vision encoder.
ds4f-vision-mxfp4
Native MXFP4 Vision Experimental model, about 145 GiB, plus its vision
encoder. Intended for CUDA or two 128 GB Macs using tensor parallelism.
ds4f-vision-encoder
Standalone Vision Experimental encoder, about 0.9 GiB. Use this when
the matching language GGUF is already present.
ds4f-vision-dspark
Matching DSpark speculative decoding support for Vision Experimental,
about 5.6 GiB. It is not compatible with the 0731 language checkpoint.
ds41f-q2
DeepSeek V4.1 Flash calibrated Q2, about 341 GiB on disk. Main weights
occupy 152 GiB; Engram tables stay on disk. Metal only: use SSD streaming
on one 128 GB Mac, tensor parallelism on two, or a larger resident Mac.
ds41f-vision
Matching V4.1 Flash vision encoder, about 0.9 GiB. Add --vision FILE
to the language-model command. Does not update ./ds4flash.gguf.
ds41f-q4
DeepSeek V4.1 Flash calibrated Q4, about 483 GiB on disk. Main weights
occupy 294 GiB; Engram tables stay on disk. Metal only: use SSD streaming
on smaller Macs or full residency on a 512 GB Mac. Downloads two parts
and joins them automatically; allow another 37 GiB of free disk space.
ds41f-mxfp4
DeepSeek V4.1 Flash 1017 MXFP4 routed experts, about 467 GiB on disk.
Downloads and verifies all nine GGUF shards, then restores the original
page-aligned GGUF for DwarfStar. Retains the shards: allow about 935 GiB
of disk space for shards plus output. Downloads and merging can resume.
pro-q2-imatrix
DeepSeek V4 PRO 0813 q2 imatrix quant, as a single GGUF file. About
430 GB on disk; intended for 512 GB RAM machines.
pro-q4-layers00-30
First half of the DeepSeek V4 PRO Q4 routed-expert quant, layers 0..30.
Use on the coordinator in a two-Mac-Studio distributed run. About 426 GB.
pro-q4-layers31-output
Second half of the DeepSeek V4 PRO Q4 routed-expert quant, layers
31..output. Use on the worker in a two-Mac-Studio distributed run.
About 412 GB.
pro-q4-split
Downloads both PRO Q4 split files into the download directory. About
838 GB total. This target does not update ./ds4flash.gguf.
glm-unsloth-q4
GLM 5.2 Unsloth UD-Q4_K_XL quant from unsloth/GLM-5.2-GGUF.
Downloads all 11 shards and links ./ds4flash.gguf to the first shard.
glm-antirez-iq2xxs
GLM 5.2 antirez routed IQ2_XXS GGUF from antirez/GLM-5.2-GGUF.
Includes Q2_K block 78 and is intended for reduced-memory testing.
glm-antirez-q2
GLM 5.2 antirez routed Q2_K GGUF from antirez/GLM-5.2-GGUF.
About 262 GB on disk.
glm-antirez-q4
GLM 5.2 antirez routed Q4_K GGUF from antirez/GLM-5.2-GGUF.
About 434 GB on disk.
glm53-full-q2
Full GLM 5.3 routed IQ2_XXS/Q2_K GGUF, about 197 GiB on disk.
Intended for 256 GB machines or SSD streaming on smaller systems.
glm53-q2
GLM 5.3 Flash imatrix Q2 GGUF, about 90 GiB on disk. Intended for
resident inference on 128 GB Macs.
glm53-q4
GLM 5.3 Flash Q4_K GGUF, about 178 GiB on disk. Intended for two-Mac
tensor parallelism or single-Mac SSD streaming.
glm53-fp8
Text-only GLM 5.3 Flash native FP8 GGUF, about 305 GiB on disk. It
preserves the released weights without requantization. DwarfStar
inference support for this paired FP8-code/scale format is pending.
glm53-vision
GLM 5.3 Flash vision encoder, about 1.1 GB on disk. Load it separately
with --vision; this target does not update ./ds4flash.gguf.
qwen38-q2 (alias: qwen38-iq2)
Qwen3.8-Flash-Next Q2: one 137.10 GiB GGUF. Main/MTP weights
occupy 41.73 GiB; original BF16 n-grams stay on disk.
Imatrix IQ2_XXS gate/up and Q2_K down experts (640 logical inputs,
padded to 768 on disk), with higher-precision dense/control tensors.
Smaller option for 64 GB Macs: start with --ctx 8192 and
--prefill-chunk 1024. Context buffers need additional RAM.
Keep the file on a local SSD. Add --mtp for speculation.
qwen38-q4k
Qwen3.8-Flash-Next Q4: one 165.11 GiB GGUF. Main/MTP weights
occupy 69.74 GiB; original BF16 n-grams stay on disk.
Imatrix Q4_K gate/up and MXFP4 down routed experts. Fits 128 GB
Macs with room for context buffers. Add --mtp for speculation.
qwen38-vision
Qwen3.8-Flash-Next vision encoder, about 0.6 GB on disk. Load it
with --vision; this target does not update ./ds4flash.gguf.
Options:
--token TOKEN Hugging Face token. Otherwise HF_TOKEN or the local HF token
cache is used if present.
Environment:
DS4_GGUF_DIR Directory used for downloaded GGUF files.
Default: ./gguf
After main-model downloads the script updates:
./ds4flash.gguf -> <download directory>/<selected model>
Then the default commands work:
./ds4 -p "Hello"
./ds4-server --ctx 100000
Qwen3.8 includes its n-grams and MTP; add --mtp to enable speculation:
./ds4 --mtp
After downloading DSpark support, enable it explicitly:
./ds4 --dspark --mtp-model <download directory>/$DS4F_DSPARK_FILE
PRO, V4.1, GLM and Qwen files use the official Hugging Face downloader
because they are too large, sharded, or nested for the curl path used by the
smaller DeepSeek Flash GGUF files.
EOF
}
if [ $# -eq 0 ]; then
usage
exit 1
fi
MODEL=$1
shift
MODEL_FILES=
LINK_MODEL=1
FORCE_HF_DOWNLOAD=0
FLATTEN_DOWNLOADS=0
case "$MODEL" in
ds4f-q2) MODEL_FILE=$DS4F_Q2_FILE ;;
ds4f-q2-q4) MODEL_FILE=$DS4F_Q2_Q4_FILE ;;
ds4f-q4) MODEL_FILE=$DS4F_Q4_FILE ;;
ds4f-mxfp4) MODEL_FILE=$DS4F_MXFP4_FILE; FORCE_HF_DOWNLOAD=1 ;;
ds4f-dspark) MODEL_FILE=$DS4F_DSPARK_FILE; LINK_MODEL=0 ;;
ds4f-vision-q2)
MODEL_FILE=$DS4F_VISION_Q2_FILE
MODEL_FILES="$MODEL_FILE $DS4F_VISION_ENCODER_FILE"
FORCE_HF_DOWNLOAD=1
;;
ds4f-vision-q2-q4)
MODEL_FILE=$DS4F_VISION_Q2_Q4_FILE
MODEL_FILES="$MODEL_FILE $DS4F_VISION_ENCODER_FILE"
FORCE_HF_DOWNLOAD=1
;;
ds4f-vision-mxfp4)
MODEL_FILE=$DS4F_VISION_MXFP4_FILE
MODEL_FILES="$MODEL_FILE $DS4F_VISION_ENCODER_FILE"
FORCE_HF_DOWNLOAD=1
;;
ds4f-vision-encoder)
MODEL_FILE=$DS4F_VISION_ENCODER_FILE
FORCE_HF_DOWNLOAD=1
LINK_MODEL=0
;;
ds4f-vision-dspark)
MODEL_FILE=$DS4F_VISION_DSPARK_FILE
FORCE_HF_DOWNLOAD=1
LINK_MODEL=0
;;
ds41f-q2)
REPO=$DS41_REPO
MODEL_FILE=$DS41_Q2_FILE
FORCE_HF_DOWNLOAD=1
;;
ds41f-q4)
REPO=$DS41_REPO
MODEL_FILE=$DS41_Q4_FILE
FORCE_HF_DOWNLOAD=1
;;
ds41f-mxfp4)
REPO=$DS41_REPO
MODEL_FILE="$DS41_MXFP4_BASE.gguf"
for part in 00001 00002 00003 00004 00005 00006 00007 00008 00009; do
MODEL_FILES="$MODEL_FILES $DS41_MXFP4_BASE-${part}-of-00009.gguf"
done
FORCE_HF_DOWNLOAD=1
;;
ds41f-vision)
REPO=$DS41_REPO
MODEL_FILE=$DS41_VISION_FILE
FORCE_HF_DOWNLOAD=1
LINK_MODEL=0
;;
pro-q2-imatrix) MODEL_FILE=$PRO_Q2_IMATRIX_FILE ;;
pro-q4-layers00-30) MODEL_FILE=$PRO_Q4_LAYERS00_30_FILE; LINK_MODEL=0 ;;
pro-q4-layers31-output) MODEL_FILE=$PRO_Q4_LAYERS31_OUTPUT_FILE; LINK_MODEL=0 ;;
pro-q4-split)
MODEL_FILES="$PRO_Q4_LAYERS00_30_FILE $PRO_Q4_LAYERS31_OUTPUT_FILE"
LINK_MODEL=0
;;
glm-unsloth-q4)
REPO=$GLM_UNSLOTH_REPO
MODEL_FILE=$GLM_UNSLOTH_Q4_FIRST_FILE
MODEL_FILES=
for part in 00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011; do
MODEL_FILES="$MODEL_FILES $GLM_UNSLOTH_Q4_REMOTE_BASE-${part}-of-00011.gguf"
done
FORCE_HF_DOWNLOAD=1
FLATTEN_DOWNLOADS=1
;;
glm-antirez-q2)
REPO=$GLM_ANTIREZ_REPO
MODEL_FILE=$GLM_ANTIREZ_Q2_FILE
FORCE_HF_DOWNLOAD=1
;;
glm-antirez-iq2xxs)
REPO=$GLM_ANTIREZ_REPO
MODEL_FILE=$GLM_ANTIREZ_IQ2XXS_FILE
FORCE_HF_DOWNLOAD=1
;;
glm-antirez-q4)
REPO=$GLM_ANTIREZ_REPO
MODEL_FILE=$GLM_ANTIREZ_Q4_FILE
FORCE_HF_DOWNLOAD=1
;;
glm53-full-q2)
REPO=$GLM53_FULL_REPO
MODEL_FILE=$GLM53_FULL_Q2_FILE
FORCE_HF_DOWNLOAD=1
;;
glm53-q2)
REPO=$GLM53_REPO
MODEL_FILE=$GLM53_Q2_FILE
FORCE_HF_DOWNLOAD=1
;;
glm53-q4)
REPO=$GLM53_REPO
MODEL_FILE=$GLM53_Q4_FILE
FORCE_HF_DOWNLOAD=1
;;
glm53-fp8)
REPO=$GLM53_REPO
MODEL_FILE=$GLM53_FP8_FILE
FORCE_HF_DOWNLOAD=1
LINK_MODEL=0
;;
glm53-vision)
REPO=$GLM53_REPO
MODEL_FILE=$GLM53_VISION_FILE
FORCE_HF_DOWNLOAD=1
LINK_MODEL=0
;;
qwen38-q2|qwen38-iq2)
REPO=$QWEN38_REPO
MODEL_FILE=$QWEN38_Q2_FILE
FORCE_HF_DOWNLOAD=1
;;
qwen38-q4k)
REPO=$QWEN38_REPO
MODEL_FILE=$QWEN38_Q4_FILE
FORCE_HF_DOWNLOAD=1
;;
qwen38-vision)
REPO=$QWEN38_MMPROJ_REPO
MODEL_FILE=$QWEN38_VISION_FILE
FORCE_HF_DOWNLOAD=1
LINK_MODEL=0
;;
-h|--help|help)
usage
exit 0
;;
*)
echo "Unknown model: $MODEL" >&2
echo >&2
usage >&2
exit 1
;;
esac
while [ $# -gt 0 ]; do
case "$1" in
--token)
shift
if [ $# -eq 0 ]; then
echo "Missing value after --token" >&2
exit 1
fi
TOKEN=$1
;;
*)
echo "Unknown option: $1" >&2
exit 1
;;
esac
shift
done
if [ -z "$TOKEN" ] && [ -s "$HOME/.cache/huggingface/token" ]; then
TOKEN=$(cat "$HOME/.cache/huggingface/token")
fi
needs_hf_download() {
if [ "${FORCE_HF_DOWNLOAD:-0}" -eq 1 ]; then
return 0
fi
case "$1" in
"$PRO_Q2_IMATRIX_FILE"|"$PRO_Q4_LAYERS00_30_FILE"|"$PRO_Q4_LAYERS31_OUTPUT_FILE")
return 0
;;
*)
return 1
;;
esac
}
find_hf_command() {
if command -v hf >/dev/null 2>&1; then
printf '%s\n' hf
return 0
fi
for dir in "$HOME"/Library/Python/*/bin "$HOME"/.local/bin; do
if [ -x "$dir/hf" ]; then
printf '%s\n' "$dir/hf"
return 0
fi
done
return 1
}
local_download_name() {
if [ "${FLATTEN_DOWNLOADS:-0}" -eq 1 ]; then
basename "$1"
else
printf '%s\n' "$1"
fi
}
artifact_identity() {
case "$1" in
"$QWEN38_Q2_FILE")
expected_bytes=147207127040
expected_sha=b1b93fa69aca5f187b0fb813aca8f3ec1beb5cf8cf0bd38cf041b93e0b6ccac9
;;
"$QWEN38_Q4_FILE")
expected_bytes=177280286720
expected_sha=680944460a8cbe93ba8b6d7b6107213ffb7e22320bd913000e563ca0a0f25a8a
;;
"$DS41_Q2_FILE")
expected_bytes=365713686528
expected_sha=5296e85ff64b42ecb62c8d0c0c54e1caa07e3df8e93112f2365ebbaed62ce93a
;;
"$DS41_Q4_FILE")
expected_bytes=518596067328
expected_sha=a5e2e2c3ada4b2e98d9f9e4b50f6d9c2a12c2c96f5da165c07e13aff9264984e
;;
"$DS41_Q4_FILE.part1")
expected_bytes=480000000000
expected_sha=6442b1f9224079662c02003c0ef9ef6be6e2aff509510f681dab9e6cc41df246
;;
"$DS41_Q4_FILE.part2")
expected_bytes=38596067328
expected_sha=7c3e10646c918eeaffbc39305a75ec96117450262c61454ff194cef00d7617f0
;;
"$DS41_MXFP4_BASE.gguf")
expected_bytes=501609136128
expected_sha=79608a69cd5bb919d8140c37105edc3a33419692d4e6caf4e68c901e4b359141
;;
"$DS41_MXFP4_BASE-00001-of-00009.gguf")
expected_bytes=49353784544
expected_sha=636918b09de6253bf41af29f06aac3ceeda220e46379d8a2058ef92c4e433ed8
;;
"$DS41_MXFP4_BASE-00002-of-00009.gguf")
expected_bytes=49412635712
expected_sha=b26d3fc1e6ae1be6c52665542f3c1fee6a33791478f26e6cd90b5a75940a9f96
;;
"$DS41_MXFP4_BASE-00003-of-00009.gguf")
expected_bytes=49582960352
expected_sha=20c7fe7adb0578336d8a5e5f9eed521aeb88e8c119ba46e0916cdaab28931c80
;;
"$DS41_MXFP4_BASE-00004-of-00009.gguf")
expected_bytes=49418206432
expected_sha=67592ba15870c4292a615666adcc2736b53cc345b2cccb1c36710a0a6caf15b4
;;
"$DS41_MXFP4_BASE-00005-of-00009.gguf")
expected_bytes=49412829632
expected_sha=ecd04e0aa71bfab8cfe79ea7fef7f35b6be0b6772455139e2081d6ce1dcc18ed
;;
"$DS41_MXFP4_BASE-00006-of-00009.gguf")
expected_bytes=49257603776
expected_sha=88214e0cc80fbae578b80c114527e6ce725199684e0b6849475c7d00b3d0f54c
;;
"$DS41_MXFP4_BASE-00007-of-00009.gguf")
expected_bytes=2406482112
expected_sha=38939faf3e4258f3ae333f0fa1954ce89515b75ceee90d37bf4ebe5fafe285e6
;;
"$DS41_MXFP4_BASE-00008-of-00009.gguf")
expected_bytes=101377628544
expected_sha=a9d1634da2ac57459a64b10b69ddedfadda7dcde0e71ca6e55bea7c293c4a9f0
;;
"$DS41_MXFP4_BASE-00009-of-00009.gguf")
expected_bytes=101380404256
expected_sha=b9832b355288c005da6ef444d02424464dd27f6ebdefeadbec2244264eb65285
;;
"$DS41_VISION_FILE")
expected_bytes=970555552
expected_sha=cc283f032b3e8b8d78aeb5fccaa14e97b859b0c53aae3cd6bffa690ddf0e9e15
;;
*) return 1 ;;
esac
}
verify_download() {
artifact_identity "$1" || return 0
if [ "$(wc -c < "$2")" -ne "$expected_bytes" ]; then
echo "Incorrect file size: $2. Move the incomplete file aside and retry." >&2
exit 1
fi
echo "Verifying SHA-256: $2"
if command -v sha256sum >/dev/null 2>&1; then
actual_sha=$(sha256sum < "$2")
else
actual_sha=$(shasum -a 256 < "$2")
fi
actual_sha=${actual_sha%% *}
if [ "$actual_sha" != "$expected_sha" ]; then
echo "Checksum mismatch: $2. The file was not accepted." >&2
exit 1
fi
}
download_one_hf() {
file=$1
local_file=$(local_download_name "$file")
out="$OUT_DIR/$local_file"
hf_out="$OUT_DIR/$file"
part="$out.part"
mkdir -p "$(dirname "$out")"
if [ -s "$out" ]; then
verify_download "$file" "$out"
echo "Already downloaded: $out"
return
fi
if [ -e "$part" ]; then
echo "Found curl partial download: $part" >&2
echo "The Hugging Face downloader cannot resume curl .part files." >&2
echo "Move or remove that partial download before retrying this target." >&2
exit 1
fi
HF_CMD=$(find_hf_command || true)
if [ -z "$HF_CMD" ]; then
echo "Large GGUF downloads require the official Hugging Face CLI." >&2
echo "Install it with:" >&2
echo " python3 -m pip install -U huggingface_hub hf_xet" >&2
exit 1
fi
echo "Downloading $file"
echo "from https://huggingface.co/$REPO"
echo "using $HF_CMD download"
echo "If the download stops, run the same command again to resume it."
if [ -n "$TOKEN" ]; then
"$HF_CMD" download "$REPO" "$file" --repo-type model --local-dir "$OUT_DIR" --token "$TOKEN"
else
"$HF_CMD" download "$REPO" "$file" --repo-type model --local-dir "$OUT_DIR"
fi
if [ "$hf_out" != "$out" ] && [ -s "$hf_out" ]; then
mv "$hf_out" "$out"
rmdir "$(dirname "$hf_out")" 2>/dev/null || true
fi
if [ ! -s "$out" ]; then
echo "Hugging Face download finished but expected file is missing: $out" >&2
exit 1
fi
verify_download "$file" "$out"
}
download_one() {
file=$1
local_file=$(local_download_name "$file")
out="$OUT_DIR/$local_file"
part="$out.part"
aria2_part="$out.aria2"
url="https://huggingface.co/$REPO/resolve/main/$file"
if needs_hf_download "$file"; then
download_one_hf "$file"
return
fi
mkdir -p "$(dirname "$out")"
if [ -e "$aria2_part" ]; then
echo "Found incomplete aria2 download sidecar: $aria2_part" >&2
echo "Finish or remove that partial download before using this curl downloader." >&2
exit 1
fi
if [ -s "$out" ]; then
echo "Already downloaded: $out"
return
fi
echo "Downloading $file"
echo "from https://huggingface.co/$REPO"
echo "If the download stops, run the same command again to resume it."
if [ -n "$TOKEN" ]; then
curl -fL --progress-meter -C - -H "Authorization: Bearer $TOKEN" -o "$part" "$url"
else
curl -fL --progress-meter -C - -o "$part" "$url"
fi
mv "$part" "$out"
}
download_ds41_q4() {
q4_out="$OUT_DIR/$DS41_Q4_FILE"
if [ -e "$q4_out" ]; then
verify_download "$DS41_Q4_FILE" "$q4_out"
echo "Already downloaded: $q4_out"
return
fi
if ! command -v python3 >/dev/null 2>&1; then
echo "Joining the Q4 download requires Python 3." >&2
exit 1
fi
if [ ! -e "$q4_out.assembling" ]; then
download_one_hf "$DS41_Q4_FILE.part1"
fi
download_one_hf "$DS41_Q4_FILE.part2"
artifact_identity "$DS41_Q4_FILE"
q4_bytes=$expected_bytes
q4_sha=$expected_sha
artifact_identity "$DS41_Q4_FILE.part1"
python3 - "$q4_out" "$expected_bytes" "$q4_bytes" "$q4_sha" <<'PY'
import fcntl
import hashlib
import os
from pathlib import Path
import shutil
import sys
out = Path(sys.argv[1])
boundary, total = map(int, sys.argv[2:4])
expected = sys.argv[4]
first, second, pending = (Path(str(out) + suffix)
for suffix in (".part1", ".part2", ".assembling"))
def verify(path):
if path.stat().st_size != total:
sys.exit("Incorrect file size: " + str(path))
print("Verifying SHA-256: " + str(path), flush=True)
digest = hashlib.sha256()
with path.open("rb") as fp:
for block in iter(lambda: fp.read(16 << 20), b""):
digest.update(block)
if digest.hexdigest() != expected:
sys.exit("Checksum mismatch: " + str(path) +
". Move this file aside before retrying; it was not accepted.")
# Keep this lock file: unlinking it could allow two different locks for the
# same download. The first part becomes the output without a second full copy.
with Path(str(pending) + ".lock").open("a") as lock:
fcntl.flock(lock, fcntl.LOCK_EX)
if out.exists():
verify(out)
sys.exit(0)
if not pending.exists():
if first.stat().st_size != boundary:
sys.exit("Incorrect file size: " + str(first))
first.rename(pending)
size = pending.stat().st_size
if not boundary <= size <= total:
sys.exit("Invalid partial assembly: " + str(pending) +
". Move it aside before retrying.")
if second.stat().st_size != total - boundary:
sys.exit("Incorrect file size: " + str(second))
# An interrupted append restarts only the smaller tail, never the prefix.
with pending.open("r+b") as dst:
dst.truncate(boundary)
dst.seek(boundary)
if shutil.disk_usage(out.parent).free < total - boundary + (1 << 30):
sys.exit("Not enough disk space to join Q4; keep the parts and retry.")
print("Joining Q4 download parts", flush=True)
with second.open("rb") as src:
shutil.copyfileobj(src, dst, 16 << 20)
dst.flush()
os.fsync(dst.fileno())
verify(pending)
pending.rename(out)
second.unlink()
PY
}
download_ds41_mxfp4() {
mx_out="$OUT_DIR/$MODEL_FILE"
if [ -e "$mx_out" ]; then
verify_download "$MODEL_FILE" "$mx_out"
echo "Already downloaded: $mx_out"
return
fi
if ! command -v python3 >/dev/null 2>&1; then
echo "Merging the MXFP4 shards requires Python 3." >&2
exit 1
fi
if [ ! -f "$ROOT/gguf-tools/merge_deepseek41_shards.py" ]; then
echo "Missing gguf-tools/merge_deepseek41_shards.py; use a complete checkout." >&2
exit 1
fi
mkdir -p "$OUT_DIR"
artifact_identity "$MODEL_FILE"
mx_bytes=$expected_bytes
mx_sha=$expected_sha
set -- "$mx_out.assembling" "$mx_bytes"
for shard in $MODEL_FILES; do
artifact_identity "$shard"
set -- "$@" "$OUT_DIR/$shard" "$expected_bytes"
done
# Check peak storage before downloading hundreds of GB. Retain the input
# shards and account for a resumable output; HF partial caches are extra.
python3 - "$OUT_DIR" "$@" <<'PY'
from pathlib import Path
import shutil
import sys
needed = 1 << 30
for name, size in zip(sys.argv[2::2], sys.argv[3::2]):
path = Path(name)
needed += max(0, int(size) - (path.stat().st_size if path.exists() else 0))
if shutil.disk_usage(sys.argv[1]).free < needed:
sys.exit("Not enough disk space for MXFP4 shards and merged GGUF: "
f"need {needed / (1 << 30):.1f} GiB free. Existing files were kept.")
PY
set --
for shard in $MODEL_FILES; do
download_one_hf "$shard"
set -- "$@" "$OUT_DIR/$shard"
done
python3 "$ROOT/gguf-tools/merge_deepseek41_shards.py" \
--output "$mx_out" --expected-bytes "$mx_bytes" --sha256 "$mx_sha" "$@"
}
if [ "$MODEL" = "ds41f-mxfp4" ]; then
download_ds41_mxfp4
elif [ "$MODEL" = "ds41f-q4" ]; then
download_ds41_q4
elif [ -n "$MODEL_FILES" ]; then
for file in $MODEL_FILES; do
download_one "$file"
done
else
download_one "$MODEL_FILE"
fi
if [ "$MODEL" = "ds4f-dspark" ]; then
echo
echo "DSpark support downloaded. Enable it explicitly:"
echo " ./ds4 --dspark -m ./ds4flash.gguf --mtp-model $OUT_DIR/$DS4F_DSPARK_FILE"
elif [ "$MODEL" = "ds4f-vision-dspark" ]; then
echo
echo "Vision Experimental DSpark support downloaded. Use it only with the matching checkpoint:"
echo " ./ds4 --dspark -m ./ds4flash.gguf --mtp-model $OUT_DIR/$DS4F_VISION_DSPARK_FILE"
elif [ "$MODEL" = "pro-q4-layers00-30" ] || [ "$MODEL" = "pro-q4-layers31-output" ] || [ "$MODEL" = "pro-q4-split" ]; then
echo
echo "Downloaded PRO Q4 distributed split file(s). Use them with --layers,"
echo "for example coordinator layers 0:30 and worker layers 31:output."
elif [ "$LINK_MODEL" -eq 1 ]; then
cd "$ROOT"
ln -sfn "$OUT_DIR/$MODEL_FILE" ds4flash.gguf
echo "Linked ./ds4flash.gguf -> $OUT_DIR/$MODEL_FILE"
fi
echo
echo "Done."
if [ "$MODEL" = qwen38-q2 ] || [ "$MODEL" = qwen38-iq2 ]; then
echo "Run with an 8K starting context:"
echo " ./ds4 --ctx 8192 --prefill-chunk 1024"
echo "Add --mtp to enable speculation."
elif [ "$MODEL" = qwen38-q4k ]; then
echo "Run ./ds4. Add --mtp to enable speculation."
fi
if [ "$MODEL" = qwen38-vision ]; then
echo
echo "Qwen3.8 vision encoder downloaded. Pass it with --vision, for example:"
printf ' ./ds4 --vision "%s/%s"\n' "$OUT_DIR" "$QWEN38_VISION_FILE"
fi