Distribute and run LLMs with a single file.
C++ cross-platformggufllama-cpplocal-ailocal-inferencelocal-llmopen-source-aisingle-file-executablespeech-to-text
Write log to /dev/null when main.log fails to open
Justine Tunneyfcc727a87e3d
diff --git a/llama.cpp/README.llamafile b/llama.cpp/README.llamafileindex 12763a69..1c681243 100644--- a/llama.cpp/README.llamafile+++ b/llama.cpp/README.llamafile@@ -20,6 +20,7 @@ LOCAL MODIFICATIONS- Introduce pledge() SECCOMP sandboxing to improve security- Use condition variables for server rather than busy loop- Remove log callback pointer API from Metal GPU module+ - Write log to /dev/null when main.log fails to open- Avoid bind() conflicts on port 8080 w/ server- Allow --grammar to be used on --image prompts- Use runtime dispatching for matmul quantsdiff --git a/llama.cpp/console.cpp b/llama.cpp/console.cppindex b6aa53c2..999f8045 100644--- a/llama.cpp/console.cpp+++ b/llama.cpp/console.cpp@@ -50,7 +50,7 @@ void init(bool use_simple_io, bool use_advanced_display) {new_termios.c_cc[VMIN] = 1;new_termios.c_cc[VTIME] = 0;tcsetattr(STDIN_FILENO, TCSANOW, &new_termios);- tty = fopen("/dev/tty", "w+");+ tty = fopen("/dev/tty", "w+e");if (tty != nullptr) {out = tty;}diff --git a/llama.cpp/ggml.c b/llama.cpp/ggml.cindex 5e034032..70dd8be9 100644--- a/llama.cpp/ggml.c+++ b/llama.cpp/ggml.c@@ -1983,7 +1983,7 @@ void ggml_numa_init(void) {}if (ggml_is_numa()) {- FILE *fptr = fopen("/proc/sys/kernel/numa_balancing", "r");+ FILE *fptr = fopen("/proc/sys/kernel/numa_balancing", "re");if (fptr != NULL) {char buf[42];if (fgets(buf, sizeof(buf), fptr) && strncmp(buf, "0\n", sizeof(buf)) != 0) {@@ -16692,7 +16692,7 @@ void ggml_graph_export(const struct ggml_cgraph * cgraph, const char * fname) {// write binary data{- FILE * fout = fopen(fname, "wb");+ FILE * fout = fopen(fname, "wbe");if (!fout) {fprintf(stderr, "%s: failed to open %s\n", __func__, fname);@@ -17174,7 +17174,7 @@ static void ggml_graph_dump_dot_leaf_edge(FILE * fp, struct ggml_tensor * node,void ggml_graph_dump_dot(const struct ggml_cgraph * gb, const struct ggml_cgraph * gf, const char * filename) {char color[16];- FILE * fp = fopen(filename, "w");+ FILE * fp = fopen(filename, "we");GGML_ASSERT(fp);fprintf(fp, "digraph G {\n");diff --git a/llama.cpp/ggml.h b/llama.cpp/ggml.hindex 5fbb2f23..4e4ff668 100644--- a/llama.cpp/ggml.h+++ b/llama.cpp/ggml.h@@ -2156,7 +2156,7 @@ extern "C" {//// - first prepare a file with a placeholder for the meta data, write the tensor data, then write the meta data://- // FILE * f = fopen(fname, "wb");+ // FILE * f = fopen(fname, "wbe");// fseek(f, gguf_get_meta_size(ctx), SEEK_SET);// fwrite(f, ...);// void * data = gguf_meta_get_meta_data(ctx);diff --git a/llama.cpp/llama.cpp b/llama.cpp/llama.cppindex 63bf2729..3d9e5450 100644--- a/llama.cpp/llama.cpp+++ b/llama.cpp/llama.cpp@@ -9829,7 +9829,7 @@ bool llama_load_session_file(struct llama_context * ctx, const char * path_sessi}bool llama_save_session_file(struct llama_context * ctx, const char * path_session, const llama_token * tokens, size_t n_token_count) {- llama_file file(path_session, "wb");+ llama_file file(path_session, "wbe");file.write_u32(LLAMA_SESSION_MAGIC);file.write_u32(LLAMA_SESSION_VERSION);diff --git a/llama.cpp/log.h b/llama.cpp/log.hindex c0e81486..fc37b3ff 100644--- a/llama.cpp/log.h+++ b/llama.cpp/log.h@@ -1,3 +1,6 @@+// -*- mode:c++;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-+// vi: set et ft=c++ ts=4 sts=4 sw=4 fenc=utf-8 :vi+#pragma once#include <chrono>@@ -393,13 +396,13 @@ inline FILE *log_handler1_impl(bool change = false, LogTriState append = LogTriS}}- logfile = fopen(filename.c_str(), _append ? "a" : "w");+ logfile = fopen(filename.c_str(), _append ? "ae" : "we");}if (!logfile){- // Verify whether the file was opened, otherwise fallback to stderr- logfile = stderr;+ // Verify whether the file was opened, otherwise fallback to /dev/null+ logfile = fopen("/dev/null", _append ? "ae" : "we");fprintf(stderr, "Failed to open logfile '%s' with error '%s'\n", filename.c_str(), std::strerror(errno));fflush(stderr);diff --git a/llama.cpp/main/main.cpp b/llama.cpp/main/main.cppindex 5d194bcd..6490ffb3 100644--- a/llama.cpp/main/main.cpp+++ b/llama.cpp/main/main.cpp@@ -53,7 +53,7 @@ static void write_logfile(}const std::string logfile_path = params.logdir + timestamp + ".yml";- FILE * logfile = fopen(logfile_path.c_str(), "w");+ FILE * logfile = fopen(logfile_path.c_str(), "we");if (logfile == NULL) {fprintf(stderr, "%s: failed to open logfile %s\n", __func__, logfile_path.c_str());