Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 53a0719

Browse files
chore: add default contructor and values to remove garbage values at runtime
1 parent e67ff4f commit 53a0719

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

engine/utils/hardware/gguf/ggml.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,9 @@ inline float GetQuantBit(GGMLType gt) {
8383
case GGML_TYPE_Q8_1:
8484
case GGML_TYPE_Q8_K:
8585
return 8.0f;
86-
8786
case GGML_TYPE_I64:
8887
case GGML_TYPE_F64:
8988
return 64.0f;
90-
9189
default:
9290
return 8.0f;
9391
}
@@ -171,7 +169,7 @@ inline std::string to_string(GGMLType t) {
171169
struct GGMLTypeTrait {
172170
uint64_t block_size;
173171
uint64_t type_size;
174-
bool is_quantized;
172+
bool is_quantized = false;
175173
};
176174

177175
const std::unordered_map<GGMLType, GGMLTypeTrait> kGGMLTypeTraits = {

engine/utils/hardware/gguf/gguf_file.h

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ constexpr const GGUFVersion kGGUFVersionV1 = 1;
4747
constexpr const GGUFVersion kGGUFVersionV2 = 2;
4848
constexpr const GGUFVersion kGGUFVersionV3 = 3;
4949

50+
constexpr std::size_t kMaxElementsToShow = 50;
51+
5052
enum GGUFMetadataValueType : uint32_t {
5153
GGUFMetadataValueTypeUint8 = 0,
5254
GGUFMetadataValueTypeInt8,
@@ -127,10 +129,21 @@ inline std::string to_string(GGUFMetadataValueType vt, const std::any& v) {
127129
return "array";
128130
}
129131
inline std::string to_string(const GGUFMetadataKVArrayValue& arr_v) {
130-
std::string res;
131-
auto num = std::min(size_t(5), arr_v.arr.size());
132-
for (size_t i = 0; i < num; i++) {
133-
res += to_string(arr_v.type, arr_v.arr[i]) + " ";
132+
std::string res = "[";
133+
size_t array_size = arr_v.arr.size();
134+
size_t elementsToShow = std::min(kMaxElementsToShow, array_size);
135+
for (size_t i = 0; i < elementsToShow; i++) {
136+
res += to_string(arr_v.type, arr_v.arr[i]) + ", ";
137+
}
138+
if(array_size > 0) {
139+
res.pop_back();
140+
res.pop_back();
141+
}
142+
res += "]";
143+
if(array_size > elementsToShow) {
144+
res += "... (";
145+
res += std::to_string(array_size - elementsToShow);
146+
res += " more elements)";
134147
}
135148
return res;
136149
}
@@ -191,6 +204,9 @@ struct GGUFTensorInfo {
191204
//
192205
// The offset is the start of the file.
193206
int64_t start_offset;
207+
208+
GGUFTensorInfo()
209+
: name(""), n_dimensions(0), dimensions(), type(GGMLType{}), offset(0), start_offset(0) {}
194210
};
195211

196212
struct GGUFHelper {
@@ -419,6 +435,10 @@ struct GGUFHeader {
419435
// MetadataKV are the key-value pairs in the metadata,
420436
std::vector<GGUFMetadataKV> metadata_kv;
421437

438+
// Constructor to initialize member variables.
439+
GGUFHeader()
440+
: magic{0}, version{0}, tensor_count(0), metadata_kv_count(0), metadata_kv() {}
441+
422442
std::pair<GGUFMetadataKV, bool> Get(const std::string& name) {
423443
for (auto const& kv : metadata_kv) {
424444
if (kv.key == name) {
@@ -478,6 +498,20 @@ struct GGUFFile {
478498
// which describes how many bits are used to store a weight,
479499
// higher is better.
480500
double model_bits_per_weight;
501+
502+
GGUFFile()
503+
: header(),
504+
tensor_infos(),
505+
padding(0),
506+
split_paddings(),
507+
tensor_data_start_offset(-1),
508+
split_tensor_data_start_offsets(),
509+
size(0),
510+
split_sizes(),
511+
model_size(0),
512+
split_model_sizes(),
513+
model_parameters(0),
514+
model_bits_per_weight(0.0) {}
481515
};
482516

483517
inline std::optional<GGUFFile> ParseGgufFile(const std::string& path) {

0 commit comments

Comments
 (0)