Deploying LLM with AidGen
Introduction
Deploying a Large Language Model (LLM) on edge devices refers to compressing, quantizing, and deploying large models that originally run in the cloud onto local devices, enabling offline, low-latency natural language understanding and generation. This chapter is based on the AidGen inference engine and demonstrates how to complete the deployment, loading, and conversation process of LLMs on edge devices.
In this case, the large language model inference runs on the device side, and the relevant interfaces are called through C++ code to receive user input and return conversation results in real time.
- Device: IQ9075
- System: Ubuntu 24.04
- Model: Qwen2.5-0.5B-Instruct
Supported Platforms
| Platform | Running Method |
|---|---|
| IQ9075 | Ubuntu 24.04 |
Prerequisites
IQ9075 hardware
Ubuntu 24.04 system
Prepare the model files
Visit Model Farm: Qwen2.5-0.5B-Instruct to download the model resource files
💡Note
Select the QCS9075 chip.
System Dependency Configuration
Configure the AidLux Repository
# Download the correct public key
sudo wget -O- https://archive.aidlux.com/ubuntu24/public.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/private-aidlux.gpg > /dev/null
# Edit the source file
sudo vim /etc/apt/sources.list.d/private-aidlux.list
# Add the private key provided by AidLux to the source file
deb [arch=arm64 signed-by=/etc/apt/trusted.gpg.d/private-aidlux.gpg] https://archive.aidlux.com/ubuntu24 noble main
# Update the cache
sudo apt updateAfter the update, you can obtain the official AidLux SDK dependencies with the following command:
sudo apt list | grep aid | grep unknown# Install software
# Must be installed first; not included with the system
sudo apt install python3 python3-pip libopencv-dev python3-opencv net-tools
# Required before installing aidlite
sudo apt install aidlux-aistack-base aidrtcm
# Install aidlite and its dependencies
sudo apt install aid-lms aidlms-sdk aidlite-sdk cmake
sudo apt-get install libfmt-dev nlohmann-json3-dev
sudo apt install aidlite-*
# Enable DSP support
sudo apt-get install qcom-fastrpc1
sudo apt-get install qcom-fastrpc-dev
# Install the aidgen SDK
sudo apt install aidgen-sdk
sudo apt install aidgen-qnn*
# Install the mms service
sudo apt install aid-mms
# Enable GPU support
sudo apt-add-repository -s ppa:ubuntu-qcom-iot/qcom-ppa
sudo apt install qcom-adreno-cl1
sudo ln -s /usr/lib/aarch64-linux-gnu/libOpenCL.so.1 /usr/lib/aarch64-linux-gnu/libOpenCL.soAfter installation, check that the aidlite and aidgen directories have been added under /usr/local/share.

Device Authorization
Obtain the Device SN Code
cat /sys/devices/soc0/serial_numberObtain the License File
Provide the SN code to the Aplux technical staff to generate a device-specific License file, and place it under /etc/opt/aidlux/license/AidLuxLics.
Activate Authorization
sudo /opt/aidlux/cpf/aid-lms/manager.sh restartCase Deployment
Step 1: Copy the AidGen SDK Code Examples
# Copy the test code
cd /home/ubuntu/aidllm
cp -r /usr/local/share/aidgen/examples/ ./Step 2: Upload & Unzip the Model Resources
Upload the downloaded model resources to the edge device.
Unzip the model resources to the
/home/ubuntu/aidllmdirectory:
cd /home/ubuntu/aidllm
unzip qnn229_qcs9075_cl4096.zipStep 3: Confirm Resource Files
The file distribution is as follows:
/home/ubuntu/aidllm/qnn229_qcs9075_cl4096
├── tokenizer_config.json
├── tokenizer.json
├── qwen2.5-0.5b-instruct_qnn229_qcs9075_4096_2_of_2.serialized.bin
├── qwen2.5-0.5b-instruct_qnn229_qcs9075_4096_1_of_2.serialized.bin
├── qwen2.5-0.5b-instruct-tokenizer.json
├── qwen2.5-0.5b-instruct-htp.json
├── prompt.conf
├── metadata.json
├── htp_backend_ext_config.json
├── genie_config.json
├── config_linux.json
├── chat.txt
├── aidgen_config.json
├── aidgen_chat_template.txtStep 4: Set the Conversation Template
💡Note
For the conversation template, refer to the aidgen_chat_template.txt file in the model resource package.
Modify the test_aidgen_t2t.cpp file according to the large model's template:
// ========================================================================
// 5. Build the prompt template (Qwen2 format)
// ========================================================================
std::string system_prompt =
"<|im_start|>system\n"
"You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n";
auto make_user_turn = [](const std::string& text) -> std::string {
return "<|im_start|>user\n" + text + "<|im_end|>\n<|im_start|>assistant\n";
};Step 5: Compile and Run
cd /home/ubuntu/aidllm/examples
# Compile
mkdir build && cd build
cmake .. && make
cp test_t2t ../../qnn229_qcs9075_cl4096
cd /home/ubuntu/aidllm/qnn229_qcs9075_cl4096
./test_t2t aidgen_config.json 'Introduce large language models' qnn240- After the model runs successfully, the following log output is displayed:
============================================================
Turn 1: Single-turn inference
============================================================
User: Introduce large language models
Assistant: [API] Generator::run(prompt, callback)
[BOS]Large language models are an artificial intelligence technology that can simulate human thinking and behavior. In large language models, we can see many advanced algorithms and technologies, such as deep learning and neural networks. These technologies enable machines to make complex decisions and reason, in order to achieve better results. In addition, large language models can also understand and generate natural language through natural language processing, which enables them to have more natural conversations with humans.
In general, large language models are a powerful tool that can help us better understand and predict natural language, thereby improving our intelligence.<|im_end|>[EOS]
--- Turn 1 Performance (Generator::get_profiler) ---
Init Time (us): 1468335
Prompt Token Count: 33
Time-to-First-Token (us): 32404
Prompt TPS (tok/s): 1975.06
Generated Token Count: 105
Generate Time (us): 1065709
Generate TPS (tok/s): 98.526