Paul Dufour
commited on
Commit
β’
00f8773
1
Parent(s):
5c5a02d
Upload the original exports
Browse files- .gitignore +1 -0
- Makefile +57 -19
- onnx/QwenVL_A.onnx +3 -0
- onnx/QwenVL_A.onnx.data +3 -0
- onnx/QwenVL_B.onnx +3 -0
- onnx/QwenVL_C.onnx +3 -0
- onnx/QwenVL_D.onnx +3 -0
- onnx/QwenVL_E.onnx +3 -0
.gitignore
CHANGED
@@ -1 +1,2 @@
|
|
1 |
.DS_STORE
|
|
|
|
1 |
.DS_STORE
|
2 |
+
/onnx-dest
|
Makefile
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
.SHELLFLAGS := -e -c
|
2 |
SHELL := /bin/bash
|
3 |
|
4 |
# Configuration variables
|
@@ -18,24 +17,63 @@ TRANSFORMERS_PYTHON = $(TRANSFORMERS_JS_PATH)/.venv/bin/python3
|
|
18 |
PARTS = A B C D E
|
19 |
|
20 |
define progress_bar
|
21 |
-
|
22 |
-
|
23 |
-
for
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
for ((i=current*20/total; i<20; i++)); do printf " "; done; \
|
29 |
-
printf "\033[1;32m]\033[0m $$current/$$total "; \
|
30 |
-
printf "\033[1;34m$$item\033[K\033[0m\n"; \
|
31 |
-
cmd="$(2)"; \
|
32 |
-
cmd=$$(echo "$$cmd" | sed "s|{}|$$item|g"); \
|
33 |
-
$$cmd; \
|
34 |
-
done; \
|
35 |
-
printf "\n"
|
36 |
endef
|
37 |
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
all-in-one: export quantize clean-large-files slim fix-gpu-buffers
|
41 |
@echo "β¨ All done! ONNX models exported, slimmed, quantized and fixed"
|
@@ -46,12 +84,12 @@ export: export-abcd export-e
|
|
46 |
export-abcd:
|
47 |
@echo "π Exporting parts A, B, C, D..."
|
48 |
cd ../Native-LLM-for-Android/Export_ONNX/QwenVL && \
|
49 |
-
|
50 |
|
51 |
export-e:
|
52 |
@echo "π Exporting part E..."
|
53 |
cd ../Native-LLM-for-Android/Export_ONNX/QwenVL && \
|
54 |
-
|
55 |
|
56 |
slim:
|
57 |
@echo "ποΈ Slimming ONNX models..."
|
|
|
|
|
1 |
SHELL := /bin/bash
|
2 |
|
3 |
# Configuration variables
|
|
|
17 |
PARTS = A B C D E
|
18 |
|
19 |
define progress_bar
|
20 |
+
printf "\r Progress: \033[1;32m["; \
|
21 |
+
_done=$$(($1 * 20 / $2)); \
|
22 |
+
for ((i=0; i<_done; i++)); do printf "="; done; \
|
23 |
+
printf "\033[0m"; \
|
24 |
+
_left=$$((20 - _done)); \
|
25 |
+
for ((i=0; i<_left; i++)); do printf " "; done; \
|
26 |
+
printf "\033[1;32m]\033[0m $1/$2 Processing: \033[1;34m%s\033[K\033[0m\r" "$3"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
endef
|
28 |
|
29 |
+
# See https://github.com/pytorch/pytorch/issues/94280#issuecomment-2089196400
|
30 |
+
# Original export scripts export a bunch of tensor files, so we merge into one / two files instead.
|
31 |
+
export-merged-source-models: export-merged-source-models-first-pass export-merged-source-models-second-pass
|
32 |
+
@echo "β
Exporting merged source models complete"
|
33 |
+
|
34 |
+
export-merged-source-models-first-pass:
|
35 |
+
@echo "πΎ First pass: Export all models with merged tensors..."
|
36 |
+
@mkdir -p $(ONNX_DEST_DIR)
|
37 |
+
@files=`find $(ONNX_SRC_DIR) -name "*.onnx"`; \
|
38 |
+
total=`echo "$$files" | wc -w | tr -d ' '`; \
|
39 |
+
echo "Files found (first pass): $$total"; \
|
40 |
+
current=0; \
|
41 |
+
for item in $$files; do \
|
42 |
+
current=$$((current + 1)); \
|
43 |
+
$(call progress_bar,$$current,$$total,$$item); \
|
44 |
+
$(NATIVE_PYTHON) -u -c "import onnx, os, sys; src='$$item'; dest_dir='$(ONNX_DEST_DIR)'; \
|
45 |
+
m = onnx.load(src); \
|
46 |
+
d = os.path.join(dest_dir, os.path.basename(src)); \
|
47 |
+
onnx.save_model(m, d, all_tensors_to_one_file=True, save_as_external_data=True, location=os.path.basename(d)+'.data')" || exit 1; \
|
48 |
+
done; \
|
49 |
+
echo "β
Done first pass"
|
50 |
+
|
51 |
+
export-merged-source-models-second-pass:
|
52 |
+
@echo "πΎ Second pass: Converting large models to external data format..."
|
53 |
+
@files=`find $(ONNX_DEST_DIR) -name "*.onnx"`; \
|
54 |
+
total=`echo "$$files" | wc -w | tr -d ' '`; \
|
55 |
+
echo "Files found (second pass): $$total"; \
|
56 |
+
current=0; \
|
57 |
+
for item in $$files; do \
|
58 |
+
current=$$((current + 1)); \
|
59 |
+
$(call progress_bar,$$current,$$total,$$item); \
|
60 |
+
$(NATIVE_PYTHON) -c 'import onnx, os, sys; \
|
61 |
+
src = """'"$$item"'"""; \
|
62 |
+
total_size = os.path.getsize(src); \
|
63 |
+
total_size += os.path.getsize(src + ".data") if os.path.exists(src + ".data") else 0; \
|
64 |
+
needs_external = total_size > 2e9; \
|
65 |
+
onnx.save_model( \
|
66 |
+
onnx.load(src), \
|
67 |
+
src, \
|
68 |
+
save_as_external_data=needs_external, \
|
69 |
+
all_tensors_to_one_file=True, \
|
70 |
+
location=(os.path.basename(src) + ".data") if needs_external else None \
|
71 |
+
); \
|
72 |
+
not needs_external and os.path.exists(src + ".data") and os.remove(src + ".data") \
|
73 |
+
' || exit 1; \
|
74 |
+
done; \
|
75 |
+
echo "β
Done second models"
|
76 |
+
|
77 |
|
78 |
all-in-one: export quantize clean-large-files slim fix-gpu-buffers
|
79 |
@echo "β¨ All done! ONNX models exported, slimmed, quantized and fixed"
|
|
|
84 |
export-abcd:
|
85 |
@echo "π Exporting parts A, B, C, D..."
|
86 |
cd ../Native-LLM-for-Android/Export_ONNX/QwenVL && \
|
87 |
+
$(NATIVE_PYTHON) QwenVL_Export_ABCD.py "Qwen/Qwen2-VL-2B-Instruct"
|
88 |
|
89 |
export-e:
|
90 |
@echo "π Exporting part E..."
|
91 |
cd ../Native-LLM-for-Android/Export_ONNX/QwenVL && \
|
92 |
+
$(NATIVE_PYTHON) QwenVL_Export_E.py "Qwen/Qwen2-VL-2B-Instruct"
|
93 |
|
94 |
slim:
|
95 |
@echo "ποΈ Slimming ONNX models..."
|
onnx/QwenVL_A.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7668776b6d8a7dbbd5344de5948f9e7040cce04ac4fafff9155204dd2e0ef561
|
3 |
+
size 341395
|
onnx/QwenVL_A.onnx.data
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a1bdde323eb76c15f6eab14966d5b802c51a8d9559d5260ad3cf9e868ef160bf
|
3 |
+
size 5322682368
|
onnx/QwenVL_B.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7b2a741d6586465346e5c552c1d375da0b8321dd76a4d5498c0dd267ccd523b6
|
3 |
+
size 233983352
|
onnx/QwenVL_C.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a239bb5f47b6589f4db8d9a3b57ada13cabee3508851769d473f3bd2338da732
|
3 |
+
size 6384
|
onnx/QwenVL_D.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1d70b7429fc137486f82683d68953dd8a60d72466071fd22104bf5ff77e4460e
|
3 |
+
size 25215
|
onnx/QwenVL_E.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0b602930000f109874f028142d62fc488908d65e30be235565efa310d3d32c89
|
3 |
+
size 1505816
|