1
1
#include " ggml.h"
2
+ #include " gguf.h"
2
3
3
4
#include < cstdio>
4
- #include < cinttypes>
5
5
#include < string>
6
6
#include < sstream>
7
- #include < fstream>
8
7
#include < vector>
9
8
10
9
#undef MIN
@@ -135,9 +134,10 @@ static bool gguf_ex_read_0(const std::string & fname) {
135
134
136
135
for (int i = 0 ; i < n_tensors; ++i) {
137
136
const char * name = gguf_get_tensor_name (ctx, i);
137
+ const size_t size = gguf_get_tensor_size (ctx, i);
138
138
const size_t offset = gguf_get_tensor_offset (ctx, i);
139
139
140
- printf (" %s: tensor[%d]: name = %s, offset = %zu\n " , __func__, i, name, offset);
140
+ printf (" %s: tensor[%d]: name = %s, size = %zu, offset = %zu\n " , __func__, i, name, size , offset);
141
141
}
142
142
}
143
143
@@ -182,9 +182,10 @@ static bool gguf_ex_read_1(const std::string & fname, bool check_data) {
182
182
183
183
for (int i = 0 ; i < n_tensors; ++i) {
184
184
const char * name = gguf_get_tensor_name (ctx, i);
185
+ const size_t size = gguf_get_tensor_size (ctx, i);
185
186
const size_t offset = gguf_get_tensor_offset (ctx, i);
186
187
187
- printf (" %s: tensor[%d]: name = %s, offset = %zu\n " , __func__, i, name, offset);
188
+ printf (" %s: tensor[%d]: name = %s, size = %zu, offset = %zu\n " , __func__, i, name, size , offset);
188
189
}
189
190
}
190
191
@@ -199,7 +200,8 @@ static bool gguf_ex_read_1(const std::string & fname, bool check_data) {
199
200
200
201
struct ggml_tensor * cur = ggml_get_tensor (ctx_data, name);
201
202
202
- printf (" %s: tensor[%d]: n_dims = %d, name = %s, data = %p\n " , __func__, i, ggml_n_dims (cur), cur->name , cur->data );
203
+ printf (" %s: tensor[%d]: n_dims = %d, ne = (%d, %d, %d, %d), name = %s, data = %p\n " ,
204
+ __func__, i, ggml_n_dims (cur), int (cur->ne [0 ]), int (cur->ne [1 ]), int (cur->ne [2 ]), int (cur->ne [3 ]), cur->name , cur->data );
203
205
204
206
// print first 10 elements
205
207
const float * data = (const float *) cur->data ;
@@ -215,7 +217,7 @@ static bool gguf_ex_read_1(const std::string & fname, bool check_data) {
215
217
const float * data = (const float *) cur->data ;
216
218
for (int j = 0 ; j < ggml_nelements (cur); ++j) {
217
219
if (data[j] != 100 + i) {
218
- fprintf (stderr, " %s: tensor[%d]: data[%d] = %f\n " , __func__, i, j, data[j]);
220
+ fprintf (stderr, " %s: tensor[%d], data[%d]: found %f, expected %f \n " , __func__, i, j, data[j], float ( 100 + i) );
219
221
gguf_free (ctx);
220
222
return false ;
221
223
}
@@ -245,6 +247,8 @@ int main(int argc, char ** argv) {
245
247
check_data = false ;
246
248
}
247
249
250
+ srand (123456 );
251
+
248
252
const std::string fname (argv[1 ]);
249
253
const std::string mode (argv[2 ]);
250
254
0 commit comments