Skip to content

Commit 4d69849

Browse files
committed
gguf : init
1 parent 5488fb7 commit 4d69849

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ models-mnt
4545
/server
4646
/Pipfile
4747
/embd-input-test
48+
/gguf
4849
/libllama.so
4950
build-info.h
5051
arm_neon.h

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Define the default target now so that it is always the first target
2-
BUILD_TARGETS = main quantize quantize-stats perplexity embedding vdot train-text-from-scratch simple server embd-input-test
2+
BUILD_TARGETS = main quantize quantize-stats perplexity embedding vdot train-text-from-scratch simple server embd-input-test gguf
33

44
# Binaries only useful for tests
55
TEST_TARGETS = tests/test-double-float tests/test-grad0 tests/test-opt tests/test-quantize-fns tests/test-quantize-perf tests/test-sampling tests/test-tokenizer-0
@@ -330,7 +330,7 @@ libllama.so: llama.o ggml.o $(OBJS)
330330
$(CXX) $(CXXFLAGS) -shared -fPIC -o $@ $^ $(LDFLAGS)
331331

332332
clean:
333-
rm -vf *.o *.so *.dll main quantize quantize-stats perplexity embedding benchmark-matmult save-load-state server simple vdot train-text-from-scratch embd-input-test build-info.h $(TEST_TARGETS)
333+
rm -vf *.o *.so *.dll main quantize quantize-stats perplexity embedding benchmark-matmult save-load-state server simple vdot train-text-from-scratch embd-input-test gguf build-info.h $(TEST_TARGETS)
334334

335335
#
336336
# Examples
@@ -370,6 +370,9 @@ $(LIB_PRE)embdinput$(DSO_EXT): examples/embd-input/embd-input.h examples/embd-in
370370
embd-input-test: $(LIB_PRE)embdinput$(DSO_EXT) examples/embd-input/embd-input-test.cpp build-info.h ggml.o llama.o common.o $(OBJS)
371371
$(CXX) $(CXXFLAGS) $(filter-out %$(DSO_EXT),$(filter-out %.h,$(filter-out %.hpp,$^))) -o $@ $(LDFLAGS) -L. -lembdinput
372372

373+
gguf: examples/gguf/gguf.cpp build-info.h ggml.o $(OBJS)
374+
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
375+
373376
train-text-from-scratch: examples/train-text-from-scratch/train-text-from-scratch.cpp build-info.h ggml.o llama.o $(OBJS)
374377
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
375378

examples/gguf/gguf.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "ggml.h"
2+
3+
#include <cstdio>
4+
#include <string>
5+
6+
bool gguf_write(const std::string & fname) {
7+
8+
9+
return true;
10+
}
11+
12+
bool gguf_read(const std::string & fname) {
13+
return true;
14+
}
15+
16+
int main(int argc, char ** argv) {
17+
if (argc < 3) {
18+
fprintf(stdout, "usage: %s data.gguf r|w\n", argv[0]);
19+
return -1;
20+
}
21+
22+
const std::string fname(argv[1]);
23+
const std::string mode(argv[2]);
24+
25+
GGML_ASSERT((mode == "r" || mode == "w") && "mode must be r or w");
26+
27+
if (mode == "w") {
28+
GGML_ASSERT(gguf_write(fname) && "failed to write gguf file");
29+
} else if (mode == "r") {
30+
GGML_ASSERT(gguf_read(fname) && "failed to read gguf file");
31+
}
32+
33+
return 0;
34+
}

ggml.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@
190190
#define GGML_FILE_MAGIC 0x67676d6c // "ggml"
191191
#define GGML_FILE_VERSION 1
192192

193+
#define GGUF_FILE_MAGIC 0x47475546 // "GGUF"
194+
#define GGUF_FILE_VERSION 1
195+
193196
#define GGML_QNT_VERSION 2 // bump this on quantization format changes
194197
#define GGML_QNT_VERSION_FACTOR 1000 // do not change this
195198

@@ -202,7 +205,6 @@
202205
#define GGML_MAX_OP_PARAMS 32
203206
#define GGML_DEFAULT_N_THREADS 4
204207

205-
206208
#define GGML_EXIT_SUCCESS 0
207209
#define GGML_EXIT_ABORTED 1
208210

@@ -1611,6 +1613,27 @@ extern "C" {
16111613

16121614
GGML_API size_t ggml_quantize_chunk(enum ggml_type type, const float * src, void * dst, int start, int n, int64_t * hist);
16131615

1616+
//
1617+
// gguf
1618+
//
1619+
1620+
enum gguf_metadata_value_type {
1621+
GGUF_METADATA_VALUE_TYPE_UINT8 = 0,
1622+
GGUF_METADATA_VALUE_TYPE_INT8 = 1,
1623+
GGUF_METADATA_VALUE_TYPE_UINT16 = 2,
1624+
GGUF_METADATA_VALUE_TYPE_INT16 = 3,
1625+
GGUF_METADATA_VALUE_TYPE_UINT32 = 4,
1626+
GGUF_METADATA_VALUE_TYPE_INT32 = 5,
1627+
GGUF_METADATA_VALUE_TYPE_FLOAT32 = 6,
1628+
GGUF_METADATA_VALUE_TYPE_BOOL = 7,
1629+
GGUF_METADATA_VALUE_TYPE_STRING = 8,
1630+
GGUF_METADATA_VALUE_TYPE_ARRAY = 9,
1631+
};
1632+
1633+
struct gguf_string {
1634+
uint32_t n;
1635+
char * data;
1636+
};
16141637
//
16151638
// system info
16161639
//

0 commit comments

Comments
 (0)