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
|
{
autoPatchelfHook,
buildPythonPackage,
fetchurl,
lib,
patchelf,
python,
pythonAtLeast,
stdenv,
# native dependencies
openvino-native,
# dependencies
backports-strenum,
flatbuffers,
numpy,
protobuf,
tqdm,
typing-extensions,
# optional-dependencies
lark,
ml-dtypes,
}:
let
release = builtins.fromJSON (builtins.readFile ./release.json);
platforms = release.src;
platform =
platforms.${stdenv.hostPlatform.system}
or (throw "ai-edge-litert: unsupported platform (${stdenv.hostPlatform.system})");
pythonMajorMinor = lib.versions.majorMinor python.version;
source =
platform.${pythonMajorMinor}
or (throw "ai-edge-litert: unsupported python version (${pythonMajorMinor})");
in
buildPythonPackage {
pname = "ai-edge-litert";
version = release.version;
format = "wheel";
src = fetchurl {
inherit (source)
url
hash
;
};
nativeBuildInputs = [ autoPatchelfHook ];
buildInputs = [ openvino-native ];
dependencies = [
backports-strenum
flatbuffers
numpy
protobuf
tqdm
typing-extensions
];
optional-dependencies = {
model-utils = [
lark
ml-dtypes
# TODO :xdsl
];
# TODO: npu-intel
# TODO: npu-sdk
};
preFixup = ''
while IFS= read -r -d "" so; do
${patchelf}/bin/patchelf --replace-needed libopenvino.so.2630 libopenvino.so "$so"
${patchelf}/bin/patchelf --replace-needed libopenvino_tensorflow_lite_frontend.so.2630 libopenvino_tensorflow_lite_frontend.so "$so"
done < <(find "$out" -type f \( -name '*.so' -o -name '*.so.*' \) -print0)
'';
autoPatchelfIgnoreMissingDeps = [
# Qualcomm Neural Network SDK
# https://www.qualcomm.com/developer/software/qualcomm-ai-engine-direct-sdk
"libQnnHtp.so"
"libQnnIr.so"
"libQnnSaver.so"
"libQnnSystem.so"
];
pythonRemoveDeps = lib.optionals (pythonAtLeast "3.12") [
# https://github.com/google-ai-edge/LiteRT/pull/5298
"backports.strenum"
];
pythonImportsCheck = [
"ai_edge_litert"
"ai_edge_litert.interpreter"
];
passthru.updateScript = ./update.py;
meta = {
changelog = "https://github.com/google-ai-edge/LiteRT/releases/tag/v${release.version}";
description = "LiteRT is for mobile and embedded devices";
downloadPage = "https://github.com/google-ai-edge/LiteRT";
homepage = "https://www.tensorflow.org/lite/";
license = lib.licenses.asl20;
platforms = lib.attrNames platforms;
sourceProvenance = [ lib.sourceTypes.binaryNativeCode ];
maintainers = with lib.maintainers; [ hexa ];
badPlatforms = [
# elftools.common.exceptions.ELFError: Magic number does not match
lib.systems.inspect.patterns.isDarwin
];
};
}
|