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

Commit c27bb18

Browse files
chore: add default contructor and values to remove garbage values at runtime
1 parent 764164e commit c27bb18

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
@@ -49,6 +49,8 @@ constexpr const GGUFVersion kGGUFVersionV1 = 1;
4949
constexpr const GGUFVersion kGGUFVersionV2 = 2;
5050
constexpr const GGUFVersion kGGUFVersionV3 = 3;
5151

52+
constexpr std::size_t kMaxElementsToShow = 50;
53+
5254
enum GGUFMetadataValueType : uint32_t {
5355
GGUFMetadataValueTypeUint8 = 0,
5456
GGUFMetadataValueTypeInt8,
@@ -129,10 +131,21 @@ inline std::string to_string(GGUFMetadataValueType vt, const std::any& v) {
129131
return "array";
130132
}
131133
inline std::string to_string(const GGUFMetadataKVArrayValue& arr_v) {
132-
std::string res;
133-
auto num = std::min(size_t(5), arr_v.arr.size());
134-
for (size_t i = 0; i < num; i++) {
135-
res += to_string(arr_v.type, arr_v.arr[i]) + " ";
134+
std::string res = "[";
135+
size_t array_size = arr_v.arr.size();
136+
size_t elementsToShow = std::min(kMaxElementsToShow, array_size);
137+
for (size_t i = 0; i < elementsToShow; i++) {
138+
res += to_string(arr_v.type, arr_v.arr[i]) + ", ";
139+
}
140+
if(array_size > 0) {
141+
res.pop_back();
142+
res.pop_back();
143+
}
144+
res += "]";
145+
if(array_size > elementsToShow) {
146+
res += "... (";
147+
res += std::to_string(array_size - elementsToShow);
148+
res += " more elements)";
136149
}
137150
return res;
138151
}
@@ -193,6 +206,9 @@ struct GGUFTensorInfo {
193206
//
194207
// The offset is the start of the file.
195208
int64_t start_offset;
209+
210+
GGUFTensorInfo()
211+
: name(""), n_dimensions(0), dimensions(), type(GGMLType{}), offset(0), start_offset(0) {}
196212
};
197213

198214
struct GGUFHelper {
@@ -421,6 +437,10 @@ struct GGUFHeader {
421437
// MetadataKV are the key-value pairs in the metadata,
422438
std::vector<GGUFMetadataKV> metadata_kv;
423439

440+
// Constructor to initialize member variables.
441+
GGUFHeader()
442+
: magic{0}, version{0}, tensor_count(0), metadata_kv_count(0), metadata_kv() {}
443+
424444
std::pair<GGUFMetadataKV, bool> Get(const std::string& name) {
425445
for (auto const& kv : metadata_kv) {
426446
if (kv.key == name) {
@@ -480,6 +500,20 @@ struct GGUFFile {
480500
// which describes how many bits are used to store a weight,
481501
// higher is better.
482502
double model_bits_per_weight;
503+
504+
GGUFFile()
505+
: header(),
506+
tensor_infos(),
507+
padding(0),
508+
split_paddings(),
509+
tensor_data_start_offset(-1),
510+
split_tensor_data_start_offsets(),
511+
size(0),
512+
split_sizes(),
513+
model_size(0),
514+
split_model_sizes(),
515+
model_parameters(0),
516+
model_bits_per_weight(0.0) {}
483517
};
484518

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

0 commit comments

Comments
 (0)