onnxruntime: [Performance] Celu becomes 4X slower after update to Eigen 3.4
Describe the issue
When running inference on the ONNX model “poc.onnx” using ONNX Runtime, there is a 30% increase in inference time between version 1.14.0 and version 1.17.3.
OS: Ubuntu 20.04.6 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Clang version: 12.0.0 (https://github.com/llvm/llvm-project.git d928dfc6f924f7e8436dcb5bcc51285fd03e869c)
CMake version: version 3.29.2
Libc version: glibc-2.31
Python version: 3.8.10 (default, Nov 22 2023, 10:22:35) [GCC 9.4.0] (64-bit runtime)
Python platform: Linux-5.4.0-174-generic-x86_64-with-glibc2.29
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
Address sizes: 46 bits physical, 48 bits virtual
CPU(s): 48
To reproduce
- Download “poc.onnx”.
- Run the following script.
import time
import onnxruntime
import numpy as np
onnx_model_path = 'poc.onnx'
ort_session = onnxruntime.InferenceSession(onnx_model_path, providers=['CPUExecutionProvider'])
ort_session.get_modelmeta()
inputs = ort_session.get_inputs()
nth = 1000
start = time.time()
for _ in range(nth):
np_input = np.random.randn(1, 3, 224, 224).astype('f')
input_ = {inputs[0].name: np_input}
ort_session.run(None, input_)
end = time.time()
print ('time:', (end - start) / nth)
[1.14.0] time: 0.011553843975067
[1.17.3] time: 0.014802978515625
Urgency
No response
Platform
Linux
OS Version
5.4.0-174-generic-x86_64
ONNX Runtime Installation
Released Package
ONNX Runtime Version or Commit ID
1.17.3
ONNX Runtime API
Python
Architecture
X64
Execution Provider
Default CPU
Execution Provider Library Version
No response
Model File
No response
Is this a quantized model?
No
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 19 (12 by maintainers)
@SuhwanSong , I think your benchmark result tells us that the problem is solely in Eigen. We should be able to create a simpler benchmark test case without using ORT code and without using multi threads, and we should be able to see the regression. Then we should report it to Eigen community.
Regarding Eigen version 3.4.0, it was needed for c++20 standard. Thus we should keep it as is.
I conducted further tests to analyze CELU performance regressions. Below are the results and testing methodology:
tested two adjacent commits: 7c58d013aa3715f5421f03f90690982625fdae6e and 1a73d618297c080cafff0a67b85c7829a8e629ad
Testing Methodology
I created an ONNX model for CELU using the following script:
I will use Sigmoid as an example. Now the cost is set to 2.
When I ran it on an Azure machine with an AMD 4th Gen CPU, 64 vCPUs, I got the following result:
When the input size was 1000, it ran in single thread and took about 328 ns. So when the input size increased to 10000, it took 2787 ns, roughly linear. The situation continues until the input was 40000. Then, you see when the input size is 80000, it actually took less than input size = 40000, it was because multithreading kicked in . So, what if we make it more aggressive? We can achieve it by decrease the cost to 1.
Then I got this:
The result stayed the same when input size <= 40000 or input size>=1280000. And, for the others the new one was not really better.
And, here is cost = 4.0f;
So, back to your question, in your case, what’s the avg input size for this operator? We may ran such benchmarks to see how it works. And we can compare the results with different eigen versions. These numbers are more convincing than the numbers from model tests(which contains a lot more extra things).
I found a performance regression (1.7x slower) between the following commits:
The regression seems related to the update to Eigen 3.4 and the removal of Eigen as a git submodule in commit 1a73d618297c080cafff0a67b85c7829a8e629ad.