@@ -49,6 +49,8 @@ constexpr const GGUFVersion kGGUFVersionV1 = 1;
4949constexpr const GGUFVersion kGGUFVersionV2 = 2 ;
5050constexpr const GGUFVersion kGGUFVersionV3 = 3 ;
5151
52+ constexpr std::size_t kMaxElementsToShow = 50 ;
53+
5254enum 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}
131133inline 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
198214struct 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
485519inline std::optional<GGUFFile> ParseGgufFile (const std::string& path) {
0 commit comments