You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/learning-paths/cross-platform/ernie_moe_v9/1_mixture_of_experts.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,15 +20,15 @@ In a typical MoE setup, the model consists of many expert sub-networks (for exam
20
20
21
21
MoE architecture provides several advantages that make it particularly well-suited for edge deployment and large-scale model development:
22
22
23
-
**Scalable model size**: You can increase total parameter count without linearly increasing inference cost, allowing for larger, more capable models within the same resource constraints.
23
+
Scalable model size: you can increase total parameter count without linearly increasing inference cost, allowing for larger, more capable models within the same resource constraints.
24
24
25
-
**Efficient inference**: The architecture requires lower memory and FLOPs per input compared to dense models of equivalent capacity, making real-time applications more feasible.
25
+
Efficient inference: the architecture requires lower memory and FLOPs per input compared to dense models of equivalent capacity, making real-time applications more feasible.
26
26
27
-
**Modularity**: Each expert can learn domain-specific patterns such as finance, medicine, or language, enabling the model to handle diverse tasks without retraining the entire network.
27
+
Modularity: each expert can learn domain-specific patterns such as finance, medicine, or language, enabling the model to handle diverse tasks without retraining the entire network.
28
28
29
-
**Specialization**: The architecture encourages the model to learn distinct processing behaviors across different experts, improving performance on specialized tasks while maintaining general capability.
29
+
Specialization: the architecture encourages the model to learn distinct processing behaviors across different experts, improving performance on specialized tasks while maintaining general capability.
30
30
31
-
**Routing flexibility**: The dynamic expert selection makes it easier to adapt to specific tasks using fine-tuned routing strategies, allowing for task-specific optimizations without modifying the core model.
31
+
Routing flexibility: the dynamic expert selection makes it easier to adapt to specific tasks using fine-tuned routing strategies, allowing for task-specific optimizations without modifying the core model.
Copy file name to clipboardExpand all lines: content/learning-paths/cross-platform/ernie_moe_v9/2_llamacpp_installation.md
+9-7Lines changed: 9 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ weight: 3
4
4
layout: "learningpathall"
5
5
---
6
6
7
-
## Set up llama.cpp on an Armv9 development board
7
+
## Overview
8
8
9
9
In the previous section, you learned how Mixture of Experts (MoE) models reduce resource consumption by activating only a fraction of parameters.
10
10
Now, you'll walk through how to prepare your environment to deploy ERNIE-4.5 models on an Armv9 platform using llama.cpp.
@@ -98,10 +98,10 @@ cd $HOME/llama.cpp/build
98
98
```
99
99
100
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, you 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.
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, you 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
105
106
106
If everything is set up correctly, you see metadata output from llama.cpp indicating the model's architecture and size:
Once inference is complete, the expected output looks like this (in Chinese):
115
115
116
-

116
+

117
117
118
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. The response describes MoE as a model combining multiple specialized sub-models (experts) and a routing mechanism (gateway) to activate only a few experts per input. It explains how routing selects top experts based on input features and how the system reduces computation by activating only a small number of experts per token. The answer also gives examples such as word segmentation and translation, explaining how different experts might focus on distinct subtasks in Chinese NLP applications.
119
119
120
120
This confirms the GGUF model is successfully loaded, the llama.cpp build functions as expected, and CPU-only inference on Armv9 is working.
121
121
122
122
The prompt "Please introduce Mixture of Experts in Chinese." was chosen because it tests two important capabilities. First, it verifies bilingual capability since the instruction is in English but the answer is expected in Chinese, confirming that ERNIE-4.5's multilingual support works correctly. Second, it engages MoE behavior by having the model explain a technical concept in Chinese, which likely activates different experts within the model during inference. Even though routing isn't explicitly logged, the richness and precision of the output suggest that MoE routing functions as designed. This type of prompt increases the likelihood of multiple experts being activated simultaneously, including language generation, machine learning knowledge, and Chinese translation experts.
123
123
124
-
You've now successfully set up llama.cpp on Armv9 hardware, deployed the ERNIE-4.5 model, and confirmed that multilingual inference works correctly. With this foundation in place, you're ready to explore expert routing behavior and benchmark performance optimizations in the next sections.
124
+
## What you've accomplished and what's next
125
+
126
+
You've successfully set up llama.cpp on Armv9 hardware, deployed the ERNIE-4.5 model, and confirmed that multilingual inference works correctly. With this foundation in place, you're ready to explore expert routing behavior and compare model variants in the next section.
Copy file name to clipboardExpand all lines: content/learning-paths/cross-platform/ernie_moe_v9/3_ernie_moe.md
+20-16Lines changed: 20 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,8 +11,8 @@ Now that both ERNIE-4.5 models are installed and verified, you can compare their
11
11
In this section, you compare the inference styles of PT and Thinking models, and learn how to inspect internal MoE expert routing behavior during generation.
12
12
13
13
Both ERNIE-4.5 models share the same MoE architecture and parameter count (around 21 B total, around 3 B activated at runtime), but they're tuned for different objectives:
14
-
- PT: General-purpose model trained on multilingual corpora for versatile tasks
15
-
- Thinking: Tuned for multi-step reasoning, long context, and structured response generation
14
+
- PT: general-purpose model trained on multilingual corpora for versatile tasks
15
+
- Thinking: tuned for multi-step reasoning, long context, and structured response generation
16
16
17
17
You can now observe how these different tuning objectives affect output behavior.
18
18
@@ -41,19 +41,18 @@ Here is the PT variant:
41
41
--jinja
42
42
```
43
43
44
-
The answer looks like this:
44
+
The output is similar to:
45
45
46
46
```output
47
47
Assistant: 1. **Top Motivation**: Achieving visible results and maintaining progress through efficient recovery nutrition.
48
48
**Hidden Pain Point**: Balancing high-intensity training with optimal recovery nutrition during busy workouts.
49
49
2. **New Product Line**: *Smart Recovery Meal Kits* – Customizable, nutrient-dense, and easy-to-prepare post-workout meals designed for quick consumption and recovery optimization.
50
50
3. **Marketing Tagline**: "Fuel Progress, Recover Faster – Smart Nutrition for the Hard Worker."
51
51
```
52
-
53
52
The answer shows:
54
-
-Delivers conclusions directly: motivations and pain points are briefly mentioned with little reasoning.
55
-
-Product ideas are sensible but templated: suggestions like "Smart Recovery Meal Kits" are plausible but lack contextual grounding in user behavior.
56
-
-Tagline reads like a standard advertisement: for example, "Fuel Progress, Recover Faster" feels promotional rather than personalized.
53
+
-Direct conclusions with minimal reasoning
54
+
-Sensible but general product suggestions (such as "Smart Recovery Meal Kits")
55
+
-Standard advertising tone in the tagline ("Fuel Progress, Recover Faster")
57
56
58
57
Here is the Thinking variant:
59
58
@@ -65,7 +64,7 @@ Here is the Thinking variant:
65
64
--jinja
66
65
```
67
66
68
-
You see a more comprehensive answer like this:
67
+
The output is similar to:
69
68
70
69
```output
71
70
assistant
@@ -98,9 +97,9 @@ So to sum up:
98
97
```
99
98
100
99
The answer shows:
101
-
-Responses show deeper layering: begins with inferring user motivation, iterates through possible product strategies, and only then crafts a refined tagline.
102
-
- Transparent reasoning process: the model "thinks out loud" ("let me try again… maybe that's too long…"), mimicking human deliberation.
103
-
-Marketing language reflects user mindset: taglines like "Share. Track. Conquer." directly appeal to community sharing and progress motivation.
100
+
-Deeper layering: the model begins by inferring user motivation, explores multiple product strategies, and then refines the tagline through iteration.
101
+
- Transparent reasoning: the model "thinks out loud" with phrases like "let me try again… maybe that's too long…", mimicking human deliberation.
102
+
-User-focused messaging: taglines like "Share. Track. Conquer." directly appeal to the user's community sharing and progress motivation.
104
103
105
104
### Compare the outputs
106
105
After execution, review the responses and compare them along the following dimensions:
@@ -161,18 +160,23 @@ Run inference with the same prompt and monitor the console for lines like this:
161
160
---[DEBUG]--- entering build_moe_ffn at layer 27 with 64 experts (use 64)
162
161
```
163
162
164
-
This reveals how many experts (for example, 6) and how many tokens (for example, 16) were routed at that layer.
163
+
This output shows that each layer has 64 total experts available. The actual number of experts activated per token (typically 6 for ERNIE-4.5) is determined by the router during inference and isn't directly visible in this debug output.
165
164
166
165
{{% notice Note %}}
167
-
You can also trace the function `llm_graph_context::build_moe_ffn()` in `src/llama-graph.cpp` to see how expert selection works.
166
+
You can also trace the function `llm_graph_context::build_moe_ffn()` in `src/llama-graph.cpp` to see how expert selection works at a deeper level.
168
167
{{% /notice %}}
169
168
170
-
Remove the print statement from `src/models/ernie4-5-moe.cpp` before moving to the next section.
169
+
Remove the print statement from `src/models/ernie4-5-moe.cpp`and rebuild llama.cpp before moving to the next section.
171
170
172
171
As you review the debug output, observe whether the number of active experts changes between the PT and Thinking models. Look for patterns in routing, such as different token batches routing to differing expert sets. You can also correlate routing behavior with output differences, as deeper routing variety might align with more detailed responses.
173
172
174
-
## Summary
173
+
## What you've accomplished and what's next
174
+
175
+
In this section, you:
176
+
- Compared ERNIE-4.5 PT and Thinking model outputs on the same task
177
+
- Observed how fine-tuning affects reasoning depth and response structure
178
+
- Learned how to add debug instrumentation to examine MoE expert routing
175
179
176
-
This task highlights the advantage of MoE fine-tuning. Even with the same architecture, thoughtful tuning can significantly change a model's reasoning behavior. The Thinking model is better suited for applications that need analytical depth, making it ideal for edge AI scenarios like customer profiling or real-time recommendations.
180
+
This comparison highlights the advantage of MoE fine-tuning. Even with the same architecture, thoughtful tuning can significantly change a model's reasoning behavior. The Thinking model is better suited for applications that need analytical depth, making it ideal for edge AI scenarios like customer profiling or real-time recommendations.
177
181
178
182
In the next section, you switch focus from model behavior to system-level performance by compiling with Armv9 instruction sets and measuring the impact on inference speed.
Copy file name to clipboardExpand all lines: content/learning-paths/cross-platform/ernie_moe_v9/4_v9_optimization.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -114,8 +114,8 @@ After running benchmarks with and without Armv9-specific instructions, the resul
114
114
115
115
Vectorized kernels (i8mm, dotprod, SVE) drastically improve inference throughput. The pp512 test shows the most significant acceleration with a 2.57× improvement. Other patterns like tg128 and pp128+tg128 also achieve measurable gains. These results demonstrate the broad benefit of hardware-aware builds and show that Armv9 optimization enables practical real-time inference for 21 B models on edge-class hardware.
116
116
117
-
### Summary
117
+
##What you've accomplished
118
118
119
-
Throughout this Learning Path, you deployed a 21 B parameter Chinese MoE model on edge-class Armv9 hardware. You started by understanding how MoE reduces memory usage by activating only a small subset of parameters per token. After setting up llama.cpp on a Radxa O6 board, you compared ERNIE-4.5 Thinking and PT model behaviors while examining expert routing logic with debug instrumentation. Finally, you applied Armv9 hardware optimizations and achieved over 2.5× speed improvements in token throughput.
119
+
Throughout this Learning Path, you deployed a 21-billion-parameter Chinese MoE model on edge-class Armv9 hardware. You started by understanding how MoE reduces memory usage by activating only a small subset of parameters per token. After setting up llama.cpp on a Radxa O6 board, you compared ERNIE-4.5 Thinking and PT model behaviors while examining expert routing logic with debug instrumentation. Finally, you applied Armv9 hardware optimizations and achieved over 2.5× speed improvements in token throughput.
120
120
121
121
You can now deploy, profile, and tune Chinese LLMs for efficient inference on modern Arm CPUs.
Copy file name to clipboardExpand all lines: content/learning-paths/cross-platform/ernie_moe_v9/_index.md
+2-6Lines changed: 2 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,9 @@
1
1
---
2
2
title: Run ERNIE-4.5 Mixture of Experts model on Armv9 with llama.cpp
3
3
4
-
draft: true
5
-
cascade:
6
-
draft: true
7
-
8
4
minutes_to_complete: 60
9
5
10
-
who_is_this_for: This Learning Path is for developers and engineers who want to deploy Mixture of Experts (MoE) models, such as ERNIE 4.5, on edge devices. MoE architectures allow large LLMs with 21 billion or more parameters to run with only a fraction of their weights active per inference, making them ideal for resource constrained environments.
6
+
who_is_this_for: This is an advanced topic for developers and engineers who want to deploy Mixture of Experts (MoE) models, such as ERNIE 4.5, on edge devices. MoE architectures allow large LLMs with 21 billion or more parameters to run with only a fraction of their weights active per inference, making them ideal for resource constrained environments.
11
7
12
8
learning_objectives:
13
9
- Deploy MoE models like ERNIE-4.5 on edge devices using llama.cpp
0 commit comments