mediapipe-nightly 0.10.10.post20240216__cp38-cp38-macosx_11_0_universal2.whl → 0.10.10.post20240220__cp38-cp38-macosx_11_0_universal2.whl
Sign up to get free protection for your applications and to get access to all the features.
- mediapipe/__init__.py +1 -1
- mediapipe/python/_framework_bindings.cpython-38-darwin.so +0 -0
- mediapipe/tasks/python/__init__.py +1 -0
- mediapipe/tasks/python/genai/__init__.py +14 -0
- mediapipe/tasks/python/genai/converter/__init__.py +24 -0
- mediapipe/tasks/python/genai/converter/converter_base.py +172 -0
- mediapipe/tasks/python/genai/converter/converter_factory.py +79 -0
- mediapipe/tasks/python/genai/converter/llm_converter.py +213 -0
- mediapipe/tasks/python/genai/converter/pytorch_converter.py +315 -0
- mediapipe/tasks/python/genai/converter/pytorch_converter_test.py +86 -0
- mediapipe/tasks/python/genai/converter/quantization_util.py +516 -0
- mediapipe/tasks/python/genai/converter/quantization_util_test.py +259 -0
- mediapipe/tasks/python/genai/converter/safetensors_converter.py +521 -0
- mediapipe/tasks/python/genai/converter/safetensors_converter_test.py +83 -0
- mediapipe/tasks/python/genai/converter/weight_bins_writer.py +111 -0
- mediapipe/tasks/python/genai/converter/weight_bins_writer_test.py +62 -0
- mediapipe/version.txt +1 -1
- {mediapipe_nightly-0.10.10.post20240216.dist-info → mediapipe_nightly-0.10.10.post20240220.dist-info}/METADATA +1 -1
- {mediapipe_nightly-0.10.10.post20240216.dist-info → mediapipe_nightly-0.10.10.post20240220.dist-info}/RECORD +21 -8
- {mediapipe_nightly-0.10.10.post20240216.dist-info → mediapipe_nightly-0.10.10.post20240220.dist-info}/LICENSE +0 -0
- {mediapipe_nightly-0.10.10.post20240216.dist-info → mediapipe_nightly-0.10.10.post20240220.dist-info}/WHEEL +0 -0
- {mediapipe_nightly-0.10.10.post20240216.dist-info → mediapipe_nightly-0.10.10.post20240220.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,111 @@
|
|
1
|
+
# Copyright 2024 The MediaPipe Authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
"""ModelWriter for writing a set of weights as binary files."""
|
16
|
+
|
17
|
+
import contextlib
|
18
|
+
import os
|
19
|
+
from typing import Dict, Tuple
|
20
|
+
|
21
|
+
import numpy as np
|
22
|
+
|
23
|
+
from mediapipe.tasks.python.genai.converter import converter_base
|
24
|
+
from mediapipe.tasks.python.genai.converter import quantization_util
|
25
|
+
|
26
|
+
|
27
|
+
@contextlib.contextmanager
|
28
|
+
def filemanager(filename: str, mode: str):
|
29
|
+
try:
|
30
|
+
with open(filename, mode) as f:
|
31
|
+
yield f
|
32
|
+
finally:
|
33
|
+
pass
|
34
|
+
|
35
|
+
|
36
|
+
def removeprefix(s, prefix):
|
37
|
+
"""Removes the prefix from a string."""
|
38
|
+
if s.startswith(prefix):
|
39
|
+
return s[len(prefix) :]
|
40
|
+
return s
|
41
|
+
|
42
|
+
|
43
|
+
class WeightBinsWriter(converter_base.ModelWriterBase):
|
44
|
+
"""A ModelWriter for writing a set of weights as binary files."""
|
45
|
+
|
46
|
+
def get_weight_info(self, var_name: str, weight: np.ndarray) -> str:
|
47
|
+
"""Gets the string that describes the weights."""
|
48
|
+
dtype_str = str(weight.dtype)
|
49
|
+
shape_str = '_'.join(map(str, weight.shape))
|
50
|
+
return f'mdl_vars.{var_name}.{dtype_str}.{shape_str}\n'
|
51
|
+
|
52
|
+
def write_variables(self, variables: Dict[str, Tuple[np.ndarray, bool]]):
|
53
|
+
"""Writes variable to the binary files. One for each layer.
|
54
|
+
|
55
|
+
Args:
|
56
|
+
variables: A dictionary that maps from the target variable names to the
|
57
|
+
quantized tensor values along with a boolean that indicates whether to
|
58
|
+
pack the values (only applicable for the 4-bit quantized tensors).
|
59
|
+
"""
|
60
|
+
weights_info = []
|
61
|
+
for var_name, value in variables.items():
|
62
|
+
output = value[0]
|
63
|
+
if value[1]:
|
64
|
+
# Squeeze the tensor to make sure it is a 1D array for packing.
|
65
|
+
output = np.expand_dims(np.ravel(output), axis=-1)
|
66
|
+
# Extra pack needed for 4 bit. We always pack the weights along the
|
67
|
+
# first dimension since the tensor has already been squeezed.
|
68
|
+
output = quantization_util.pack_4bit(output, 0)
|
69
|
+
if 'combined_qkv' in var_name:
|
70
|
+
var_name = removeprefix(var_name, 'mld_vars.')
|
71
|
+
var_name_q = var_name.replace('combined_qkv', 'q')
|
72
|
+
var_name_k = var_name.replace('combined_qkv', 'k')
|
73
|
+
var_name_v = var_name.replace('combined_qkv', 'v')
|
74
|
+
if output.shape[0] == 3:
|
75
|
+
weight_q, weight_k, weight_v = output
|
76
|
+
assert weight_q.shape == weight_k.shape == weight_v.shape
|
77
|
+
else: # LoRA right weight is shared across q, k, v
|
78
|
+
weight_q = weight_k = weight_v = output
|
79
|
+
weights_info.append(self.get_weight_info(var_name_q, weight_q))
|
80
|
+
path_q = os.path.join(self._output_dir, var_name_q)
|
81
|
+
with filemanager(path_q, 'wb') as f:
|
82
|
+
f.write(weight_q.tobytes())
|
83
|
+
weights_info.append(self.get_weight_info(var_name_k, weight_k))
|
84
|
+
path_k = os.path.join(self._output_dir, var_name_k)
|
85
|
+
with filemanager(path_k, 'wb') as f:
|
86
|
+
f.write(weight_k.tobytes())
|
87
|
+
path_v = os.path.join(self._output_dir, var_name_v)
|
88
|
+
with filemanager(path_v, 'wb') as f:
|
89
|
+
f.write(weight_v.tobytes())
|
90
|
+
weights_info.append(self.get_weight_info(var_name_v, weight_v))
|
91
|
+
else:
|
92
|
+
if 'key' in var_name:
|
93
|
+
var_name = var_name.replace('key', 'k')
|
94
|
+
if 'query' in var_name:
|
95
|
+
var_name = var_name.replace('query', 'q')
|
96
|
+
if 'value' in var_name:
|
97
|
+
var_name = var_name.replace('value', 'v')
|
98
|
+
path = os.path.join(
|
99
|
+
self._output_dir, removeprefix(var_name, 'mdl_vars.')
|
100
|
+
)
|
101
|
+
with filemanager(path, 'wb') as f:
|
102
|
+
f.write(output.tobytes())
|
103
|
+
weights_info.append(self.get_weight_info(var_name, output))
|
104
|
+
|
105
|
+
# Sort weights_info
|
106
|
+
weights_info.sort()
|
107
|
+
with filemanager(
|
108
|
+
os.path.join(self._output_dir, 'layer_info.txt'), 'w'
|
109
|
+
) as finfo:
|
110
|
+
for line in weights_info:
|
111
|
+
finfo.write(line + '\n')
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# Copyright 2024 The MediaPipe Authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
"""Unit tests for pax_converter."""
|
16
|
+
|
17
|
+
import os
|
18
|
+
|
19
|
+
from absl import flags
|
20
|
+
from absl.testing import absltest
|
21
|
+
from absl.testing import parameterized
|
22
|
+
import numpy as np
|
23
|
+
|
24
|
+
from mediapipe.tasks.python.genai.converter import weight_bins_writer
|
25
|
+
|
26
|
+
|
27
|
+
class WeightBinsWriterTest(parameterized.TestCase):
|
28
|
+
|
29
|
+
def test_get_weight_info(self):
|
30
|
+
output_dir = os.path.join(flags.FLAGS.test_tmpdir, 'output_dir')
|
31
|
+
writer = weight_bins_writer.WeightBinsWriter(
|
32
|
+
output_dir=output_dir, backend='cpu'
|
33
|
+
)
|
34
|
+
var_name = 'params.lm.softmax.logits_ffn.linear.w'
|
35
|
+
weight_info = writer.get_weight_info(
|
36
|
+
var_name, np.array([[1, 2, 3], [4, 5, 6]], dtype=np.float32)
|
37
|
+
)
|
38
|
+
self.assertEqual(
|
39
|
+
weight_info,
|
40
|
+
'mdl_vars.params.lm.softmax.logits_ffn.linear.w.float32.2_3\n',
|
41
|
+
)
|
42
|
+
|
43
|
+
def test_load_to_actions(self):
|
44
|
+
output_dir = os.path.join(flags.FLAGS.test_tmpdir, 'output_dir')
|
45
|
+
writer = weight_bins_writer.WeightBinsWriter(
|
46
|
+
output_dir=output_dir, backend='cpu'
|
47
|
+
)
|
48
|
+
variables = {
|
49
|
+
'mdl_vars.params.lm.softmax.logits_ffn.linear.w': (
|
50
|
+
np.array([[1, 2, 3], [4, 5, 6]], dtype=np.float32),
|
51
|
+
False,
|
52
|
+
),
|
53
|
+
}
|
54
|
+
writer.write_variables(variables)
|
55
|
+
file_size = os.path.getsize(
|
56
|
+
os.path.join(output_dir, 'params.lm.softmax.logits_ffn.linear.w')
|
57
|
+
)
|
58
|
+
self.assertEqual(file_size, 6 * 4)
|
59
|
+
|
60
|
+
|
61
|
+
if __name__ == '__main__':
|
62
|
+
absltest.main()
|
mediapipe/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.10.10-
|
1
|
+
0.10.10-20240220
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: mediapipe-nightly
|
3
|
-
Version: 0.10.10.
|
3
|
+
Version: 0.10.10.post20240220
|
4
4
|
Summary: MediaPipe is the simplest way for researchers and developers to build world-class ML solutions and applications for mobile, edge, cloud and the web.
|
5
5
|
Home-page: https://github.com/google/mediapipe
|
6
6
|
Author: The MediaPipe Authors
|
@@ -1,11 +1,11 @@
|
|
1
|
-
mediapipe_nightly-0.10.10.
|
2
|
-
mediapipe_nightly-0.10.10.
|
3
|
-
mediapipe_nightly-0.10.10.
|
4
|
-
mediapipe_nightly-0.10.10.
|
5
|
-
mediapipe_nightly-0.10.10.
|
6
|
-
mediapipe/__init__.py,sha256=
|
1
|
+
mediapipe_nightly-0.10.10.post20240220.dist-info/RECORD,,
|
2
|
+
mediapipe_nightly-0.10.10.post20240220.dist-info/LICENSE,sha256=hwfu8FM5h-_FsVXWR2HutuIHk_ULm9Gmja0c9HGdDtg,12331
|
3
|
+
mediapipe_nightly-0.10.10.post20240220.dist-info/WHEEL,sha256=ne9oAesYhmqqzZoZWVnfbfuFiLIE1hGPUf33054jNWs,109
|
4
|
+
mediapipe_nightly-0.10.10.post20240220.dist-info/top_level.txt,sha256=LG-epD1oIiiHFRqLp--7jacjB3dbx2RfMcLYjCIhmxU,175
|
5
|
+
mediapipe_nightly-0.10.10.post20240220.dist-info/METADATA,sha256=EhYSeSZKjHI0a_l13O29t73CzTLaRhFQix-W_s_lVX8,9672
|
6
|
+
mediapipe/__init__.py,sha256=rdbukqBkiz5MY5H-FrACK0jAtVcmijeoMWNeVR_bhrU,816
|
7
7
|
mediapipe/tasks/__init__.py,sha256=sVJS2p8J2PNVl8DLRPVY6KLpHenP_z3QVPRU0x_iL5g,571
|
8
|
-
mediapipe/tasks/python/__init__.py,sha256=
|
8
|
+
mediapipe/tasks/python/__init__.py,sha256=wIM_WOWboOVI1MeehN8fkN_DjoA0MEBVw5mShAd8AS4,858
|
9
9
|
mediapipe/tasks/python/benchmark/__init__.py,sha256=epEucluzX0HinwBZoS7Tgb19j_qgfTuBf-vBkqemch8,587
|
10
10
|
mediapipe/tasks/python/benchmark/benchmark_utils.py,sha256=5qbqGxxYlJJQLJzbW0cwMCcGl4c8ZfKL3rNmm7xMVAE,2241
|
11
11
|
mediapipe/tasks/python/benchmark/vision/benchmark.py,sha256=gifRumSkesmXVU51GHRct-UYf8S9Dn2isD28Aw7BClQ,3491
|
@@ -85,6 +85,19 @@ mediapipe/tasks/python/text/text_embedder.py,sha256=JB-jQyVgcbfH8tOuJjV2Qyk2ewyU
|
|
85
85
|
mediapipe/tasks/python/text/text_classifier.py,sha256=AJbYep6iL8vkf6JKRrGArr9sNd5ugLEliOK1tNr3DsE,7917
|
86
86
|
mediapipe/tasks/python/text/core/base_text_task_api.py,sha256=OHt7j_0n5c3HBdOrCb_BGWCdKWMKvDULp6tKA5mDZAc,1822
|
87
87
|
mediapipe/tasks/python/text/core/__init__.py,sha256=ZKC2XRtShVe6k6u6LxDt1pG7DQIn5nZnjurs6Pcvm6A,593
|
88
|
+
mediapipe/tasks/python/genai/__init__.py,sha256=7rri6fT6wNurla8O2c5yKiLs9_3qIY0vKkyVAUDe-18,620
|
89
|
+
mediapipe/tasks/python/genai/converter/pytorch_converter_test.py,sha256=hJOjozkWpzjedhkfWoF-vinSMs7TqCPO-W9VpleQo2U,3008
|
90
|
+
mediapipe/tasks/python/genai/converter/safetensors_converter_test.py,sha256=bdBHCQOTqAyHpC19di_H0hV3zraBOXXfV_6NbFT0ouw,2796
|
91
|
+
mediapipe/tasks/python/genai/converter/quantization_util.py,sha256=B6i13GqRRIwMabEJWO8rFHPMBjIgdOhFpHiwMD4GzRc,17196
|
92
|
+
mediapipe/tasks/python/genai/converter/safetensors_converter.py,sha256=IbnvTH_n8hnVd9nChOT8oGx2Ssw4iCFCnlWB1708ujc,18710
|
93
|
+
mediapipe/tasks/python/genai/converter/weight_bins_writer_test.py,sha256=6qgNYXODNOsbveZ0ighEW4JBdawil9mPcC16MZ0mdm8,1994
|
94
|
+
mediapipe/tasks/python/genai/converter/converter_base.py,sha256=nRIhPYUg2pkUZcmwMIDVM4lskRRUwoOYep9MY78b2xE,6519
|
95
|
+
mediapipe/tasks/python/genai/converter/pytorch_converter.py,sha256=RiuCr2aXbZVn3Ssa3OcSx_RQK56rfZRCpvG7qYIji4w,10675
|
96
|
+
mediapipe/tasks/python/genai/converter/__init__.py,sha256=jfUkinDJR5BVldnbJMbo5vIr2Xc5Z4TTnaCJTNoAUvg,893
|
97
|
+
mediapipe/tasks/python/genai/converter/converter_factory.py,sha256=2K16PZBQym0WhXM2HOdBMHMugykohoD4OTaOIo-UKko,2928
|
98
|
+
mediapipe/tasks/python/genai/converter/llm_converter.py,sha256=_S8fj-WAA6OMQFj_QZPChlfkJ4gp_DE2t8i4pwJAHjI,7782
|
99
|
+
mediapipe/tasks/python/genai/converter/quantization_util_test.py,sha256=ICujhTFeREGuHGmNk1PlBpf1AUThFvv-Wl5UuZ-xWAk,9060
|
100
|
+
mediapipe/tasks/python/genai/converter/weight_bins_writer.py,sha256=Ar8XBs1GhVSFObqN29K754iVZ_WSxe4k0Rty1a4vla0,4308
|
88
101
|
mediapipe/tasks/python/metadata/metadata.py,sha256=EECQnM-Af0angD60jaBBOuNMgt7HExH6SqVtVMFNHGc,33763
|
89
102
|
mediapipe/tasks/python/metadata/metadata_displayer_cli.py,sha256=tLhF0B1mXG0igFTA9nPh8t1efRpRw2hQ00XpTPYdk_o,1202
|
90
103
|
mediapipe/tasks/python/metadata/__init__.py,sha256=YGHXQMz1ZGPcNgSXggu03b0USZKE8d9Xqvn6NDUl898,586
|
@@ -296,7 +309,7 @@ mediapipe/python/solution_base.py,sha256=48PszV6dCssQUkyPBaqhqVehVjPtskawtGUc54k
|
|
296
309
|
mediapipe/python/timestamp_test.py,sha256=oWKTZMsV586jH57OBV30rihcymETyGC29VbYURNLJQQ,2528
|
297
310
|
mediapipe/python/image_frame_test.py,sha256=ZSjdE-an2t8i6MiA4_Xri91VMH5_CCx45fjhWUQptMY,8602
|
298
311
|
mediapipe/python/__init__.py,sha256=xTuq4e55ofMUGUpV81ZbVzYHmjMmzt9dBOfS4ugFN1c,1428
|
299
|
-
mediapipe/python/_framework_bindings.cpython-38-darwin.so,sha256=
|
312
|
+
mediapipe/python/_framework_bindings.cpython-38-darwin.so,sha256=Eg1Puj-umoAIaSTLEQSbfasgJCtoy6a2ZFkhDnQkLs0,78069827
|
300
313
|
mediapipe/python/solution_base_test.py,sha256=1u5Lo4aEUrMKj8Ha_34XMyKnI-3A1AvpaX3MCI0b2MM,15632
|
301
314
|
mediapipe/python/packet_creator.py,sha256=34MBIMwykbZSLV-gdVYTzK8R07yzWV5yg1HuyRbS4d0,11414
|
302
315
|
mediapipe/python/packet_getter.py,sha256=QkBxKCjXrOC6j2dJ5zcVNGaPB6zjurKztQpW5kOYLj4,4205
|
File without changes
|
File without changes
|
File without changes
|