Enable FP16 activations in MatMulNBits#341
Closed
qti-mattsinc wants to merge 1 commit into
Closed
Conversation
### Description * Remove FP32 input restriction in MatMulNBits op builder. Note that the scales initializer must be cast to FP32 in the op builder as QNN currently requires FP32 scales at the API level. * Add FP16 MatMulNBits unit tests. ### Motivation and Context * Enable w4a16 LLMs on the GPU for faster inferencing.
minfhong-qti
reviewed
May 6, 2026
minfhong-qti
left a comment
Collaborator
There was a problem hiding this comment.
A gentle heads up I'm working on supporting MatMulNBits for HTP in PR #288. There will be a slight refactory. Feel free to review that PR.
Comment on lines
+257
to
+267
| const OrtTypeInfo* type_info = nullptr; | ||
| const auto& ort_api = qnn_model_wrapper.GetOrtApi(); | ||
| ORT_CXX_RETURN_ON_API_FAIL(ort_api.GetValueInfoTypeInfo(scale_tensor_proto, &type_info)); | ||
| const OrtTensorTypeAndShapeInfo* tensor_type_and_shape_info = nullptr; | ||
| ORT_CXX_RETURN_ON_API_FAIL(ort_api.CastTypeInfoToTensorInfo(type_info, &tensor_type_and_shape_info)); | ||
| ONNXTensorElementDataType onnx_data_type = ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED; | ||
| ORT_CXX_RETURN_ON_API_FAIL(ort_api.GetTensorElementType(tensor_type_and_shape_info, &onnx_data_type)); | ||
|
|
||
| RETURN_IF(onnx_data_type != ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT && | ||
| onnx_data_type != ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16, | ||
| "Unsupported scales datatype"); |
Collaborator
There was a problem hiding this comment.
Suggested change
| const OrtTypeInfo* type_info = nullptr; | |
| const auto& ort_api = qnn_model_wrapper.GetOrtApi(); | |
| ORT_CXX_RETURN_ON_API_FAIL(ort_api.GetValueInfoTypeInfo(scale_tensor_proto, &type_info)); | |
| const OrtTensorTypeAndShapeInfo* tensor_type_and_shape_info = nullptr; | |
| ORT_CXX_RETURN_ON_API_FAIL(ort_api.CastTypeInfoToTensorInfo(type_info, &tensor_type_and_shape_info)); | |
| ONNXTensorElementDataType onnx_data_type = ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED; | |
| ORT_CXX_RETURN_ON_API_FAIL(ort_api.GetTensorElementType(tensor_type_and_shape_info, &onnx_data_type)); | |
| RETURN_IF(onnx_data_type != ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT && | |
| onnx_data_type != ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16, | |
| "Unsupported scales datatype"); | |
| RETURN_IF(scales_tensor.type != ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT && | |
| scale_tensor.type != ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16, | |
| "Unsupported scales datatype"); |
Collaborator
Author
|
Closing; this change was brought into a related PR: #288. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Motivation and Context