-
Notifications
You must be signed in to change notification settings - Fork 4.1k
[MLAS] Add CPU DynamicQuantMatMulFp8 contrib op with MLAS FP8 fallback #28416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
melkap01-Arm
wants to merge
26
commits into
microsoft:main
Choose a base branch
from
melkap01-Arm:fp8_DynamicQuantMatMul_Support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
536fb3f
Add CPU DynamicQuantMatMulFp8 contrib op with MLAS FP8 fallback
melkap01-Arm b53b1c5
wording for tile replaced with block
melkap01-Arm 563dcaa
Merge branch 'microsoft:main' into fp8_DynamicQuantMatMul_Support
melkap01-Arm c5fe8e1
cleaning the zp checks from MlasFp8GemmBatch after symmetric quantis…
melkap01-Arm a258ad8
documentation updated for failing build, copilot comment addressed
melkap01-Arm 7fb80e7
Reusable A buffer implemented before gemm, tests covering all fp8 typ…
melkap01-Arm 864b1a8
Merge branch 'microsoft:main' into fp8_DynamicQuantMatMul_Support
melkap01-Arm 1966da4
redundant lines removed
melkap01-Arm 98ea9ff
Optimize DynamicQuantMatMulFp8 A quantization
melkap01-Arm 473287e
Merge branch 'microsoft:main' into fp8_DynamicQuantMatMul_Support
melkap01-Arm 10c88a7
Merge branch 'microsoft:main' into fp8_DynamicQuantMatMul_Support
melkap01-Arm e041589
Merge branch 'microsoft:main' into fp8_DynamicQuantMatMul_Support
melkap01-Arm b913105
Merge branch 'microsoft:main' into fp8_DynamicQuantMatMul_Support
melkap01-Arm 16efd04
Merge branch 'microsoft:main' into fp8_DynamicQuantMatMul_Support
melkap01-Arm 4655e91
documentation difference patched
melkap01-Arm f3018d9
Merge branch 'microsoft:main' into fp8_DynamicQuantMatMul_Support
melkap01-Arm cc27b94
Merge branch 'microsoft:main' into fp8_DynamicQuantMatMul_Support
melkap01-Arm 93592f3
answering copilot comment regarding N==0 case
melkap01-Arm cdb66cf
Merge branch 'microsoft:main' into fp8_DynamicQuantMatMul_Support
melkap01-Arm f5424a9
LHS,RHS block layouts changed, scales adjusted
melkap01-Arm 3696f36
review comments addressed, docs patched
melkap01-Arm 68e2037
Merge branch 'microsoft:main' into fp8_DynamicQuantMatMul_Support
melkap01-Arm 5e9f1b9
copilot comments addressed
melkap01-Arm 68027e9
Merge branch 'microsoft:main' into fp8_DynamicQuantMatMul_Support
melkap01-Arm 7769b19
Merge branch 'microsoft:main' into fp8_DynamicQuantMatMul_Support
melkap01-Arm 183c5f7
enum representation cleaned
melkap01-Arm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
863 changes: 863 additions & 0 deletions
863
onnxruntime/contrib_ops/cpu/quantization/dynamic_quant_matmul_fp8.cc
Large diffs are not rendered by default.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
onnxruntime/contrib_ops/cpu/quantization/dynamic_quant_matmul_fp8.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // Copyright (c) 2026 Arm Limited. All rights reserved. | ||
| // SPDX-FileCopyrightText: Copyright 2026 Arm Limited and/or its affiliates <open-source-office@arm.com> | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "core/framework/op_kernel.h" | ||
| #include "core/framework/prepacked_weights.h" | ||
| #include "core/graph/onnx_protobuf.h" | ||
| #include "core/mlas/inc/mlas.h" | ||
|
|
||
| namespace onnxruntime { | ||
| namespace contrib { | ||
|
|
||
| class DynamicQuantMatMulFp8 final : public OpKernel { | ||
| public: | ||
| DynamicQuantMatMulFp8(const OpKernelInfo& info); | ||
|
|
||
| Status PrePack(const Tensor& tensor, int input_idx, AllocatorPtr alloc, | ||
| /*out*/ bool& is_packed, | ||
| /*out*/ PrePackedWeights* prepacked_weights) override; | ||
|
|
||
| Status Compute(OpKernelContext* context) const override; | ||
|
|
||
| enum InputTensors : int { | ||
| IN_A = 0, | ||
| IN_A_SCALE = 1, | ||
| IN_A_ZERO_POINT = 2, | ||
| IN_B = 3, | ||
| IN_B_SCALE = 4, | ||
| IN_B_ZERO_POINT = 5, | ||
| IN_Y_SCALE = 6, | ||
| IN_Y_ZERO_POINT = 7 | ||
| }; | ||
|
|
||
| enum OutputTensors : int { OUT_Y = 0 }; | ||
|
|
||
| static Status GetFp8Type(const Tensor& tensor, mlas_fp8_mode& out_type); | ||
| static Status GetFp8Type(ONNX_NAMESPACE::TensorProto_DataType elem_type, mlas_fp8_mode& out_type); | ||
|
|
||
| Status UseSharedPrePackedBuffers(std::vector<BufferUniquePtr>& prepacked_buffers, | ||
| gsl::span<const size_t> prepacked_buffer_sizes, | ||
| int input_idx, | ||
| /*out*/ bool& used_shared_buffers) override; | ||
|
|
||
| private: | ||
| static constexpr int GetBIdx() { return IN_B; } | ||
| IAllocatorUniquePtr<void> quantized_b_; | ||
| size_t quantized_b_size_{0}; | ||
| TensorShape b_shape_; | ||
| mlas_fp8_mode b_type_{static_cast<mlas_fp8_mode>(0)}; | ||
| bool has_b_type_{false}; | ||
| size_t block_size_m_{128}; | ||
| size_t block_size_k_{128}; | ||
| size_t block_size_n_{128}; | ||
| }; | ||
|
|
||
| } // namespace contrib | ||
| } // namespace onnxruntime |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.