ai-edge-litert-sdk-mediatek-nightly 0.1.0.dev20250515__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ graft ai_edge_litert_sdk_mediatek/data
2
+ include ai_edge_litert_sdk_mediatek/__init__.py
@@ -0,0 +1,25 @@
1
+ Metadata-Version: 2.1
2
+ Name: ai-edge-litert-sdk-mediatek-nightly
3
+ Version: 0.1.0.dev20250515
4
+ Summary: MediaTek NeuroPilot SDK for AI Edge LiteRT
5
+ Home-page: https://www.tensorflow.org/lite/
6
+ Author: Google AI Edge Authors
7
+ Author-email: packages@tensorflow.org
8
+ License: Apache 2.0
9
+ Keywords: litert tflite tensorflow tensor machine learning
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Education
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Topic :: Scientific/Engineering
21
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Classifier: Topic :: Software Development
24
+ Classifier: Topic :: Software Development :: Libraries
25
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
@@ -0,0 +1,63 @@
1
+ # Copyright 2025 The LiteRT Authors. All Rights Reserved.
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
+
16
+ """MediaTek SDK for AI Edge LiteRT."""
17
+
18
+ __version__ = "0.1.0.dev20250515"
19
+
20
+ import os
21
+ import pathlib
22
+ import platform
23
+ import sys
24
+ from typing import Optional
25
+
26
+ _SDK_FILES_SUBDIR = "data"
27
+
28
+
29
+ def path_to_sdk_libs(version: str = "v8") -> Optional[pathlib.Path]:
30
+ sdk_path = get_sdk_path()
31
+ if version != "v8":
32
+ raise NotImplementedError(
33
+ f"Unsupported version: {version}. Only 'v8' is supported."
34
+ )
35
+ if not sdk_path:
36
+ return None
37
+ # Currently we only support linux x86 architecture.
38
+ return get_sdk_path() / "v8_0_8/host/lib"
39
+
40
+
41
+ def get_sdk_path() -> Optional[pathlib.Path]:
42
+ """Returns the absolute path to the root of the downloaded SDK files."""
43
+ is_linux = sys.platform == "linux"
44
+ is_x86_architecture = platform.machine() in ("x86_64", "i386", "i686")
45
+ if not (is_linux and is_x86_architecture):
46
+ raise NotImplementedError(
47
+ "Currently LiteRT NPU AOT for MediaTek is only supported on Linux x86"
48
+ " architecture."
49
+ )
50
+ try:
51
+ package_dir = pathlib.Path(__file__).parent.resolve()
52
+ sdk_path = package_dir / _SDK_FILES_SUBDIR
53
+ if sdk_path.is_dir():
54
+ return sdk_path
55
+ else:
56
+ print(
57
+ f"Warning: SDK files directory not found at {sdk_path}",
58
+ file=sys.stderr,
59
+ )
60
+ return None
61
+ except Exception as e: # pylint: disable=broad-exception-caught
62
+ print(f"Error determining SDK path: {e}", file=sys.stderr)
63
+ return None
@@ -0,0 +1,25 @@
1
+ Metadata-Version: 2.1
2
+ Name: ai-edge-litert-sdk-mediatek-nightly
3
+ Version: 0.1.0.dev20250515
4
+ Summary: MediaTek NeuroPilot SDK for AI Edge LiteRT
5
+ Home-page: https://www.tensorflow.org/lite/
6
+ Author: Google AI Edge Authors
7
+ Author-email: packages@tensorflow.org
8
+ License: Apache 2.0
9
+ Keywords: litert tflite tensorflow tensor machine learning
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Education
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Topic :: Scientific/Engineering
21
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Classifier: Topic :: Software Development
24
+ Classifier: Topic :: Software Development :: Libraries
25
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
@@ -0,0 +1,8 @@
1
+ MANIFEST.in
2
+ setup.py
3
+ ai_edge_litert_sdk_mediatek/__init__.py
4
+ ai_edge_litert_sdk_mediatek_nightly.egg-info/PKG-INFO
5
+ ai_edge_litert_sdk_mediatek_nightly.egg-info/SOURCES.txt
6
+ ai_edge_litert_sdk_mediatek_nightly.egg-info/dependency_links.txt
7
+ ai_edge_litert_sdk_mediatek_nightly.egg-info/not-zip-safe
8
+ ai_edge_litert_sdk_mediatek_nightly.egg-info/top_level.txt
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,236 @@
1
+ # Copyright 2025 The AI Edge LiteRT 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
+ """LiteRT is for mobile and embedded devices.
16
+
17
+ LiteRT is the official solution for running machine learning models on mobile
18
+ and embedded devices. It enables on-device machine learning inference with low
19
+ latency and a small binary size on Android, iOS, and other operating systems.
20
+ """
21
+
22
+ import os
23
+ import platform
24
+ import sys
25
+ import tarfile
26
+ import tempfile
27
+ import urllib.request
28
+ import zipfile
29
+
30
+ import setuptools
31
+ from setuptools.command.build_py import build_py as _build_py # pylint: disable=g-importing-member
32
+
33
+ PACKAGE_NAME = 'ai_edge_litert_sdk_mediatek_nightly'
34
+ PACKAGE_VERSION = '0.1.0.dev20250515'
35
+
36
+ SKIP_SDK_DOWNLOAD = os.environ.get('SKIP_SDK_DOWNLOAD', False)
37
+
38
+
39
+ # Platform information
40
+ IS_LINUX = sys.platform == 'linux'
41
+ IS_X86_ARCHITECTURE = platform.machine() in ('x86_64', 'i386', 'i686')
42
+
43
+
44
+ # --- Configuration for MediaTek NeuroPilot SDK Download ---
45
+ # NeuroPilot version doesn't not necessarily match the SDK version though.
46
+ NEUROPILOT_URL = 'https://s3.ap-southeast-1.amazonaws.com/mediatek.neuropilot.com/57c17aa0-90b4-4871-a7b6-cdcdc678b3aa.gz' # pylint: disable=line-too-long
47
+ NEUROPILOT_CONTENT_DIR = 'neuro_pilot'
48
+ NEUROPILOT_TARGET_DIR = 'ai_edge_litert_sdk_mediatek/data'
49
+ # ---
50
+
51
+
52
+ def _download_and_extract(
53
+ tarball_url: str, prefix_to_strip: str, target_dir: str
54
+ ):
55
+ """Download archive, extracts and copy."""
56
+ if not (IS_LINUX and IS_X86_ARCHITECTURE):
57
+ print(
58
+ 'IGNORED: Currently LiteRT NPU AOT for MediaTek is only supported on'
59
+ ' Linux x86 architecture.'
60
+ )
61
+ return
62
+
63
+ os.makedirs(target_dir, exist_ok=True)
64
+
65
+ with tempfile.TemporaryDirectory() as tmpdir:
66
+ archive_name_local = os.path.join(tmpdir, os.path.basename(tarball_url))
67
+
68
+ print(f'Downloading SDK from {tarball_url}...')
69
+ try:
70
+ urllib.request.urlretrieve(tarball_url, archive_name_local)
71
+ except Exception as e: # pylint: disable=broad-exception-caught
72
+ print(f'ERROR: Failed to download SDK: {e}', file=sys.stderr)
73
+ print(
74
+ 'Please ensure you have an active internet connection.',
75
+ file=sys.stderr,
76
+ )
77
+ return
78
+
79
+ print('Extracting SDK files...')
80
+ try:
81
+ if tarball_url.endswith('.zip'):
82
+ archive_type = 'zip'
83
+ elif (
84
+ tarball_url.endswith('.tar.gz')
85
+ or tarball_url.endswith('.tgz')
86
+ or tarball_url.endswith('.gz')
87
+ ):
88
+ archive_type = 'tar.gz'
89
+ else:
90
+ print(
91
+ f'ERROR: Unsupported archive type for URL: {tarball_url}',
92
+ file=sys.stderr,
93
+ )
94
+ return
95
+
96
+ if archive_type == 'zip':
97
+ with zipfile.ZipFile(archive_name_local, 'r') as zipf:
98
+ for member_info in zipf.infolist():
99
+ original_name = member_info.filename
100
+ # Ensure paths are normalized and secure (prevent path traversal)
101
+ if (
102
+ original_name.startswith(prefix_to_strip + '/')
103
+ and original_name != prefix_to_strip + '/'
104
+ ):
105
+ path_inside_subdir = original_name[len(prefix_to_strip) + 1 :]
106
+
107
+ if not path_inside_subdir:
108
+ continue
109
+
110
+ normalized_path = os.path.normpath(path_inside_subdir)
111
+ if normalized_path.startswith('..') or os.path.isabs(
112
+ normalized_path
113
+ ):
114
+ print(
115
+ 'WARNING: Skipping potentially malicious path:'
116
+ f' {original_name}',
117
+ file=sys.stderr,
118
+ )
119
+ continue
120
+
121
+ target_path_for_member = os.path.join(target_dir, normalized_path)
122
+
123
+ if member_info.is_dir():
124
+ os.makedirs(target_path_for_member, exist_ok=True)
125
+ else: # It's a file
126
+ os.makedirs(
127
+ os.path.dirname(target_path_for_member), exist_ok=True
128
+ )
129
+ with zipf.open(member_info) as source, open(
130
+ target_path_for_member, 'wb'
131
+ ) as target:
132
+ target.write(source.read())
133
+
134
+ elif archive_type == 'tar.gz':
135
+ with tarfile.open(archive_name_local, 'r:gz') as tar:
136
+ members_to_extract = []
137
+ for member in tar.getmembers():
138
+ if (
139
+ member.name.startswith(prefix_to_strip + '/')
140
+ and member.name != prefix_to_strip + '/'
141
+ ):
142
+ path_inside_subdir = member.name[len(prefix_to_strip) + 1 :]
143
+
144
+ if not path_inside_subdir: # Skip if it's empty after stripping
145
+ continue
146
+
147
+ normalized_path = os.path.normpath(path_inside_subdir)
148
+ if normalized_path.startswith('..') or os.path.isabs(
149
+ normalized_path
150
+ ):
151
+ print(
152
+ 'WARNING: Skipping potentially malicious path:'
153
+ f' {member.name}',
154
+ file=sys.stderr,
155
+ )
156
+ continue
157
+
158
+ member_copy = tar.getmember(member.name)
159
+ member_copy.name = normalized_path
160
+ members_to_extract.append(member_copy)
161
+
162
+ if members_to_extract:
163
+ tar.extractall(path=target_dir, members=members_to_extract)
164
+ print(
165
+ f"SDK files from '{prefix_to_strip}/' extracted to {target_dir}"
166
+ )
167
+ else:
168
+ print(f"No files found under '{prefix_to_strip}/' in the tarball.")
169
+
170
+ except (
171
+ zipfile.BadZipFile,
172
+ tarfile.TarError,
173
+ ) as e: # Catch both zipfile and tarfile specific errors
174
+ print(f'ERROR: Failed to extract archive: {e}', file=sys.stderr)
175
+ return
176
+ except Exception as e: # pylint: disable=broad-exception-caught
177
+ print(
178
+ f'ERROR: An unexpected error occurred during SDK extraction: {e}',
179
+ file=sys.stderr,
180
+ )
181
+ raise SystemExit('Install SDK failed. Aborting installation.') from e
182
+
183
+
184
+ class CustomBuildPy(_build_py):
185
+ """Command to replace import statements."""
186
+
187
+ def run(self):
188
+
189
+ print('Preparing SDK...')
190
+ if SKIP_SDK_DOWNLOAD:
191
+ print('Skipping SDK download...')
192
+ else:
193
+ _download_and_extract(
194
+ NEUROPILOT_URL, NEUROPILOT_CONTENT_DIR, NEUROPILOT_TARGET_DIR
195
+ )
196
+
197
+ super().run()
198
+
199
+
200
+ setuptools.setup(
201
+ name=PACKAGE_NAME.replace('_', '-'),
202
+ version=PACKAGE_VERSION,
203
+ description='MediaTek NeuroPilot SDK for AI Edge LiteRT',
204
+ url='https://www.tensorflow.org/lite/',
205
+ author='Google AI Edge Authors',
206
+ author_email='packages@tensorflow.org',
207
+ license='Apache 2.0',
208
+ include_package_data=True,
209
+ has_ext_modules=lambda: True,
210
+ keywords='litert tflite tensorflow tensor machine learning',
211
+ classifiers=[
212
+ 'Development Status :: 5 - Production/Stable',
213
+ 'Intended Audience :: Developers',
214
+ 'Intended Audience :: Education',
215
+ 'Intended Audience :: Science/Research',
216
+ 'License :: OSI Approved :: Apache Software License',
217
+ 'Programming Language :: Python :: 3',
218
+ 'Programming Language :: Python :: 3.8',
219
+ 'Programming Language :: Python :: 3.9',
220
+ 'Programming Language :: Python :: 3.10',
221
+ 'Programming Language :: Python :: 3.11',
222
+ 'Topic :: Scientific/Engineering',
223
+ 'Topic :: Scientific/Engineering :: Mathematics',
224
+ 'Topic :: Scientific/Engineering :: Artificial Intelligence',
225
+ 'Topic :: Software Development',
226
+ 'Topic :: Software Development :: Libraries',
227
+ 'Topic :: Software Development :: Libraries :: Python Modules',
228
+ ],
229
+ packages=['ai_edge_litert_sdk_mediatek'],
230
+ package_dir={'ai_edge_litert_sdk_mediatek': 'ai_edge_litert_sdk_mediatek'},
231
+ # Use the custom command for the build_py step
232
+ cmdclass={
233
+ 'build_py': CustomBuildPy,
234
+ },
235
+ zip_safe=False,
236
+ )