Skip to content

Commit 79e3697

Browse files
authored
Add building guide for the ggml plugin (#205)
* Add building guide for the ggml plugin Signed-off-by: hydai <[email protected]> * Add TensorFlow Lite Signed-off-by: hydai <[email protected]> --------- Signed-off-by: hydai <[email protected]>
1 parent ce11b49 commit 79e3697

File tree

1 file changed

+188
-2
lines changed

1 file changed

+188
-2
lines changed

docs/contribute/source/plugin/wasi_nn.md

Lines changed: 188 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The WASI-NN plug-in is a proposed WebAssembly System Interface (WASI) API for ma
88

99
## Prerequisites
1010

11-
Currently, WasmEdge used OpenVINO™ or PyTorch as the WASI-NN backend implementation. For using WASI-NN on WasmEdge, you need to install [OpenVINO™](https://docs.openvino.ai/2023.0/openvino_docs_install_guides_installing_openvino_apt.html)(2023) or [PyTorch 1.8.2 LTS](https://pytorch.org/get-started/locally/) for the backend.
11+
Currently, WasmEdge used OpenVINO™, PyTorch, TensorFlow Lite, or llama.cpp as the WASI-NN backend implementation. For using WASI-NN on WasmEdge, you need to install [OpenVINO™](https://docs.openvino.ai/2023.0/openvino_docs_install_guides_installing_openvino_apt.html)(2023), [TensorFlow Lite](https://www.tensorflow.org/install/lang_c), or [PyTorch 1.8.2 LTS](https://pytorch.org/get-started/locally/) for the backend.
1212

1313
By default, we don't enable any WASI-NN backend in WasmEdge. Therefore developers should [build the WasmEdge from source](../os/linux.md) with the cmake option `WASMEDGE_PLUGIN_WASI_NN_BACKEND` to enable the backends.
1414

@@ -128,4 +128,190 @@ Or set the environment variable `export LD_LIBRARY_PATH=$(pwd):${LD_LIBRARY_PATH
128128
We also provided the `darwin_x86_64`, `darwin_arm64`, and `manylinux_aarch64` versions of the TensorFlow-Lite pre-built shared libraries.
129129
:::
130130

131-
For more information, you can refer to the [GitHub repository](https://github.com/WasmEdge/WasmEdge/tree/master/plugins/wasi_nn).
131+
For more information, you can refer to the [GitHub repository](https://github.com/WasmEdge/WasmEdge/tree/master/plugins/wasi_nn).
132+
133+
## Build WasmEdge with WASI-NN llama.cpp Backend
134+
135+
You don't need to install any llama.cpp libraries. WasmEdge will download it during the building period.
136+
137+
Due to the acceleration frameworks being various, you will need to use different compilation options to build this plugin. Please make sure you are following the same OS section to do this.
138+
139+
### macOS
140+
141+
#### Intel Model
142+
143+
If you are using the Intel Model macOS, we won't enable any acceleration framework. It is a pure CPU mode plugin.
144+
145+
```bash
146+
cd <path/to/your/wasmedge/source/folder>
147+
# Disable BLAS and METAL on x86_64 macOS.
148+
cmake -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Release \
149+
-DWASMEDGE_PLUGIN_WASI_NN_BACKEND="GGML" \
150+
-DWASMEDGE_PLUGIN_WASI_NN_GGML_LLAMA_METAL=OFF \
151+
-DWASMEDGE_PLUGIN_WASI_NN_GGML_LLAMA_BLAS=OFF \
152+
.
153+
cmake --build build
154+
# For the WASI-NN plugin, you should install this project.
155+
cmake --install build
156+
```
157+
158+
#### Apple Silicon Model
159+
160+
You can build and install WasmEdge from source directly on the macOS arm64 platform. It will use the built-in GPU by default.
161+
162+
```bash
163+
cd <path/to/your/wasmedge/source/folder>
164+
# Enable METAL on arm64 macOS.
165+
cmake -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Release \
166+
-DWASMEDGE_PLUGIN_WASI_NN_BACKEND="GGML" \
167+
-DWASMEDGE_PLUGIN_WASI_NN_GGML_LLAMA_METAL=ON \
168+
-DWASMEDGE_PLUGIN_WASI_NN_GGML_LLAMA_BLAS=OFF \
169+
.
170+
cmake --build build
171+
# For the WASI-NN plugin, you should install this project.
172+
cmake --install build
173+
```
174+
175+
### Linux
176+
177+
#### Ubuntu/Debian with CUDA 12
178+
179+
Please follow the official guide provided by NVIDIA for installing the CUDA framework: https://developer.nvidia.com/cuda-12-2-0-download-archive
180+
181+
```bash
182+
cd <path/to/your/wasmedge/source/folder>
183+
184+
# You may need to install dependencies
185+
apt update
186+
apt install -y software-properties-common lsb-release \
187+
cmake unzip pkg-config
188+
189+
# Due to cuda-related files, it will produce some warning.
190+
# Disable the warning as an error to avoid failures.
191+
export CXXFLAGS="-Wno-error"
192+
# Please make sure you set up the correct CUDAARCHS.
193+
# We use `60;61;70` for maximum compatibility.
194+
export CUDAARCHS="60;61;70"
195+
196+
# BLAS cannot work with CUBLAS
197+
cmake -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Release \
198+
-DCMAKE_CUDA_ARCHITECTURES="60;61;70" \
199+
-DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc \
200+
-DWASMEDGE_PLUGIN_WASI_NN_BACKEND="GGML" \
201+
-DWASMEDGE_PLUGIN_WASI_NN_GGML_LLAMA_BLAS=OFF \
202+
-DWASMEDGE_PLUGIN_WASI_NN_GGML_LLAMA_CUBLAS=ON \
203+
.
204+
205+
cmake --build build
206+
207+
# For the WASI-NN plugin, you should install this project.
208+
cmake --install build
209+
```
210+
211+
#### Ubuntu on NVIDIA Jetson AGX Orin
212+
213+
You should use the pre-built OS image from the NVIDIA official site.
214+
215+
```bash
216+
cd <path/to/your/wasmedge/source/folder>
217+
218+
# Due to cuda-related files, it will produce some warning.
219+
# Disable the warning as an error to avoid failures.
220+
export CXXFLAGS="-Wno-error"
221+
# Please make sure you set up the correct CUDAARCHS.
222+
# 72 is for NVIDIA Jetson AGX Orin
223+
export CUDAARCHS=72
224+
225+
# BLAS cannot work with CUBLAS
226+
cmake -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Release \
227+
-DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc \
228+
-DWASMEDGE_PLUGIN_WASI_NN_BACKEND="GGML" \
229+
-DWASMEDGE_PLUGIN_WASI_NN_GGML_LLAMA_BLAS=OFF \
230+
-DWASMEDGE_PLUGIN_WASI_NN_GGML_LLAMA_CUBLAS=ON \
231+
.
232+
233+
cmake --build build
234+
235+
# For the WASI-NN plugin, you should install this project.
236+
cmake --install build
237+
```
238+
239+
#### Ubuntu/Debian with OpenBLAS
240+
241+
Please install OpenBLAS before building the plugin.
242+
243+
```bash
244+
cd <path/to/your/wasmedge/source/folder>
245+
246+
# You may need to install dependencies
247+
apt update
248+
apt install -y software-properties-common lsb-release \
249+
cmake unzip pkg-config
250+
# You must install OpenBLAS
251+
apt install libopenblas-dev
252+
253+
cmake -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Release \
254+
-DWASMEDGE_PLUGIN_WASI_NN_BACKEND="GGML" \
255+
-DWASMEDGE_PLUGIN_WASI_NN_GGML_LLAMA_BLAS=ON \
256+
.
257+
258+
cmake --build build
259+
260+
# For the WASI-NN plugin, you should install this project.
261+
cmake --install build
262+
```
263+
264+
#### General Linux without any acceleration framework
265+
266+
```bash
267+
cd <path/to/your/wasmedge/source/folder>
268+
269+
cmake -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Release \
270+
-DWASMEDGE_PLUGIN_WASI_NN_BACKEND="GGML" \
271+
-DWASMEDGE_PLUGIN_WASI_NN_GGML_LLAMA_BLAS=OFF \
272+
.
273+
274+
cmake --build build
275+
276+
# For the WASI-NN plugin, you should install this project.
277+
cmake --install build
278+
```
279+
280+
#### Apple Silicon Model
281+
282+
You can build and install WasmEdge from source directly on the macOS arm64 platform. It will use the built-in GPU by default.
283+
284+
```bash
285+
cd <path/to/your/wasmedge/source/folder>
286+
# Enable METAL on arm64 macOS.
287+
cmake -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Release \
288+
-DWASMEDGE_PLUGIN_WASI_NN_BACKEND="GGML" \
289+
-DWASMEDGE_PLUGIN_WASI_NN_GGML_LLAMA_METAL=ON \
290+
-DWASMEDGE_PLUGIN_WASI_NN_GGML_LLAMA_BLAS=OFF \
291+
.
292+
cmake --build build
293+
# For the WASI-NN plugin, you should install this project.
294+
cmake --install build
295+
```
296+
297+
### Appendix
298+
299+
<!-- prettier-ignore -->
300+
:::note
301+
If the built `wasmedge` CLI tool cannot find the WASI-NN plugin, you can set the `WASMEDGE_PLUGIN_PATH` environment variable to the plugin installation path (such as `/usr/local/lib/wasmedge/` or the built plugin path `build/plugins/wasi_nn/`) to try to fix this issue.
302+
:::
303+
304+
<!-- prettier-ignore -->
305+
:::note
306+
We also provided the pre-built ggml plugins on the following platforms:
307+
- darwin\_x86\_64: Intel Model macOS
308+
- darwin\_arm64: Apple Silicon Model macOS
309+
- ubuntu20.04\_x86\_64: x86\_64 Linux (the glibc is using Ubuntu20.04 one)
310+
- ubuntu20.04\_aarch64: aarch64 Linux (the glibc is using Ubuntu20.04 one)
311+
- ubuntu20.04\_blas\_x86\_64: x86\_64 Linux with OpenBLAS support (the glibc is using Ubuntu20.04 one)
312+
- ubuntu20.04\_blas\_aarch64: aarch64 Linux with OpenBLAS support (the glibc is using Ubuntu20.04 one)
313+
- ubuntu20.04\_cuda\_x86\_64: x86\_64 Linux with CUDA 12 support (the glibc is using Ubuntu20.04 one)
314+
- ubuntu20.04\_cuda\_aarch64: aarch64 Linux with CUDA 11 support (the glibc is using Ubuntu20.04 one), for NVIDIA Jetson AGX Orin
315+
- manylinux2014\_x86\_64: x86\_64 Linux (the glibc is using CentOS 7 one)
316+
- manylinux2014\_aarch64: aarch64 Linux (the glibc is using CentOS 7 one)
317+
:::

0 commit comments

Comments
 (0)