Distribute and run LLMs with a single file.
C++ cross-platformggufllama-cpplocal-ailocal-inferencelocal-llmopen-source-aisingle-file-executablespeech-to-text
Fix a memory bug in an error message
Justine Tunney20bfe9b346dc
diff --git a/llama.cpp/ggml-file.c b/llama.cpp/ggml-file.cindex fc094d6a..e486cce6 100644--- a/llama.cpp/ggml-file.c+++ b/llama.cpp/ggml-file.c@@ -1,6 +1,6 @@// -*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;coding:utf-8 -*-// vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi-#include "ggml.h"+#define _COSMO_SOURCE#include <cosmo.h>#include <errno.h>#include <fcntl.h>@@ -11,6 +11,7 @@#include <limits.h>#include <unistd.h>#include <sys/mman.h>+#include "ggml.h"#include "zip.h"#define Min(a, b) ((a) < (b) ? (a) : (b))@@ -162,6 +163,10 @@ struct ggml_file *ggml_file_open(const char * fname, const char * mode) {entry_index < cnt && entry_offset + kZipCfileHdrMinSize <= cdirsize &&entry_offset + ZIP_CFILE_HDRSIZE(cdirdata + entry_offset) <= cdirsize;++entry_index, entry_offset += ZIP_CFILE_HDRSIZE(cdirdata + entry_offset)) {+ if (ZIP_CFILE_MAGIC(cdirdata + entry_offset) != kZipCfileHdrMagic) {+ fprintf(stderr, "error: corrupted zip central directory entry magic\n");+ goto Failure;+ }if (fname_len == ZIP_CFILE_NAMESIZE(cdirdata + entry_offset) &&!memcmp(fname, ZIP_CFILE_NAME(cdirdata + entry_offset), fname_len)) {off = GetZipCfileOffset(cdirdata + entry_offset);@@ -182,7 +187,11 @@ struct ggml_file *ggml_file_open(const char * fname, const char * mode) {// this is needed to determine offset of file contentuint8_t lfile[kZipLfileHdrMinSize];if (pread(fd, lfile, kZipLfileHdrMinSize, off) != kZipLfileHdrMinSize) {- fprintf(stderr, "warning: failed to pread lfile: %s\n", prog);+ fprintf(stderr, "error: failed to pread lfile: %s\n", prog);+ goto Failure;+ }+ if (ZIP_LFILE_MAGIC(lfile) != kZipLfileHdrMagic) {+ fprintf(stderr, "error: corrupted zip local file magic\n");goto Failure;}off += ZIP_LFILE_HDRSIZE(lfile);diff --git a/llama.cpp/ggml.c b/llama.cpp/ggml.cindex 00a855ff..4289d19c 100644--- a/llama.cpp/ggml.c+++ b/llama.cpp/ggml.c@@ -18691,7 +18691,11 @@ struct gguf_context * gguf_init_from_file(struct ggml_file * file, struct gguf_ifor (uint32_t i = 0; i < sizeof(magic); i++) {if (magic[i] != GGUF_MAGIC[i]) {- fprintf(stderr, "%s: invalid magic characters %s.\n", __func__, magic);+ fprintf(stderr, "%s: invalid magic characters: %c%c%c%c.\n", __func__,+ isgraph(magic[0]) ? magic[0] : '?',+ isgraph(magic[1]) ? magic[1] : '?',+ isgraph(magic[2]) ? magic[2] : '?',+ isgraph(magic[3]) ? magic[3] : '?');return NULL;}}diff --git a/llama.cpp/llama.cc b/llama.cpp/llama.ccindex 1193b733..e27713b9 100644--- a/llama.cpp/llama.cc+++ b/llama.cpp/llama.cc@@ -753,8 +753,11 @@ struct llama_mmap {llama_mmap(struct llama_file * file, size_t prefetch = (size_t) -1 /* -1 = max value */, bool numa = false) {size = ggml_file_size(file->file);if (!ggml_file_fp(file->file)) {+ // file is an uncompressed zip asset+ // therefore it's already mappedis_owned = false;addr = ggml_file_content(file->file);+ ggml_schlep(addr, size);return;}is_owned = true;