Skip to content

Commit b50795f

Browse files
committed
Update documents.
1 parent a25a576 commit b50795f

File tree

20 files changed

+130
-1297
lines changed

20 files changed

+130
-1297
lines changed

docs/python_arm64.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,54 @@
1-
Using the Python extensions with ARM64 Python will make it easier for developers to build GUI app for Windows on Snapdragon(WoS) platforms. Python 3.12.6 ARM64 version has support for following modules: PyQt6, OpenCV, Numpy, PyTorch*, Torchvision*, ONNX*, ONNX Runtime*. Developers can design apps that benefit from rich Python ecosystem. <br>
1+
### 1. Intruduction:
22

3-
**PyTorch, Torchvision, ONNX, ONNX Runtime: need to compile from source code.* <br>
3+
Using the Python extensions with ARM64 Python will get better performance for developers to build GUI app for Windows on Snapdragon(WoS) platforms. Python 3.12.6 ARM64 version has support for following modules: PyQt6, OpenCV, Numpy, PyTorch*, Torchvision*, ONNX*, ONNX Runtime*. <br>
44

5+
**PyTorch, Torchvision, ONNX, ONNX Runtime: need to compile from source code today.* <br>
6+
7+
### 2. Python and common python extensions:
8+
Get ARM64 version 'python-3.12.6-arm64.exe' from below link and install it. Make sure to add Python to your PATH environment.
9+
https://www.python.org/ftp/python/3.12.6/python-3.12.6-arm64.exe
10+
11+
Get common Python extensions such as OpenCV, NumPy, Pillow from here:
12+
https://github.com/cgohlke/win_arm64-wheels/releases/download/v2024.6.15/2024.6.15-experimental-cp312-win_arm64.whl.zip
13+
Please to use numpy-1.26.4, do not use numpy-2.0.0.
14+
```
15+
pip install numpy-1.26.4-cp312-cp312-win_arm64.whl
16+
pip install opencv_python_headless-4.10.0.82-cp39-abi3-win_arm64.whl
17+
pip install pillow-10.3.0-cp312-cp312-win_arm64.whl
18+
```
19+
20+
Get PyQt6 from here, refer to the *Notes* below on compiling PyQt6_sip:
21+
https://github.com/RockLakeGrass/Windows-on-ARM64-Toolchain/tree/main/Python/packages/PyQt/PyQt6
22+
23+
### 3. PyTorch, TorchVision, ONNX, ONNX Runtime:
24+
If need these Python extensioins for ARM64 Python, you need compile them by yourselves. If need support on how to compile them, you can contact with us.
25+
26+
### 4. MSVC library:
27+
You need ARM64 version 'msvcp140.dll' from 'Microsoft Visual C++ 2022 Redistributable (Arm64)'. You can download it from here and install it:
28+
https://aka.ms/arm64previewredist/
29+
30+
### 5. Notes: <br>
31+
a. For C++(Visual Studio) projects, you need to set 'Runtime Library' to 'Multi-threaded DLL (/MD)'. Please refer to below link for detailed information:
32+
https://learn.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=msvc-170
33+
34+
b. Plese use the API *LogLevel.SetLogLevel()* for Python and *SetLogLevel()* for C++ to initialize the log function before you call any other APIs.
35+
36+
c. If using Python 3.11.5, get OpenCV from here:
37+
https://github.com/RockLakeGrass/Windows-on-ARM64-Toolchain/tree/main/Python/packages/opencv-python
38+
39+
d. PyQt6 install:
40+
If using Python 3.12.6, you perhaps need to setup compile environment according to below link for compiling PyQt6_sip: 13.4.0:
41+
https://github.com/quic/ai-engine-direct-helper/tree/main?tab=readme-ov-file#build
42+
43+
Steps to install PyQt6 for Python 3.12.6:
44+
1. Download PyQt6-6.3.1-cp37-abi3-win_arm64.whl & PyQt6_Qt6-6.3.1-py3-none-win_arm64.whl from below link:
45+
https://github.com/RockLakeGrass/Windows-on-ARM64-Toolchain/tree/main/Python/packages/PyQt/PyQt6/PyQt6-6.3.1
46+
2. Use below commands to install PyQt6:
47+
48+
```
49+
pip install PyQt6-6.3.1-cp37-abi3-win_arm64.whl
50+
pip install PyQt6_Qt6-6.3.1-py3-none-win_arm64.whl
51+
pip install PyQt6_sip==13.4.0
52+
```
53+
You can get PyQt6_sip for Python 3.11.5 from here directly:
54+
https://github.com/RockLakeGrass/Windows-on-ARM64-Toolchain/blob/main/Python/packages/PyQt/PyQt6/PyQt6-sip/PyQt6_sip-13.4.0-cp311-cp311-win_arm64.whl

docs/user_guide.md

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -29,56 +29,8 @@ C:\Qualcomm\AIStack\QAIRT\{SDK Version}\lib\hexagon-v73\unsigned\libqnnhtpv73.ca
2929
```
3030

3131
We can copy these libraries to one folder. E.g.: ```C:\<Project Name>\qnn\``` <br>
32-
33-
### 2. Python and common python extensions:
34-
Get ARM64 version 'python-3.12.6-arm64.exe' from below link and install it. Make sure to add Python to your PATH environment.
35-
https://www.python.org/ftp/python/3.12.6/python-3.12.6-arm64.exe
36-
37-
Get common Python extensions such as OpenCV, NumPy, Pillow from here:
38-
https://github.com/cgohlke/win_arm64-wheels/releases/download/v2024.6.15/2024.6.15-experimental-cp312-win_arm64.whl.zip
39-
Please to use numpy-1.26.4, do not use numpy-2.0.0.
40-
```
41-
pip install numpy-1.26.4-cp312-cp312-win_arm64.whl
42-
pip install opencv_python_headless-4.10.0.82-cp39-abi3-win_arm64.whl
43-
pip install pillow-10.3.0-cp312-cp312-win_arm64.whl
44-
```
45-
46-
Get PyQt6 from here, refer to the *Notes* below on compiling PyQt6_sip:
47-
https://github.com/RockLakeGrass/Windows-on-ARM64-Toolchain/tree/main/Python/packages/PyQt/PyQt6
48-
49-
### 3. PyTorch, TorchVision, ONNX, ONNX Runtime:
50-
If need these Python extensioins for ARM64 Python, you need compile them by yourselves. If need support on how to compile them, you can contact with us.
51-
52-
### 4. MSVC library:
53-
You need ARM64 version 'msvcp140.dll' from 'Microsoft Visual C++ 2022 Redistributable (Arm64)'. You can download it from here and install it:
54-
https://aka.ms/arm64previewredist/
55-
56-
### 5. Notes: <br>
57-
a. For C++(Visual Studio) projects, you need to set 'Runtime Library' to 'Multi-threaded DLL (/MD)'. Please refer to below link for detailed information:
58-
https://learn.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=msvc-170
59-
60-
b. Plese use the API *LogLevel.SetLogLevel()* for Python and *SetLogLevel()* for C++ to initialize the log function before you call any other APIs.
61-
62-
c. If using Python 3.11.5, get OpenCV from here:
63-
https://github.com/RockLakeGrass/Windows-on-ARM64-Toolchain/tree/main/Python/packages/opencv-python
64-
65-
d. PyQt6 install:
66-
If using Python 3.12.6, you perhaps need to setup compile environment according to below link for compiling PyQt6_sip: 13.4.0:
67-
https://github.com/quic/ai-engine-direct-helper/tree/main?tab=readme-ov-file#build
68-
69-
Steps to install PyQt6 for Python 3.12.6:
70-
1. Download PyQt6-6.3.1-cp37-abi3-win_arm64.whl & PyQt6_Qt6-6.3.1-py3-none-win_arm64.whl from below link:
71-
https://github.com/RockLakeGrass/Windows-on-ARM64-Toolchain/tree/main/Python/packages/PyQt/PyQt6/PyQt6-6.3.1
72-
2. Use below commands to install PyQt6:
73-
74-
```
75-
pip install PyQt6-6.3.1-cp37-abi3-win_arm64.whl
76-
pip install PyQt6_Qt6-6.3.1-py3-none-win_arm64.whl
77-
pip install PyQt6_sip==13.4.0
78-
```
79-
You can get PyQt6_sip for Python 3.11.5 from here directly:
80-
https://github.com/RockLakeGrass/Windows-on-ARM64-Toolchain/blob/main/Python/packages/PyQt/PyQt6/PyQt6-sip/PyQt6_sip-13.4.0-cp311-cp311-win_arm64.whl
81-
32+
* [python.md](python.md) can help setup the x64 Python environment automatically.
33+
* In WoS platform, ARM64 Python has better performance, but some Python extensions such as 'PyTorch' don't work for ARM64 Python today. For detailed help information on how to setup environment for using ARM64 Python, you can refer to [python_arm64.md](python_arm64.md)
8234

8335
## API from AppBuilder Python binding extension for Python projects.<br>
8436
There're several Python classes from this extension:

samples/genie/c++/BUILD.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Source code
2+
## Service:
3+
The code under this folder is C++ implementation of the service. It can be compiled to Windows, Android and Linux target.
4+
5+
## Android:
6+
The code under this folder is Android app which can be used to launch the service in Android device.
7+
8+
## Build Service from source code:
9+
10+
### Build GenieAPIServer for WoS:<br>
11+
Install Qualcomm® AI Runtime SDK, CMake, Visual Studio etc, before you compile this service.<br>
12+
```
13+
Set QNN_SDK_ROOT=C:\Qualcomm\AIStack\QAIRT\2.34.0.250424\
14+
cd samples\genie\c++\Service
15+
mkdir build && cd build
16+
cmake -S .. -B . -A ARM64
17+
cmake --build . --config Release
18+
```
19+
20+
### Build GenieAPIServer for Android: <br>
21+
Install Qualcomm® AI Runtime SDK, Android NDK etc, before you compile this service.<br>
22+
```
23+
Set QNN_SDK_ROOT=C:\Qualcomm\AIStack\QAIRT\2.34.0.250424\
24+
set PATH=%PATH%;C:\Programs\android-ndk-r26d\toolchains\llvm\prebuilt\windows-x86_64\bin
25+
Set NDK_ROOT=C:/Programs/android-ndk-r26d/
26+
Set ANDROID_NDK_ROOT=%NDK_ROOT%
27+
28+
"C:\Programs\android-ndk-r26d\prebuilt\windows-x86_64\bin\make.exe" android
29+
```
30+
31+
### Build Android app:<br>
32+
You can install Android Studio for build the Android app.

samples/genie/c++/README.md

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,71 @@
11
# README
22

33
## Introduction
4-
This sample helps developers use C++ to build Genie based Open AI compatibility API service on Windows on Snapdragon (WoS), Mobile, Linux platforms.
4+
This sample helps developers use C++ to build Genie based Open AI compatibility API service on Windows on Snapdragon (WoS), Mobile and Linux platforms.
55

66
# GenieAPIService
77
Genie OpenAI Compatible API Service.
88

99
This is an OpenAI compatible API service that can be used to access the Genie AI model.
1010
This service can be used on multiple platforms such as Android, Windows, Linux, etc.
1111

12-
# Source code
13-
## Service:
14-
The code under this folder is C++ implementation of the service. It can be compiled to Windows, Android and Linux target.
15-
16-
## Android:
17-
The code under this folder is Android app which can be used to launch the service in Android device.
18-
19-
## Build Service from source code:
20-
21-
### Build GenieAPIServer for WoS:<br>
22-
Install Qualcomm® AI Runtime SDK, CMake, Visual Studio etc, before you compile this service.<br>
23-
```
24-
Set QNN_SDK_ROOT=C:\Qualcomm\AIStack\QAIRT\2.34.0.250424\
25-
cd samples\genie\c++\Service
26-
mkdir build && cd build
27-
cmake -S .. -B . -A ARM64
28-
cmake --build . --config Release
29-
```
30-
31-
### Build GenieAPIServer for Android: <br>
32-
Install Qualcomm® AI Runtime SDK, Android NDK etc, before you compile this service.<br>
33-
```
34-
Set QNN_SDK_ROOT=C:\Qualcomm\AIStack\QAIRT\2.34.0.250424\
35-
set PATH=%PATH%;C:\Programs\android-ndk-r26d\toolchains\llvm\prebuilt\windows-x86_64\bin
36-
Set NDK_ROOT=C:/Programs/android-ndk-r26d/
37-
Set ANDROID_NDK_ROOT=%NDK_ROOT%
38-
39-
"C:\Programs\android-ndk-r26d\prebuilt\windows-x86_64\bin\make.exe" android
40-
```
41-
4212
### Run the service on WoS: <br>
43-
1. [Setup LLM models](https://github.com/quic/ai-engine-direct-helper/tree/main/samples/genie/python#step-3-download-models-and-tokenizer-files) first before running the service. <br>
44-
2. Download [Pre-build app](https://github.com/quic/ai-engine-direct-helper/releases/download/v2.34.0/GenieAPIService_2.34.zip) and copy "GenieAPIService" folder to path "ai-engine-direct-helper\samples".<br>
45-
3. Run the commands below to launch the Service.
13+
1. [Setup LLM models](https://github.com/quic/ai-engine-direct-helper/tree/main/samples/genie/python#step-3-download-models-and-tokenizer-files) first before running this service. <br>
14+
2. Download [GenieAPIService binary](https://github.com/quic/ai-engine-direct-helper/releases/download/v2.34.0/GenieAPIService_2.34.zip) and copy the subdirectory "GenieAPIService" to path "ai-engine-direct-helper\samples".<br>
15+
3. Run the following commands to launch the Service (Do *not* close this terminal window while service is running).
4616

4717
```
4818
cd ai-engine-direct-helper\samples
4919
GenieAPIService\GenieAPIService.exe -c "genie\python\models\IBM-Granite-v3.1-8B\config.json" -l
5020
```
21+
The service prints the following log, indicating that GenieAPIService started successfully.
22+
```
23+
process_arguments c: genie\python\models\IBM-Granite-v3.1-8B\config.json
24+
process_arguments l: load model
25+
model path: genie\python\models\IBM-Granite-v3.1-8B
26+
model name: IBM-Granite-v3.1-8B
27+
INFO: loading model <<< IBM-Granite-v3.1-8B >>>
28+
[INFO] "Using create From Binary"
29+
[INFO] "Allocated total size = 353404160 across 10 buffers"
30+
SetStopSequence: {
31+
"stop-sequence" : ["<|end_of_text|>", "<|end_of_role|>", "<|start_of_role|>"]
32+
}
33+
INFO: model <<< IBM-Granite-v3.1-8B >>> is ready!
34+
INFO: [TIME] | model load time >> 8103.10 ms
35+
INFO: Service Is Ready Now!
36+
```
5137

5238
### Run the service on Mobile(Snapdragon® 8 Elite Mobile device): <br>
53-
1. Copy GenieModels folder to the root folder of mobile sdcard.<br>
54-
2. Copy your LLM model & tokenizer.json to "/sdcard/GenieModels/qwen2.0_7b"<br>
39+
1. Copy the subdirectory "GenieModels" in the folder "Android" in [GenieAPIService binary](https://github.com/quic/ai-engine-direct-helper/releases/download/v2.34.0/GenieAPIService_2.34.zip) to the root path of mobile sdcard.<br>
40+
2. Copy your QWen QNN model & tokenizer.json to "/sdcard/GenieModels/qwen2.0_7b"<br>
5541
3. Modify the config file "/sdcard/GenieModels/qwen2.0_7b/config.json" if necessary.<br>
5642
4. Install the GenieAPIService.apk to mobile and start it.<br>
43+
* You can also try other models such [IBM-Granite-v3.1-8B-Instruct](https://aihub.qualcomm.com/mobile/models/ibm_granite_v3_1_8b_instruct?domain=Generative+AI&useCase=Text+Generation) which is for "Snapdragon® 8 Elite Mobile" device. You can create a subdirectory in the path "/sdcard/GenieModels/" for your model and customize the "config.json" for your model.
5744

5845
## Client Usage:
59-
The service can be access through http://ip:8910/, it's compatible with OpenAI API.
60-
Here is a Python client sample:
46+
The service can be access through the ip address 'localhost:8910', it's compatible with OpenAI API.
47+
Here is a Python client sample (You can run this Python client in a new terminal window):
48+
6149
```
6250
import argparse
6351
from openai import OpenAI
6452
65-
HOST="localhost"
66-
PORT="8910"
53+
IP_ADDR = "localhost:8910"
6754
6855
parser = argparse.ArgumentParser()
6956
parser.add_argument("--stream", action="store_true")
7057
parser.add_argument("--prompt", default="Hello", type=str)
7158
args = parser.parse_args()
7259
73-
client = OpenAI(base_url="http://" + HOST + ":" + PORT + "/v1", api_key="123")
60+
client = OpenAI(base_url="http://" + IP_ADDR + "/v1", api_key="123")
7461
7562
model_lst = client.models.list()
7663
print(model_lst)
7764
7865
messages = [{"role": "system", "content": "You are a math teacher who teaches algebra."}, {"role": "user", "content": args.prompt}]
7966
extra_body = {"size": 4096, "temp": 1.5, "top_k": 13, "top_p": 0.6}
8067
81-
model_name = "qwen2.0_7b"
68+
model_name = "IBM-Granite-v3.1-8B"
8269
8370
if args.stream:
8471
response = client.chat.completions.create(model=model_name, stream=True, messages=messages, extra_body=extra_body)
@@ -90,4 +77,4 @@ if args.stream:
9077
else:
9178
response = client.chat.completions.create(model=model_name, messages=messages, extra_body=extra_body)
9279
print(response.choices[0].message.content)
93-
```
80+
```

samples/genie/python/README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,36 @@ pip install uvicorn pydantic_settings fastapi langchain langchain_core langchain
1515
```
1616

1717
### Step 3: Download models and tokenizer files
18-
Download files for the models listed at the end of this page, save them to following path. Need to unzip the 'weight_sharing_model_N_of_N.serialized.bin' files from model package to following path.
18+
Download files for the [AI-Hub LLM models](https://github.com/quic/ai-engine-direct-helper/tree/main/samples/genie/python#ai-hub-llm-models) list at the end of this page, save them to following path. You need to unzip the 'weight_sharing_model_N_of_N.serialized.bin' files from model package to following path. Copy the corresponding 'tokenizer.json' file to the following directory path too.
1919
```
20-
ai-engine-direct-helper\samples\genie\python\models\<model folder>
20+
ai-engine-direct-helper\samples\genie\python\models\<model name>
2121
```
2222
If you want to modify the relative path of the directory where the model file is located, you need to modify the "config.json" file in the corresponding directory of the model to ensure that the tokenizer.json, htp_backend_ext_config.json and model files set in the configuration file can be found correctly.
2323
```
24-
ai-engine-direct-helper\samples\genie\python\models\<model folder>\config.json
24+
ai-engine-direct-helper\samples\genie\python\models\<model name>\config.json
2525
```
26+
* You can also use your own QNN LLM model (if you have one). You can create a subdirectory in the path "ai-engine-direct-helper\samples\genie\python\models\" for your model and customize the "config.json" for your model. Then use your model name in the client application.
2627

27-
### Step 4: Switch to webui directory
28+
### Step 4: Switch to samples directory
2829
Run following commands in Windows terminal:
2930
```
3031
cd ai-engine-direct-helper\samples
3132
```
3233

3334
### Step 5: Run service
34-
Run the following commands to launch Genie API Service:
35+
Run the following commands to launch Genie API Service (Do *not* close this terminal window while service is running)
3536
```
3637
python genie\python\GenieAPIService.py
3738
```
3839

3940
### Step 6: Now you can access the API service
40-
The default IP address for this API is: [http://localhost:8910](http://localhost:8910)
41-
You can try using the following commands to generate text or image:
41+
The default IP address for this API is: 'localhost:8910', you can access this IP address in the client app.
42+
You can try using the following commands to generate text or image (You can run these Python in a new terminal window):
4243
```
43-
python genie\python\GenieAPIClient.py --prompt "<Your query>" --stream
44-
python genie\python\GenieAPIClientImage.py --prompt "<Your prompt>"
44+
python genie\python\GenieAPIClient.py --prompt "How to fish?" --stream
45+
python genie\python\GenieAPIClientImage.py --prompt "spectacular view of northern lights from Alaska"
4546
```
47+
When you run the client, you can see the current status of processing client requests from the server. When you run the request of image generation for the first time, the server may have to download the Stable Diffusion model from AI-Hub, and it will take a long time.
4648

4749
### AI-Hub LLM models:
4850

samples/python/aotgan/README.md

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,3 @@
22

33
## Introduction
44
This is sample code for using AppBuilder to load aotgan QNN model to HTP and execute inference to erase and in-paint part of given input image.
5-
6-
## Setup AppBuilder environment and prepare QNN SDK libraries by referring to the links below:
7-
https://github.com/quic/ai-engine-direct-helper/blob/main/README.md
8-
https://github.com/quic/ai-engine-direct-helper/blob/main/Docs/User_Guide.md
9-
10-
Copy the QNN libraries from QNN SDK to below path:
11-
```
12-
C:\ai-hub\aotgan\qai_libs\libQnnHtpV73Skel.so
13-
C:\ai-hub\aotgan\qai_libs\QnnHtp.dll
14-
C:\ai-hub\aotgan\qai_libs\QnnHtpV73Stub.dll
15-
C:\ai-hub\aotgan\qai_libs\QnnSystem.dll
16-
C:\ai-hub\aotgan\qai_libs\libqnnhtpv73.cat
17-
```
18-
19-
## aotgan QNN models
20-
Download the quantized aotgan QNN models from Qualcomm® AI Hub:
21-
https://aihub.qualcomm.com/compute/models/aotgan
22-
23-
After downloaded the model, copy it to the following path:
24-
```
25-
"C:\ai-hub\aotgan\models\aotgan.bin"
26-
```
27-
28-
## Run the sample code
29-
Download the sample code from the following link:
30-
https://github.com/quic/ai-engine-direct-helper/blob/main/Samples/aotgan/aotgan.py
31-
32-
After downloaded the sample code, please copy it to the following path:
33-
```
34-
C:\ai-hub\aotgan\
35-
```
36-
37-
Copy one sample 512x512 image and mask to following path:
38-
```
39-
C:\ai-hub\aotgan\test_input_image.png
40-
C:\ai-hub\aotgan\test_input_mask.png
41-
```
42-
43-
Run the sample code:
44-
```
45-
python aotgan.py
46-
```
47-
48-
## Output
49-
The output image will be saved to the following path:
50-
```
51-
C:\ai-hub\aotgan\out.png
52-
```
53-
54-
## Reference
55-
You need to setup the AppBuilder environment before you run the sample code. Below is the guide on how to setup the AppBuilder environment:
56-
https://github.com/quic/ai-engine-direct-helper/blob/main/README.md
57-
https://github.com/quic/ai-engine-direct-helper/blob/main/Docs/User_Guide.md
58-
59-

0 commit comments

Comments
 (0)