Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions onnxruntime/contrib_ops/cpu/quantization/matmul_nbits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,9 @@ Status MatMulNBits<MLFloat16>::PrePack(const Tensor& tensor, int input_idx, /*ou
OpKernel::Info().TryGetConstantInput(InputIndex::scales, &scales);
if (scales && MlasQNBitGemmScalesPacked(K_, nbits_, block_size_, compute_type_, has_zp_input_)) {
auto sptr = scales->Data<MLFloat16>();
auto tensor_size = static_cast<size_t>(tensor.Shape().Size());
auto ptr = IAllocator::MakeUniquePtr<float>(alloc, tensor_size, true);
MlasConvertHalfToFloatBuffer(sptr, ptr.get(), tensor_size);
auto scales_size = static_cast<size_t>(scales->Shape().Size());
auto ptr = IAllocator::MakeUniquePtr<float>(alloc, scales_size, true);
MlasConvertHalfToFloatBuffer(sptr, ptr.get(), scales_size);
scales_fp32_ = std::move(ptr);
}

Expand Down
8 changes: 8 additions & 0 deletions onnxruntime/test/shared_lib/test_inference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ static constexpr PATH_TYPE MODEL_URI = TSTR("testdata/mul_1.onnx");
static constexpr PATH_TYPE CUDA_GRAPH_ANNOTATION_MODEL_URI = TSTR("testdata/mul_1_dynamic.onnx");
#endif
static constexpr PATH_TYPE MATMUL_MODEL_URI = TSTR("testdata/matmul_1.onnx");
static constexpr PATH_TYPE PR_27412_FP16A_INT4B_MODEL_URI = TSTR("testdata/pr_27412_fp16A_int4B_model.onnx");
#ifndef ORT_NO_RTTI
static constexpr PATH_TYPE SEQUENCE_MODEL_URI = TSTR("testdata/sequence_length.onnx");
#endif
Expand Down Expand Up @@ -624,6 +625,13 @@ TEST(CApiTest, TestDanglingInput) {
ASSERT_TRUE(null_present);
}

// This test tests successful load of a fp16 A and Int4 B quantized model
// which caused an issue before PR #27412 - there was a crash on Mac M4 while trying to pack scales
TEST(CApiTest, LoadPr27412Fp16AInt4BModel) {
Ort::SessionOptions session_options;
EXPECT_NO_THROW(Ort::Session session(*ort_env, PR_27412_FP16A_INT4B_MODEL_URI, session_options));
}

#if !defined(DISABLE_SPARSE_TENSORS)
TEST(CApiTest, SparseOutputModel) {
std::vector<int64_t> dense_shape{3, 3};
Expand Down
Binary file not shown.
Loading