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/servers-and-cloud-computing/llama_cpp_streamline/1_overview.md
+10-15Lines changed: 10 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,26 +6,21 @@ weight: 2
6
6
layout: learningpathall
7
7
---
8
8
9
-
## Overview: Profiling LLMs on Arm CPUs with Streamline
9
+
## Profiling LLMs on Arm CPUs with Streamline
10
10
11
-
Large Language Models (LLMs) run efficiently on Arm CPUs.
12
-
Frameworks that run LLMs, such as [**llama.cpp**](https://github.com/ggml-org/llama.cpp), provides a convenient framework for running LLMs, it also comes with a certain level of complexity.
11
+
Deploying Large Language Models (LLMs) on Arm CPUs provides a power-efficient and flexible solution. While larger models may benefit from GPU acceleration, techniques like quantization enable a wide range of LLMs to perform effectively on CPUs alone.
12
+
13
+
Frameworks such as [**llama.cpp**](https://github.com/ggml-org/llama.cpp), provide a convenient way to run LLMs, but it also comes with a certain level of complexity.
13
14
14
15
To analyze their execution and use profiling insights for optimization, you need both a basic understanding of transformer architectures and the right analysis tools.
15
16
16
-
This learning path demonstrates how to use the **llama-cli** application from llama.cpp together with **Arm Streamline** to analyze the efficiency of LLM inference on Arm CPUs.
17
+
This Learning Path demonstrates how to use `llama-cli` application from llama.cpp together with Arm Streamline to analyze the efficiency of LLM inference on Arm CPUs.
17
18
18
-
In this guide you will learn how to:
19
-
- Profile token generation at the **Prefill** and **Decode** stages
19
+
You will learn how to:
20
+
- Profile token generation at the Prefill and Decode stages
20
21
- Profile execution of individual tensor nodes and operators
21
-
- Profile LLM execution across **multiple threads and cores**
22
+
- Profile LLM execution across multiple threads and cores
22
23
23
-
You will run the **Qwen1_5-0_5b-chat-q4_0.gguf** model with llama-cli on **Arm64 Linux** and use Streamline for analysis.
24
-
The same method can also be applied to **Arm64 Android** platforms.
24
+
You will run the `Qwen1_5-0_5b-chat-q4_0.gguf` model using `llama-cli` on Arm Linux and use Streamline for analysis.
25
25
26
-
## Prerequisites
27
-
Before starting this guide, you should be familiar with:
28
-
- Basic understanding of llama.cpp
29
-
- Understanding of transformer model
30
-
- Knowledge of Streamline usage
31
-
- An Arm Neoverse or Cortex-A hardware platform running Linux or Android to test the application
26
+
The same method can also be applied to Android platforms.
- Build a **compute graph** based on the model structure
22
-
- The graph can be divided into subgraphs, each assigned to the most suitable backend device
23
-
- In this guide, all operators are executed on the **CPU backend**
24
-
- Allocate memory for tensor nodes using the **graph planner**
25
-
- Execute tensor nodes in the graph during the **graph_compute** stage, which traverses nodes and forwards work to backend devices
20
+
### What does the Llama CLI do?
21
+
22
+
Here are the steps performed by `llama-cli`:
23
+
24
+
1. Load and interpret LLMs in GGUF format
25
+
26
+
2. Build a compute graph based on the model structure
27
+
28
+
The graph can be divided into subgraphs, each assigned to the most suitable backend device, but in this Learning Path all operations are executed on the Arm CPU backend.
29
+
30
+
3. Allocate memory for tensor nodes using the graph planner
26
31
27
-
Step2 to Step4 are wrapped inside the function **`llama_decode`**.
28
-
During **Prefill** and **Decode**, `llama-cli` repeatedly calls `llama_decode` to generate tokens.
29
-
The parameter **`llama_batch`** passed to `llama_decode` differs between stages, containing input tokens, their count, and their positions.
32
+
4. Execute tensor nodes in the graph during the `graph_compute` stage, which traverses nodes and forwards work to backend devices
33
+
34
+
Steps 2 to 4 are wrapped inside the function `llama_decode`.
35
+
During Prefill and Decode, `llama-cli` repeatedly calls `llama_decode` to generate tokens.
36
+
37
+
The parameter `llama_batch` passed to `llama_decode` differs between stages, containing input tokens, their count, and their positions.
llama.cpp supports various backends such as `CPU`, `GPU`, `CUDA`, and `OpenCL`.
46
+
47
+
For the CPU backend, it provides an optimized `ggml-cpu` library, mainly utilizing CPU vector instructions.
48
+
49
+
For Arm CPUs, the `ggml-cpu` library also offers an `aarch64` trait that leverages 8-bit integer multiply (i8mm) instructions for acceleration.
36
50
37
-
For the CPU backend, it provides an optimized `ggml-cpu` library (mainly utilizing CPU vector instructions).
38
-
For Arm CPUs, the `ggml-cpu` library also offers an `aarch64` trait that leverages the new **I8MM** instructions for acceleration.
39
51
The `ggml-cpu` library also integrates the Arm [KleidiAI](https://github.com/ARM-software/kleidiai) library as an additional trait.
40
52
41
53
### Prefill and Decode in autoregressive LLMs
42
-
Most autoregressive LLMs are Decoder-only model.
43
-
Here is a brief introduction to Prefill and Decode stage of autoregressive LLMs.
44
-

54
+
55
+
An autoregressive LLM is a type of Large Language Model that generates text by predicting the next token (word or word piece) in a sequence based on all the previously generated tokens.
56
+
57
+
The term "autoregressive" means the model uses its own previous outputs as inputs for generating subsequent outputs, creating a sequential generation process.
58
+
59
+
For example, when generating the sentence "The cat sat on the", an autoregressive LLM:
60
+
1. Takes the input prompt as context
61
+
2. Predicts the next most likely token (e.g., "mat")
62
+
3. Uses the entire sequence including "mat" to predict the following token
63
+
4. Continues this process token by token until completion
64
+
65
+
This sequential nature is why autoregressive LLMs have two distinct computational phases: Prefill (processing the initial prompt) and Decode (generating tokens one by one).
66
+
67
+
Most autoregressive LLMs are Decoder-only models. This refers to the transformer architecture they use, which consists only of decoder blocks from the original Transformer paper. The alternatives to decoder-only models include encoder-only models used for tasks like classification and encoder-decoder models used for tasks like translation.
68
+
69
+
Decoder-only models like LLaMA have become dominant for text generation because they are simpler to train at scale, can handle both understanding and generation tasks, and are more efficient for text generation.
70
+
71
+
Here is a brief introduction to Prefill and Decode stages of autoregressive LLMs.
72
+

45
73
46
74
At the Prefill stage, multiple input tokens of the prompt are processed.
47
-
It mainly performs GEMM (A matrix is multiplied by another matrix) operations to generate the first output token.
75
+
76
+
It mainly performs GEMM (a matrix is multiplied by another matrix) operations to generate the first output token.
At the Decode stage, by utilizing the [KV cache](https://huggingface.co/blog/not-lain/kv-caching), it mainly performs GEMV (A vector is multiplied by a matrix) operations to generate subsequent output tokens one by one.
80
+
At the Decode stage, by utilizing the [KV cache](https://huggingface.co/blog/not-lain/kv-caching), it mainly performs GEMV (a vector is multiplied by a matrix) operations to generate subsequent output tokens one by one.
Copy file name to clipboardExpand all lines: content/learning-paths/servers-and-cloud-computing/llama_cpp_streamline/3_llama.cpp_annotation.md
+37-35Lines changed: 37 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,36 +1,40 @@
1
1
---
2
-
title: Integrating Streamline Annotations into llama.cpp
2
+
title: Integrate Streamline Annotations into llama.cpp
3
3
weight: 4
4
4
5
5
### FIXED, DO NOT MODIFY
6
6
layout: learningpathall
7
7
---
8
8
9
-
## Integrating Streamline Annotations into llama.cpp
9
+
## Integrate Streamline Annotations into llama.cpp
10
10
11
-
To visualize token generation at the **Prefill** and **Decode** stages, we use **Streamline’s Annotation Marker** feature.
12
-
This requires integrating annotation support into the **llama.cpp** project.
13
-
More information about the Annotation Marker API can be found [here](https://developer.arm.com/documentation/101816/9-7/Annotate-your-code?lang=en).
11
+
To visualize token generation at the Prefill and Decode stages, you can use Streamline's Annotation Marker feature.
12
+
13
+
This requires integrating annotation support into the llama.cpp project.
14
+
15
+
More information about the Annotation Marker API can be found in the [Streamline User Guide](https://developer.arm.com/documentation/101816/9-7/Annotate-your-code?lang=en).
14
16
15
17
{{% notice Note %}}
16
-
You can either build natively on an **Arm platform**, or cross-compile on another architecture using an Arm cross-compiler toolchain.
18
+
You can either build natively on an Arm platform, or cross-compile on another architecture using an Arm cross-compiler toolchain.
17
19
{{% /notice %}}
18
20
19
21
### Step 1: Build Streamline Annotation library
20
22
21
23
Install [Arm DS](https://developer.arm.com/Tools%20and%20Software/Arm%20Development%20Studio) or [Arm Streamline](https://developer.arm.com/Tools%20and%20Software/Streamline%20Performance%20Analyzer) on your development machine first.
22
24
23
-
Streamline Annotation support code in the installation directory such as *"Arm\Development Studio 2024.1\sw\streamline\gator\annotate"*.
25
+
Streamline Annotation support code is in the installation directory such as `Arm/Development Studio 2024.1/sw/streamline/gator/annotate`.
24
26
25
-
For installation guidance, refer to the [Streamline installation guide](https://learn.arm.com/install-guides/streamline/).
27
+
For installation guidance, refer to the [Streamline installation guide](/install-guides/streamline/).
26
28
27
29
Clone the gator repository that matches your Streamline version and build the `Annotation support library`.
28
30
29
-
The installation step is depends on your development machine.
31
+
The installation step depends on your development machine.
32
+
33
+
For Arm native build, you can use the following instructions to install the packages.
30
34
31
-
For Arm native build, you can use following insturction to install the packages.
32
-
For other machine, you need to set up the cross compiler environment by install [aarch64 gcc compiler toolchain](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads).
33
-
You can refer this [guide](https://learn.arm.com/install-guides/gcc/cross/) for Cross-compiler installation.
35
+
For other machines, you need to set up the cross compiler environment by installing [Arm GNU toolchain](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads).
36
+
37
+
You can refer to the [GCC install guide](https://learn.arm.com/install-guides/gcc/cross/) for cross-compiler installation.
make CROSS_COMPILE=/path/to/aarch64_linux_gcc_tool
55
57
{{< /tab >}}
56
58
{{< /tabpane >}}
57
59
58
-
Once complete, the static library **libstreamline_annotate.a** will be generated at `~/gator/annotate/libstreamline_annotate.a` and the header file at:`gator/annotate/streamline_annotate.h`
60
+
Once complete, the static library `libstreamline_annotate.a` will be generated at `~/gator/annotate/libstreamline_annotate.a` and the header file is at`gator/annotate/streamline_annotate.h`.
59
61
60
62
### Step 2: Integrate Annotation Marker into llama.cpp
61
63
62
-
Next, we need to install **llama.cpp** to run the LLM model.
63
-
To make the following performance profiling content easier to follow, this Learning Path will use a specific release version of llama.cpp to ensure the steps and results remain consistent.
64
+
Next, you need to install llama.cpp to run the LLM model.
64
65
65
-
Before the build **llama.cpp**, create a directory `streamline_annotation` and copy the library `libstreamline_annotate.a` and the header file `streamline_annotate.h` into the folder.
66
+
{{% notice Note %}}
67
+
To make the performance profiling content easier to follow, this Learning Path uses a specific release version of llama.cpp to ensure the steps and results remain consistent.
68
+
{{% /notice %}}
69
+
70
+
Before building llama.cpp, create a directory `streamline_annotation` and copy the library `libstreamline_annotate.a` and the header file `streamline_annotate.h` into the new directory.
@@ -174,23 +179,20 @@ Then configure the project by running
174
179
{{< /tabpane >}}
175
180
176
181
177
-
Set `CMAKE_C_COMPILER` and `DCMAKE_CXX_COMPILER` to your cross compiler path. Make sure that **-march** in `DCMAKE_C_FLAGS` and `CMAKE_CXX_FLAGS` matches your Arm CPU hardware.
182
+
Set `CMAKE_C_COMPILER` and `CMAKE_CXX_COMPILER` to your cross compiler path. Make sure that -march in `CMAKE_C_FLAGS` and `CMAKE_CXX_FLAGS` matches your Arm CPU hardware.
178
183
179
184
180
-
In this learning path, we run llama-cli on an Arm CPU that supports **NEON Dotprod** and **I8MM** instructions.
181
-
Therefore, we specify: **armv8.2-a+dotprod+i8mm**.
185
+
With the flags above you can run `llama-cli` on an Arm CPU that supports NEON dot product and 8-bit integer multiply (i8mm) instructions.
182
186
183
-
We also specify **-static** and **-g** options:
184
-
-**-static**: produces a statically linked executable, so it can run on different Arm64 Linux/Android environments without needing shared libraries.
185
-
-**-g**: includes debug information, which makes source code and function-level profiling in Streamline much easier.
187
+
The `-static` and `-g` options are also specified to produce a statically linked executable, so it can run on different Arm64 Linux/Android environments without needing shared libraries and to include debug information, which makes source code and function-level profiling in Streamline much easier.
186
188
187
-
so that the llama-cli executable is static linked and with debug info. This makes source code/function level profiling easier and the llama-cli executable runnable on various version of Arm64 Linux/Android.
188
-
189
-
Now you can build the project by running:
189
+
Now you can build the project using `cmake`:
190
190
191
191
```bash
192
192
cd~/llama.cpp/build
193
193
cmake --build ./ --config Release
194
194
```
195
195
196
-
After the building process, you should find the llama-cli will be generated at **~/llama.cpp/build/bin/** directory.
196
+
After the building process completes, you can find the `llama-cli` in the `~/llama.cpp/build/bin/` directory.
197
+
198
+
You now have an annotated version of `llama-cli` ready for Streamline.
0 commit comments