Distribute and run LLMs with a single file.
C++ cross-platformggufllama-cpplocal-ailocal-inferencelocal-llmopen-source-aisingle-file-executablespeech-to-text
Reduce server memory use on Windows
Justine Tunneyed05ba9c85b9
diff --git a/llamafile/cuda.c b/llamafile/cuda.cindex c3c3baf8..14c12f44 100644--- a/llamafile/cuda.c+++ b/llamafile/cuda.c@@ -928,8 +928,8 @@ GGML_CALL void ggml_cuda_host_free(void *data) {}GGML_CALL bool ggml_cuda_can_mul_mat(const struct ggml_tensor *src0,- const struct ggml_tensor *src1,- struct ggml_tensor *dst) {+ const struct ggml_tensor *src1,+ struct ggml_tensor *dst) {if (!ggml_cuda_supported()) return false;return ggml_cuda.ggml_cuda_can_mul_mat(src0, src1, dst);}@@ -995,7 +995,7 @@ GGML_CALL void ggml_cuda_free_scratch(void) {}GGML_CALL bool ggml_cuda_compute_forward(struct ggml_compute_params *params,- struct ggml_tensor *tensor) {+ struct ggml_tensor *tensor) {if (!ggml_cuda_supported()) return false;return ggml_cuda.compute_forward(params, tensor);}@@ -1006,8 +1006,8 @@ GGML_CALL int ggml_cuda_get_device_count(void) {}GGML_CALL void ggml_cuda_get_device_description(int device,- char *description,- size_t description_size) {+ char *description,+ size_t description_size) {if (!ggml_cuda_supported()) return;return ggml_cuda.get_device_description(device, description,description_size);diff --git a/llamafile/launch_browser.c b/llamafile/launch_browser.cindex e8b5842e..f9359af9 100644--- a/llamafile/launch_browser.c+++ b/llamafile/launch_browser.c@@ -29,6 +29,12 @@static volatile bool g_timed_out;+static void finish(void) {+ if (!IsWindows()) {+ _exit(0);+ }+}+static void handle_timeout(int sig) {g_timed_out = true;}@@ -47,14 +53,16 @@ void llamafile_launch_browser(const char *url) {// perform this task from a subprocess so it doesn't block servertinylog("opening browser tab... (pass --nobrowser to disable)\n", NULL);- switch (fork()) {- case 0:- break;- default:- return;- case -1:- perror("fork");- return;+ if (!IsWindows()) {+ switch (fork()) {+ case 0:+ break;+ default:+ return;+ case -1:+ perror("fork");+ return;+ }}// determine which command opens browser tab@@ -78,7 +86,7 @@ void llamafile_launch_browser(const char *url) {posix_spawnattr_destroy(&sa);if (err) {report_failure(url, cmd, strerror(err));- _exit(0);+ return finish();}// kill command if it takes more than three seconds@@ -90,19 +98,19 @@ void llamafile_launch_browser(const char *url) {sigaction(SIGALRM, &hand, 0);alarm(3);- // wait for tab to finish opening+ // wait for tab to return finish opening// the browser will still be running after this completesint ws;while (waitpid(pid, &ws, 0) == -1) {if (errno != EINTR) {report_failure(url, cmd, strerror(errno));kill(pid, SIGKILL);- _exit(0);+ return finish();}if (g_timed_out) {report_failure(url, cmd, "process timed out");kill(pid, SIGKILL);- _exit(0);+ return finish();}}if (ws) {@@ -110,5 +118,5 @@ void llamafile_launch_browser(const char *url) {}// we're done- _exit(0);+ return finish();}