Skip to content

Update x64 template kernel library for 'sqnbitgemm' - #19016

Merged
yufenglee merged 40 commits into
microsoft:mainfrom
luoyu-intel:main
Jan 18, 2024
Merged

Update x64 template kernel library for 'sqnbitgemm'#19016
yufenglee merged 40 commits into
microsoft:mainfrom
luoyu-intel:main

Conversation

@luoyu-intel

@luoyu-intel luoyu-intel commented Jan 5, 2024

Copy link
Copy Markdown
Contributor

Description

  1. Make JBLAS codes an external module of ORT.
  2. Move q4 gemm code to contrib_ops.
  3. Update template kernel library to v0.1 release.

Motivation and Context

We found that the current LLM model performance is far below our expectations. Here is some performance data collected on Mistral-7B model with Xeon-8480:

8 threads prompt length=32 past_len=32 prompt length=1 past_len=32
ORT-main 1220ms 263ms
Neural-speed 564ms 87ms
ORT-this PR 597ms 120ms

Although Neural-speed and ORT-this PR use the same int4 kernel code, there is a 33ms(87ms vs. 120ms) latency gap between the two frameworks.
Through some statistics analysis, the summary latency of MatMulNBits is 86.7ms
The summary latency of all int4 GEMMs in Neural-speed is 84.8ms. So other OPs introduce an extra 30ms latency.

The performance of MatMulNBits in this PR meets our expectations.

Remain Issues

  1. For hybrid CPUs, like core 12900K, the ONNXRuntime thread pool uses TaskGranularityFactor to scale its number of threads. This is not expected in our code design. It may slow down the hybrid CPU performance by 30~40%.
  2. Prepack uses a single thread which is very slow to init a session.
  3. MatMulNBits with zero points will fall through to COMP_FP32 even accuracy_level=4. Our COMP_INT8 IGemmCore with zero points process is not optimized for now. It will be updated in the future. So, for an int4 model with zero points, whether the accuracy_level is 0 or 4 will be no difference.

@luoyu-intel
luoyu-intel marked this pull request as ready for review January 5, 2024 08:23
@luoyu-intel
luoyu-intel requested a review from a team as a code owner January 5, 2024 08:23
Comment thread cmake/external/neural_speed.cmake Outdated
Comment thread cmake/external/neural_speed.cmake Outdated
@yufenglee

Copy link
Copy Markdown
Member

/azp run Windows GPU TensorRT CI Pipeline, Windows x64 QNN CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed

@yufenglee

Copy link
Copy Markdown
Member

/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, Windows ARM64 QNN CI Pipeline, Windows CPU CI Pipeline, Windows GPU CI Pipeline

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 6 pipeline(s).

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 10 pipeline(s).

@yufenglee

Copy link
Copy Markdown
Member

/azp run Windows GPU TensorRT CI Pipeline, Windows x64 QNN CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed

@yufenglee

Copy link
Copy Markdown
Member

/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, Windows ARM64 QNN CI Pipeline, Windows CPU CI Pipeline, Windows GPU CI Pipeline

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 6 pipeline(s).

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 10 pipeline(s).

Comment thread onnxruntime/contrib_ops/cpu/quantization/bestla_gemm.cc Fixed
Comment thread cmake/onnxruntime_providers_cpu.cmake Outdated
Comment thread onnxruntime/contrib_ops/cpu/quantization/bestla_gemm.cc Outdated
@yufenglee

Copy link
Copy Markdown
Member

/azp run Windows GPU TensorRT CI Pipeline, Windows x64 QNN CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed

@yufenglee

Copy link
Copy Markdown
Member

/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, Windows ARM64 QNN CI Pipeline, Windows CPU CI Pipeline, Windows GPU CI Pipeline

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 6 pipeline(s).

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 10 pipeline(s).

@yufenglee

Copy link
Copy Markdown
Member

/azp run Windows GPU TensorRT CI Pipeline, Windows x64 QNN CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed

@yufenglee

Copy link
Copy Markdown
Member

/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, Windows ARM64 QNN CI Pipeline, Windows CPU CI Pipeline, Windows GPU CI Pipeline

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 6 pipeline(s).

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 10 pipeline(s).

Comment thread onnxruntime/contrib_ops/cpu/quantization/bestla_gemm.h Outdated
Comment thread onnxruntime/contrib_ops/cpu/quantization/bestla_gemm.cc Outdated
Comment thread onnxruntime/contrib_ops/cpu/quantization/bestla_gemm.cc Outdated
Comment thread onnxruntime/contrib_ops/cpu/quantization/bestla_gemm.h Outdated
Comment thread onnxruntime/contrib_ops/cpu/quantization/bestla_gemm.h Outdated
@yufenglee

Copy link
Copy Markdown
Member

/azp run Windows GPU TensorRT CI Pipeline, Windows x64 QNN CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed

@yufenglee

Copy link
Copy Markdown
Member

/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, Windows ARM64 QNN CI Pipeline, Windows CPU CI Pipeline, Windows GPU CI Pipeline

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 6 pipeline(s).

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 10 pipeline(s).

@luoyu-intel

Copy link
Copy Markdown
Contributor Author

/azp run Linux CPU CI Pipeline

@azure-pipelines

Copy link
Copy Markdown
Commenter does not have sufficient privileges for PR 19016 in repo microsoft/onnxruntime

@yufenglee

Copy link
Copy Markdown
Member

/azp run Windows GPU TensorRT CI Pipeline, Windows x64 QNN CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed

@yufenglee

Copy link
Copy Markdown
Member

/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, Windows ARM64 QNN CI Pipeline, Windows CPU CI Pipeline, Windows GPU CI Pipeline

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 6 pipeline(s).

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 10 pipeline(s).

Comment thread cmake/deps.txt Outdated
Comment thread cmake/external/neural_speed.cmake Outdated
@yufenglee

Copy link
Copy Markdown
Member

/azp run Windows GPU TensorRT CI Pipeline, Windows x64 QNN CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed

@yufenglee

Copy link
Copy Markdown
Member

/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, Windows ARM64 QNN CI Pipeline, Windows CPU CI Pipeline, Windows GPU CI Pipeline

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 6 pipeline(s).

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 10 pipeline(s).

@yufenglee yufenglee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@yufenglee
yufenglee merged commit 459c750 into microsoft:main Jan 18, 2024
mszhanyi added a commit that referenced this pull request Jan 23, 2024
YUNQIUGUO pushed a commit that referenced this pull request Jan 23, 2024
### Description
<!-- Describe your changes. -->
1. Make JBLAS codes an external module of ORT.
2. Move q4 gemm code to contrib_ops.
3. Update template kernel library to v0.1 release.


### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
We found that the current LLM model performance is far below our
expectations. Here is some performance data collected on Mistral-7B
model with Xeon-8480:
8 threads | prompt length=32 past_len=32 | prompt length=1   past_len=32
-- | -- | --
ORT-main | 1220ms | 263ms
Neural-speed | 564ms | 87ms
ORT-this PR|597ms|120ms

Although `Neural-speed` and `ORT-this PR` use the same int4 kernel code,
there is a 33ms(87ms vs. 120ms) latency gap between the two frameworks.
Through some statistics analysis, the summary latency of `MatMulNBits`
is 86.7ms
The summary latency of all int4 GEMMs in `Neural-speed` is 84.8ms. So
other OPs introduce an extra 30ms latency.

The performance of MatMulNBits in this PR meets our expectations.

### Remain Issues
1. For hybrid CPUs, like core 12900K, the ONNXRuntime thread pool uses
TaskGranularityFactor to scale its number of threads. This is not
expected in our code design. It may slow down the hybrid CPU performance
by 30~40%.
2. Prepack uses a single thread which is very slow to init a session.
3. MatMulNBits with zero points will fall through to COMP_FP32 even
accuracy_level=4. Our COMP_INT8 IGemmCore with zero points process is
not optimized for now. It will be updated in the future. So, for an int4
model with zero points, whether the accuracy_level is 0 or 4 will be no
difference.
snnn pushed a commit that referenced this pull request Feb 7, 2024
### Description
<!-- Describe your changes. -->
Revert PR#19016 #19016
Revert PR#17669 #17669
skottmckay pushed a commit that referenced this pull request Feb 15, 2024
### Description
<!-- Describe your changes. -->
Revert PR#19016 #19016
Revert PR#17669 #17669
rohan11235813 pushed a commit to quadric-io/onnxruntime that referenced this pull request Aug 19, 2025
### Description
<!-- Describe your changes. -->
Revert PR#19016 microsoft/onnxruntime#19016
Revert PR#17669 microsoft/onnxruntime#17669
@snnn

snnn commented Sep 5, 2025

Copy link
Copy Markdown
Contributor

This PR has been cherry-picked into the rel-1.17.0 branch in PR #19243. Removing the release:1.17.0 label.

rohan11235813 pushed a commit to quadric-io/onnxruntime that referenced this pull request Sep 15, 2025
### Description
<!-- Describe your changes. -->
Revert PR#19016 microsoft/onnxruntime#19016
Revert PR#17669 microsoft/onnxruntime#17669
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants