|
| 1 | +--- |
| 2 | +title: Setting Up llama.cpp on Arm v9 develop board |
| 3 | +weight: 3 |
| 4 | +layout: "learningpathall" |
| 5 | +--- |
| 6 | + |
| 7 | +## Setting Up llama.cpp on Arm v9 develop board |
| 8 | + |
| 9 | +In the previous section, you learned how Mixture-of-Experts (MoE) models reduce resource consumption by activating only a fraction of parameters. |
| 10 | +Now, you'll walk through how to prepare your environment to deploy `ERNIE-4.5 MoE` models on an Armv9 platform using `llama.cpp`. |
| 11 | + |
| 12 | +In this module, you’ll verify model inference on Radxa O6 and validate multilingual outputs using ERNIE’s Thinking variant. |
| 13 | + |
| 14 | +This section prepares the foundation for deploying ERNIE-4.5 on an ARMv9 platform. You will begin by reviewing the hardware—specifically, the `Radxa O6` development board equipped with an Armv9 CPU. From there, you will install llama.cpp, a lightweight inference engine, build it from source, and download ERNIE-4.5 models in GGUF format (quantized to Q4 for efficient CPU inference). Finally, you will run a basic inference test to confirm that the environment is properly configured and ready for benchmarking and optimization in the next module. |
| 15 | + |
| 16 | +### Arm v9 development board |
| 17 | + |
| 18 | +In this learning path, we use the [Radxa O6](https://radxa.com/products/orion/o6/) — a compact Armv9 development board powered by the [CIX CD8180](https://en.cixtech.com/Personal-Computing/) SoC. It features: |
| 19 | + |
| 20 | +- 12-core Armv9.2 CPU |
| 21 | +- Support for SVE, dotprod, and i8mm instruction sets |
| 22 | +- Multiple HDMI, PCIe slot with Gen4x8, dual 5Gbps Ethernet Ports and USB-C for I/O expansion |
| 23 | + |
| 24 | +We chose this board because it balances affordability and performance. Most importantly, it supports vector instructions we’ll benchmark later in this path. |
| 25 | + |
| 26 | +The default system image for the board is [Debian](https://docs.radxa.com/en/orion/o6/debian/debian-user-guide), which includes a ready-to-use user environment. You can verify or reflash the OS by following the instructions on the Radxa O6 [download page](https://docs.radxa.com/en/orion/o6/download). |
| 27 | + |
| 28 | +With the Radxa O6 ready, let’s set up the software stack beginning with llama.cpp. |
| 29 | + |
| 30 | +### Step 1: Clone and Build llama.cpp |
| 31 | + |
| 32 | +First, ensure your system is up-to-date and install the required tools and libraries: |
| 33 | + |
| 34 | +```bash |
| 35 | +sudo apt update |
| 36 | +sudo apt install build-essential cmake python3 python3-pip htop |
| 37 | +``` |
| 38 | + |
| 39 | +Next, build [llama.cpp](https://github.com/ggml-org/llama.cpp/), an open-source C++ framework for running and experimenting with large language models. Designed to be lightweight and fast, llama.cpp supports inference on edge devices (CPU-only) and implements many of the most popular LLM architectures. |
| 40 | + |
| 41 | +In the context of MoE models, `llama.cpp` currently supports: |
| 42 | +- Openai-moe |
| 43 | +- Oleo |
| 44 | +- lm4-moe |
| 45 | +- Qwen2 moe, Qwen3 moe |
| 46 | +- Grok |
| 47 | +- Ernie4.5 |
| 48 | + |
| 49 | +These models use diverse routing and expert management strategies, and llama.cpp provides a unified backend for efficient MoE inference. |
| 50 | +For more in-depth coverage of llama.cpp capabilities and use cases, see those [learning paths](https://learn.arm.com/tag/llama.cpp/) for the detail. |
| 51 | + |
| 52 | +```bash |
| 53 | +cd ~ |
| 54 | +git clone https://github.com/ggerganov/llama.cpp.git |
| 55 | +cd llama.cpp |
| 56 | + |
| 57 | +mkdir build && cd build |
| 58 | +cmake .. |
| 59 | +make -j$(nproc) |
| 60 | +``` |
| 61 | + |
| 62 | +This will generate binaries like `llama-cli` under directory `~/llama.cpp/build/bin`, which we’ll use to run inference in later steps. |
| 63 | +Once llama.cpp is compiled, we can now download the models we’ll use for evaluation. |
| 64 | + |
| 65 | + |
| 66 | +### Step 2: Download ERNIE-4.5 Q4 GGUF Model |
| 67 | + |
| 68 | +In this learning path, you will use [ERNIE-4.5](https://huggingface.co/collections/baidu/ernie-45) to deploy in Arm v9. |
| 69 | +Download both model variants so you can experiment later: |
| 70 | + |
| 71 | +```bash |
| 72 | +mkdir -p ~/models/ernie-4.5 |
| 73 | +cd ~/models/ernie-4.5 |
| 74 | +wget https://modelscope.cn/models/unsloth/ERNIE-4.5-21B-A3B-PT-GGUF/resolve/master/ERNIE-4.5-21B-A3B-PT-Q4_0.gguf |
| 75 | +wget https://modelscope.cn/models/unsloth/ERNIE-4.5-21B-A3B-Thinking-GGUF/resolve/master/ERNIE-4.5-21B-A3B-Thinking-Q4_0.gguf |
| 76 | +``` |
| 77 | + |
| 78 | +You can see the size of both models are 12 GB and quantized to Q4, making them suitable for CPU-only inference. |
| 79 | + |
| 80 | +{{% notice Note %}} |
| 81 | +The Q4 quantized models reduce memory footprint and allow CPU‑only inference — you’ll still need around 12 GB of RAM for good performance. |
| 82 | +{{% /notice %}} |
| 83 | + |
| 84 | +While both the Thinking and PT variants of ERNIE-4.5 share the same MoE architecture, they are fine-tuned for different objectives. The Thinking model is optimized for logical reasoning and structured generation, making it the main focus of subsequent benchmarking and hardware optimization. You are encouraged to install both variants and observe behavioral differences using the same prompt. |
| 85 | + |
| 86 | +### Step 3: Run a Basic Inference Test |
| 87 | + |
| 88 | +Navigate to the build directory and run the following command to verify that the model loads correctly and supports multilingual input: |
| 89 | + |
| 90 | +```bash |
| 91 | +cd ~/llama.cpp/build |
| 92 | +./bin/llama-cli \ |
| 93 | + --jinja \ |
| 94 | + -m ~/models/ernie-4.5/ERNIE-4.5-21B-A3B-Thinking-Q4_0.gguf \ |
| 95 | + -p "Please introduce Mixture of Experts in Chinese." \ |
| 96 | + -c 4096 -t 12 \ |
| 97 | + --jinja |
| 98 | +``` |
| 99 | + |
| 100 | +Note the flags: |
| 101 | +- ***-p***: Passes the input prompt directly as a string. |
| 102 | +- ***-c 4096***: Sets the context length (in tokens). A longer context allows the model to “remember” more input text, which is crucial for long-form tasks. Here we use the recommended 4096 tokens. |
| 103 | +- ***-t 12***: Specifies the number of CPU threads used for inference. You should match this number to the physical cores (or logical threads) available on your system to maximize performance. |
| 104 | +- ***--jinja***: Enables Jinja‑style prompt templates. Many Chinese‑oriented MoE models rely on this template format for structured inputs. |
| 105 | + |
| 106 | +If everything is set up correctly, you will see metadata output from llama.cpp indicating the model’s architecture and size: |
| 107 | + |
| 108 | +``` |
| 109 | +print_info: model type = 21B.A3B |
| 110 | +print_info: model params = 21.83 B |
| 111 | +print_info: general.name = Ernie-4.5-21B-A3B-Thinking |
| 112 | +``` |
| 113 | + |
| 114 | +Once inference is complete, the expected output will look like this (in Chinese): |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | +This answer demonstrates the model’s multilingual and structured reasoning ability. It begins with a narrative explanation introducing the concept of Mixture of Experts (MoE), followed by a well-organized markdown-style summary with section headers and bullet points: |
| 119 | +- Concept breakdown: It describes MoE as a model combining multiple specialized sub-models (experts) and a routing mechanism (gateway) to activate only a few experts per input. |
| 120 | +- Workflow explanation: It explains how routing selects top experts based on input features and how the system reduces computation by only activating a small number of experts per token. |
| 121 | +- Chinese NLP examples: It gives examples such as word segmentation and translation, explaining how different experts may focus on distinct subtasks. |
| 122 | + |
| 123 | +This confirms: |
| 124 | +- The GGUF model is successfully loaded. |
| 125 | +- The llama.cpp build functions as expected. |
| 126 | +- CPU-only inference on Armv9 is working. |
| 127 | + |
| 128 | +#### Why This Prompt Matters |
| 129 | + |
| 130 | +This prompt, “Please introduce Mixture of Experts in Chinese.”, was chosen for its dual pedagogical value: |
| 131 | +- ***Bilingual Capability Check***: The instruction is issued in English, but the answer is expected in Chinese. This helps confirm that ERNIE-4.5’s multilingual support is active and effective. |
| 132 | +- ***MoE Behavior Engagement***: The topic itself — explaining “Mixture of Experts” — requires combining multiple sub-skills: technical understanding, translation, and structured explanation. This likely triggers different experts within the model to contribute during inference. Even though routing isn’t explicitly logged, the richness and precision of the output suggest that MoE routing is functioning as designed. This kind of prompt increases the likelihood of multiple experts being activated simultaneously—e.g., language generation, machine learning knowledge, and Chinese translation. |
| 133 | + |
| 134 | +By using a single prompt, you verify setup correctness, observe output quality, and gain insight into MoE inference characteristics — all essential elements before moving on to hardware-specific performance tuning. |
0 commit comments