-
-
Notifications
You must be signed in to change notification settings - Fork 56.2k
[WIP] [GSOC] GGUF Importer #27177
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
base: 5.x
Are you sure you want to change the base?
[WIP] [GSOC] GGUF Importer #27177
Conversation
GGUFBuffer::GGUFBuffer(const std::string & fileName){ | ||
std::ifstream file(fileName, std::ios::binary | std::ios::ate); | ||
if (!file.is_open()) { | ||
throw std::runtime_error("Could not open file: "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use CV_Error, CV_Assert, etc. See https://docs.opencv.org/5.x/db/de0/group__core__utils.html#ga5b48c333c777666e076bd7052799f891
if (!file.read(reinterpret_cast<char*>(buf.data()), size)) { | ||
throw std::runtime_error("Error reading file: " ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same for error handling.
GTEST_API_ int main(int argc, char **argv) | ||
{ | ||
testing::InitGoogleTest(&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should not be here. We have genetic test main to handle extra options and environment.
{ | ||
// Locate the GGUF file; this should be in the directory dnn/gguf/ (adjust the filename as needed) | ||
std::string ggufModelPath = _tf("mha.gguf", true); | ||
std::string onnxModelPath = _tf("mha.onnx", true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense to save the model output as .pb file with ONNX runtime for example, but not relay on OpenCV implementation for ONNX. It's more reliable and easy to catch regressions.
std::vector<int> dims; | ||
for (uint32_t i = 0; i < dim_count; ++i) { | ||
dims.push_back(reader.readSingleValueInt<int64_t>()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's more efficient to use std::vector dims(dim_count); and assign values, rather than call push_back and trigger reallocations.
if (tensor.type != GGML_TYPE_F32) { | ||
throw std::runtime_error("Unsupported tensor type: " + std::to_string(tensor.type)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use CV_Assert
and CV_Check
tensor.role = get_tensor_role(layerName); | ||
tensor.n_block = blockn; | ||
} else { | ||
throw std::runtime_error("Invalid tensor name format: " + tensor_name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CV_Error
if (t.size() == 0) { | ||
throw std::runtime_error("No input tensors found"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CV_Assert
if (t.size() == 0) { | ||
throw std::runtime_error("No input tensors found"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CV_Assert
throw std::runtime_error( | ||
"Unsupported tensor dimension: " + std::to_string(dims.size())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CV_Error
draft PR for #27176
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.