Skip to content

Commit 2d43387

Browse files
committed
ggml : fix builds, add ggml-quants-k.o (close #1712, close #1710)
1 parent 7ad7750 commit 2d43387

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ models/*
3535
/benchmark-matmult
3636
/vdot
3737
/Pipfile
38+
/libllama.so
3839

3940
build-info.h
4041
arm_neon.h

Makefile

+9-9
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ llama.o: llama.cpp ggml.h ggml-cuda.h llama.h llama-util.h
243243
common.o: examples/common.cpp examples/common.h
244244
$(CXX) $(CXXFLAGS) -c $< -o $@
245245

246-
libllama.so: llama.o ggml.o $(OBJS)
246+
libllama.so: llama.o ggml.o ggml-quants-k.o $(OBJS)
247247
$(CXX) $(CXXFLAGS) -shared -fPIC -o $@ $^ $(LDFLAGS)
248248

249249
clean:
@@ -253,28 +253,28 @@ clean:
253253
# Examples
254254
#
255255

256-
main: examples/main/main.cpp build-info.h ggml.o ggml-quants-k.o llama.o common.o $(OBJS)
256+
main: examples/main/main.cpp build-info.h ggml.o ggml-quants-k.o llama.o common.o $(OBJS)
257257
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
258258
@echo
259259
@echo '==== Run ./main -h for help. ===='
260260
@echo
261261

262-
quantize: examples/quantize/quantize.cpp build-info.h ggml.o llama.o ggml-quants-k.o $(OBJS)
262+
quantize: examples/quantize/quantize.cpp build-info.h ggml.o ggml-quants-k.o llama.o $(OBJS)
263263
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
264264

265-
quantize-stats: examples/quantize-stats/quantize-stats.cpp build-info.h ggml.o llama.o ggml-quants-k.o $(OBJS)
265+
quantize-stats: examples/quantize-stats/quantize-stats.cpp build-info.h ggml.o ggml-quants-k.o llama.o $(OBJS)
266266
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
267267

268-
perplexity: examples/perplexity/perplexity.cpp build-info.h ggml.o llama.o common.o ggml-quants-k.o $(OBJS)
268+
perplexity: examples/perplexity/perplexity.cpp build-info.h ggml.o ggml-quants-k.o llama.o common.o $(OBJS)
269269
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
270270

271-
embedding: examples/embedding/embedding.cpp build-info.h ggml.o llama.o common.o ggml-quants-k.o $(OBJS)
271+
embedding: examples/embedding/embedding.cpp build-info.h ggml.o ggml-quants-k.o llama.o common.o $(OBJS)
272272
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
273273

274-
save-load-state: examples/save-load-state/save-load-state.cpp build-info.h ggml.o llama.o common.o ggml-quants-k.o $(OBJS)
274+
save-load-state: examples/save-load-state/save-load-state.cpp build-info.h ggml.o ggml-quants-k.o llama.o common.o $(OBJS)
275275
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
276276

277-
server: examples/server/server.cpp examples/server/httplib.h examples/server/json.hpp build-info.h ggml.o llama.o common.o $(OBJS)
277+
server: examples/server/server.cpp examples/server/httplib.h examples/server/json.hpp build-info.h ggml.o ggml-quants-k.o llama.o common.o $(OBJS)
278278
$(CXX) $(CXXFLAGS) -Iexamples/server $(filter-out %.h,$(filter-out %.hpp,$^)) -o $@ $(LDFLAGS)
279279

280280
build-info.h: $(wildcard .git/index) scripts/build-info.sh
@@ -289,7 +289,7 @@ build-info.h: $(wildcard .git/index) scripts/build-info.sh
289289
# Tests
290290
#
291291

292-
benchmark-matmult: examples/benchmark/benchmark-matmult.cpp build-info.h ggml.o $(OBJS)
292+
benchmark-matmult: examples/benchmark/benchmark-matmult.cpp build-info.h ggml.o ggml-quants-k.o $(OBJS)
293293
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
294294
./$@
295295

ggml.c

+12-8
Original file line numberDiff line numberDiff line change
@@ -14753,7 +14753,7 @@ static void ggml_graph_export_leaf(const struct ggml_tensor * tensor, FILE * fou
1475314753
const int64_t * ne = tensor->ne;
1475414754
const size_t * nb = tensor->nb;
1475514755

14756-
fprintf(fout, "%-6s %-12s %8d %8lld %8lld %8lld %8lld %16zu %16zu %16zu %16zu %16p %32s\n",
14756+
fprintf(fout, "%-6s %-12s %8d %8jd %jd %jd %jd %16zu %16zu %16zu %16zu %16p %32s\n",
1475714757
ggml_type_name(tensor->type),
1475814758
ggml_op_name (tensor->op),
1475914759
tensor->n_dims,
@@ -14767,7 +14767,7 @@ static void ggml_graph_export_node(const struct ggml_tensor * tensor, const char
1476714767
const int64_t * ne = tensor->ne;
1476814768
const size_t * nb = tensor->nb;
1476914769

14770-
fprintf(fout, "%-6s %-6s %-12s %8d %8lld %8lld %8lld %8lld %16zu %16zu %16zu %16zu %8d %16p %32s\n",
14770+
fprintf(fout, "%-6s %-6s %-12s %8d %jd %jd %jd %jd %16zu %16zu %16zu %16zu %8d %16p %32s\n",
1477114771
arg,
1477214772
ggml_type_name(tensor->type),
1477314773
ggml_op_name (tensor->op),
@@ -14796,11 +14796,11 @@ void ggml_graph_export(const struct ggml_cgraph * cgraph, const char * fname) {
1479614796
FILE * fout = stdout;
1479714797

1479814798
fprintf(fout, "\n");
14799-
fprintf(fout, "%-16s %8x\n", "magic", GGML_FILE_MAGIC);
14800-
fprintf(fout, "%-16s %8d\n", "version", GGML_FILE_VERSION);
14801-
fprintf(fout, "%-16s %8d\n", "leafs", cgraph->n_leafs);
14802-
fprintf(fout, "%-16s %8d\n", "nodes", cgraph->n_nodes);
14803-
fprintf(fout, "%-16s %8llu\n", "eval", size_eval);
14799+
fprintf(fout, "%-16s %8x\n", "magic", GGML_FILE_MAGIC);
14800+
fprintf(fout, "%-16s %8d\n", "version", GGML_FILE_VERSION);
14801+
fprintf(fout, "%-16s %8d\n", "leafs", cgraph->n_leafs);
14802+
fprintf(fout, "%-16s %8d\n", "nodes", cgraph->n_nodes);
14803+
fprintf(fout, "%-16s %8ju\n", "eval", size_eval);
1480414804

1480514805
// header
1480614806
fprintf(fout, "\n");
@@ -15033,7 +15033,11 @@ struct ggml_cgraph ggml_graph_import(const char * fname, struct ggml_context **
1503315033

1503415034
data = ggml_new_tensor_1d(*ctx_data, GGML_TYPE_I8, fsize);
1503515035

15036-
fread(data->data, sizeof(char), fsize, fin);
15036+
const size_t ret = fread(data->data, sizeof(char), fsize, fin);
15037+
if (ret != fsize) {
15038+
fprintf(stderr, "%s: failed to read %s\n", __func__, fname);
15039+
return result;
15040+
}
1503715041

1503815042
fclose(fin);
1503915043
}

0 commit comments

Comments
 (0)