openvino.genai: FullyConnected nodes use slow reference kernel on ARM
@Wovchena This is related to #406 but goes deeper, hence I decided to make this a new issue.
TL;DR
- For
greedy_causal_lminference onarm, large matmuls (e.g.1x2x4096:4096x4096in query/key/value projection) fall back to using a slow reference matmul implementation (ref_any_bf16) - Smaller matmuls (e.g.
1x32x2x2:1x32x2x128in dot-product attention) use a fastergemm_acl_f16kernel, which indicates that ACL kernels through oneDNN are available but not being used for point (1). - On
x86most matmuls usebrgemm_avx512_bf16kernel resulting in much faster inference.
Question: Is there a heuristic in OpenVINO that causes large matmuls on arm to fall back to the reference implementation?
Details
Following #327, I added code in greedy_causal_lm.cpp to save profiling information after inference. The table below shows the kernels used on x86 vs arm and their runtime (in microseconds) from the first decoder block of meta-llama/Llama-2-7b-hf (HuggingFace, compressed to INT8_ASYM).
| Operation | Shape | x86 kernel | x86 time (mcs) | arm kernel | arm time (mcs) |
|---|---|---|---|---|---|
| q_proj | 1x2x4096:4096x4096 | brgemm_avx512_bf16 |
584 | ref_any_f16 |
44714 |
| k_proj | 1x2x4096:4096x4096 | brgemm_avx512_bf16 |
699 | ref_any_f16 |
39713 |
| v_proj | 1x2x4096:4096x4096 | brgemm_avx512_bf16 |
5775 | ref_any_f16 |
37816 |
| o_proj | 1x2x4096:4096x4096 | brgemm_avx512_bf16 |
833 | ref_any_f16 |
36469 |
| mlp.gate_proj | 1x2x4096:4096x11008 | brgemm_avx512_bf16 |
1023 | ref_any_f16 |
97537 |
| mlp.up_proj | 1x2x4096:4096x11008 | brgemm_avx512_bf16 |
965 | ref_any_f16 |
101677 |
| mlp.down_proj | 1x2x11008:11008x4096 | brgemm_avx512_bf16 |
953 | ref_any_f16 |
98749 |
| classifier (logits) | 1x2x4096:4096x32000 | brgemm_avx512_bf16 |
1813 | ref_any_f16 |
284708 |
For small matmuls however, I noticed gemm_acl_f16 being called on arm.
| Operation | Shape | arm kernel | arm time (mcs) |
|---|---|---|---|
| A = q_proj * k_proj ^ T | 1x32x2x128:1x32x2x128 | gemm_acl_f16 |
226 |
| A * v_proj | 1x32x2x2:1x32x2x128 | gemm_acl_f16 |
69 |
This indicates that ACL kernels are available during inference but not being used only for large matmuls. To check that this diversion is not coming from oneDNN, I compiled oneDNN with ACL with following version combinations and benchmarked the above matmul sizes with benchdnn. Results are shown below, which indicate that gemm:acl is used on arm for all of the above sizes when the two compile correctly.
| oneDNN source | oneDNN version | ACL version | Kernel used on arm | Comments |
|---|---|---|---|---|
| oneapi-src/oneDNN | 3.3.3 | 24.02.1 | Build fails; error from ACL | References to ACL v24.02.1 were found in openvino docs. |
| oneapi-src/oneDNN | 3.3.3 | 23.11 | Build fails; error from ACL | N/A |
| oneapi-src/oneDNN | 3.3.3 | 23.08 | gemm:acl |
Expected kernel is used. |
| openvinotoolkit/oneDNN | 3.3.3 | 24.02.1 | gemm:jit_f32 |
ACL compilation flag ignored by cmake |
| openvinotoolkit/oneDNN | 3.3.3 | 23.11 | gemm:jit_f32 |
ACL compilation flag ignored by cmake |
| openvinotoolkit/oneDNN | 3.3.3 | 23.08 | gemm:jit_f32 |
ACL compilation flag ignored by cmake |
I think ACL kernels should ideally be used for any matmul on arm since they are available and being used for some operations. Since oneDNN is not the one causing a reference kernel to be used, I am led to believe that a heuristic within OpenVINO is causing this fallback. I’m hoping to know whether that is indeed the case, and (if yes) where this heuristic has been implemented.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18
@dmitry-gorokhov @alvoron Thanks for your response.
Regarding performance related points:
optimumis most likely due to the right openvino package not being installed, like you pointed out. I ran several experiments today but I can’t derive any conclusions right now due to large variations in performance I’m observing for the other two experiments (compared to yesterday). This variation is due to issues with the instances I’m using for my experiments, not with OpenVINO. I’ll try and resolve them at my end and come back to you with some reliable data soon.llm_benchon ARM with Llama2, and got roughly the same performance numbers as I did from my script. The output ofllm_benchis much more informative however, so I’ll probably continue using that going forward 😄 .I discussed with some of my colleagues, and they found it interesting that FP16 and BF16 had comparable accuracy as per your findings. We’ve almost always had BF16 give better accuracy, across many architectures (not limited to LLMs) and tasks. However, I can understand that there could be situations where this is not the case. It’s fine to take this up at a later point; not very urgent.
Thanks for clarifying.
Please see
If you’d like to know how I’ve run my experiments (such as in point 1.2), see below. Before running, please export
OPENVINO_SRC_DIRwith the path whereopenvinois being cloned, without the trailing slash.This should build the project and the wheel files in the usual locations. If some step errors out, please run the appropriate commands from build.sh with required adjustments separately. If the step corresponding to building the wheel file errors out, set
-DPython3_EXECUTABLEto${OPENVINO_SRC_DIR}/.venv/bin/python3.11instead of/usr/bin/python3.11inbuild.sh. Then, the scripts can be run as follows.Export Llama2 to IR format
C++ script
Python script with HuggingFace
optimumPython script using
openvinopackage directlyEach script should print throughput information at the end once it finishes running.