Skip to content

Commit 68c4b4c

Browse files
danbevtybalex
authored andcommitted
gguf : add option to not check tensor data (ggml-org#6582)
This commit adds an option to the gguf example to not check the tensor data. The motivation for this is that it can be nice to use the gguf tool to read other .gguf files that were not created by the gguf tool. Signed-off-by: Daniel Bevenius <[email protected]>
1 parent b0abc58 commit 68c4b4c

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

examples/gguf/gguf.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static bool gguf_ex_read_0(const std::string & fname) {
142142
}
143143

144144
// read and create ggml_context containing the tensors and their data
145-
static bool gguf_ex_read_1(const std::string & fname) {
145+
static bool gguf_ex_read_1(const std::string & fname, bool check_data) {
146146
struct ggml_context * ctx_data = NULL;
147147

148148
struct gguf_init_params params = {
@@ -206,7 +206,7 @@ static bool gguf_ex_read_1(const std::string & fname) {
206206
printf("\n\n");
207207

208208
// check data
209-
{
209+
if (check_data) {
210210
const float * data = (const float *) cur->data;
211211
for (int j = 0; j < ggml_nelements(cur); ++j) {
212212
if (data[j] != 100 + i) {
@@ -229,9 +229,16 @@ static bool gguf_ex_read_1(const std::string & fname) {
229229

230230
int main(int argc, char ** argv) {
231231
if (argc < 3) {
232-
printf("usage: %s data.gguf r|w\n", argv[0]);
232+
printf("usage: %s data.gguf r|w [n]\n", argv[0]);
233+
printf("r: read data.gguf file\n");
234+
printf("w: write data.gguf file\n");
235+
printf("n: no check of tensor data\n");
233236
return -1;
234237
}
238+
bool check_data = true;
239+
if (argc == 4) {
240+
check_data = false;
241+
}
235242

236243
const std::string fname(argv[1]);
237244
const std::string mode (argv[2]);
@@ -242,7 +249,7 @@ int main(int argc, char ** argv) {
242249
GGML_ASSERT(gguf_ex_write(fname) && "failed to write gguf file");
243250
} else if (mode == "r") {
244251
GGML_ASSERT(gguf_ex_read_0(fname) && "failed to read gguf file");
245-
GGML_ASSERT(gguf_ex_read_1(fname) && "failed to read gguf file");
252+
GGML_ASSERT(gguf_ex_read_1(fname, check_data) && "failed to read gguf file");
246253
}
247254

248255
return 0;

0 commit comments

Comments
 (0)