Distribute and run LLMs with a single file.
C++ cross-platformggufllama-cpplocal-ailocal-inferencelocal-llmopen-source-aisingle-file-executablespeech-to-text
Document Mozilla's contributions as Apache 2.0
Justine Tunneydfe961717d77
diff --git a/llama.cpp/LICENSE b/LICENSEsimilarity index 55%rename from llama.cpp/LICENSErename to LICENSEindex 76f67efd..73e7a3b0 100644--- a/llama.cpp/LICENSE+++ b/LICENSE@@ -1,6 +1,27 @@+Copyright 2023 Mozilla Foundation++Licensed under the Apache License, Version 2.0 (the "License");+you may not use this file except in compliance with the License.+You may obtain a copy of the License at++ http://www.apache.org/licenses/LICENSE-2.0++Unless required by applicable law or agreed to in writing, software+distributed under the License is distributed on an "AS IS" BASIS,+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+See the License for the specific language governing permissions and+limitations under the License.++--------------------------------------------------------------------------------+MIT LicenseCopyright (c) 2023 Georgi Gerganov+Copyright (c) 2023 Jeffrey Quesnelle and Bowen Peng.+Copyright (c) 2023 Yuji Hirose+Copyright (c) 2022 Niels Lohmann <https://nlohmann.me>+Copyright (c) 2022 Bjoern Hoehrmann <[email protected]>+Copyright (c) 2017 Sean BarrettPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealdiff --git a/llama.cpp/README.cosmo b/llama.cpp/README.llamafilesimilarity index 67%rename from llama.cpp/README.cosmorename to llama.cpp/README.llamafileindex 5b705999..a7ee16be 100644--- a/llama.cpp/README.cosmo+++ b/llama.cpp/README.llamafile@@ -4,7 +4,9 @@ DESCRIPTIONLICENSE- MIT+ llama.cpp is licensed MIT and in our repository it includes files+ released under the Apache 2.0 license. Files that are licensed as+ such are clearly documented at the top of each file.ORIGINdiff --git a/llama.cpp/cpucheck.c b/llama.cpp/cpucheck.cindex 2812a191..6bdd392a 100644--- a/llama.cpp/cpucheck.c+++ b/llama.cpp/cpucheck.c@@ -1,5 +1,20 @@// -*- 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+//+// Copyright 2023 Mozilla Foundation+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.+#define _COSMO_SOURCE#include <cosmo.h>#include <stdlib.h>diff --git a/llama.cpp/cuda.c b/llama.cpp/cuda.cindex cfa33d33..89682f90 100644--- a/llama.cpp/cuda.c+++ b/llama.cpp/cuda.c@@ -1,5 +1,20 @@// -*- 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+//+// Copyright 2023 Mozilla Foundation+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.+#define _COSMO_SOURCE#include <cosmo.h>#include <time.h>diff --git a/llama.cpp/extract.c b/llama.cpp/extract.cindex 731520a5..bd0b88d0 100644--- a/llama.cpp/extract.c+++ b/llama.cpp/extract.c@@ -1,5 +1,20 @@// -*- 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+//+// Copyright 2023 Mozilla Foundation+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.+#define _COSMO_SOURCE#include <cosmo.h>#include <fcntl.h>@@ -11,7 +26,7 @@#include <sys/stat.h>#include "ggml.h"-static const char *GetTmpDir(void) {+static const char *ggml_get_tmp_dir(void) {const char *tmpdir;if (!(tmpdir = getenv("TMPDIR")) || !*tmpdir) {if (!(tmpdir = getenv("HOME")) || !*tmpdir) {@@ -25,39 +40,111 @@ static const char *GetTmpDir(void) {* Returns path of directory for app-specific files.*/void ggml_get_app_dir(char *path, size_t size) {- strlcpy(path, GetTmpDir(), size);+ strlcpy(path, ggml_get_tmp_dir(), size);strlcat(path, "/.llamafile/", size);}-/**- * Returns true if `path` should replace `other`.- *- * The use case for this function is determining if a source code file- * needs to be rebuilt. In that case, `path` can be thought of as the- * source code file (which may reside under `/zip/...`, and `other`- * would be the generated artifact that's dependent on `path`.- */-bool ggml_is_newer_than(const char *path, const char *other) {+static int ggml_is_file_newer_than_time(const char *path, const char *other) {struct stat st1, st2;- if (stat(path, &st1) == -1) {+ if (stat(path, &st1)) {// PATH should always exist when calling this functionperror(path);- return false;+ return -1;}- if (stat(other, &st2) == -1) {+ if (stat(other, &st2)) {if (errno == ENOENT) {// PATH should replace OTHER because OTHER doesn't exist yetreturn true;} else {// some other error happened, so we can't do anything- perror(path);- return false;+ perror(other);+ return -1;}}// PATH should replace OTHER if PATH was modified more recentlyreturn timespec_cmp(st1.st_mtim, st2.st_mtim) > 0;}+static int ggml_is_file_newer_than_bytes(const char *path, const char *other) {+ int other_fd;+ if ((other_fd = open(other, O_RDONLY | O_CLOEXEC)) == -1) {+ if (errno == ENOENT) {+ return true;+ } else {+ perror(other);+ return -1;+ }+ }+ int path_fd;+ if ((path_fd = open(path, O_RDONLY | O_CLOEXEC)) == -1) {+ perror(path);+ close(other_fd);+ return -1;+ }+ int res;+ off_t i = 0;+ for (;;) {+ char path_buf[512];+ ssize_t path_rc = pread(path_fd, path_buf, sizeof(path_buf), i);+ if (path_rc == -1) {+ perror(path);+ res = -1;+ break;+ }+ char other_buf[512];+ ssize_t other_rc = pread(other_fd, other_buf, sizeof(other_buf), i);+ if (other_rc == -1) {+ perror(other);+ res = -1;+ break;+ }+ if (!path_rc || !other_rc) {+ if (!path_rc && !other_rc) {+ res = false;+ } else {+ res = true;+ }+ break;+ }+ size_t size = path_rc;+ if (other_rc < path_rc) {+ size = other_rc;+ }+ if (memcmp(path_buf, other_buf, size)) {+ res = true;+ break;+ }+ i += size;+ }+ if (close(path_fd)) {+ perror(path);+ res = -1;+ }+ if (close(other_fd)) {+ perror(other);+ res = -1;+ }+ return res;+}++/**+ * Returns true if `path` should replace `other`.+ *+ * The use case for this function is determining if a source code file+ * needs to be rebuilt. In that case, `path` can be thought of as the+ * source code file (which may reside under `/zip/...`, and `other`+ * would be the generated artifact that's dependent on `path`.+ */+int ggml_is_file_newer_than(const char *path, const char *other) {+ if (startswith(path, "/zip/")) {+ // to keep builds deterministic, embedded zip files always have+ // the same timestamp from back in 2022 when it was implemented+ return ggml_is_file_newer_than_bytes(path, other);+ } else {+ return ggml_is_file_newer_than_time(path, other);+ }+}+/*** Returns true if `zip` was successfully copied to `to`.*diff --git a/llama.cpp/ggml-file.c b/llama.cpp/ggml-file.cindex e486cce6..af8f798d 100644--- a/llama.cpp/ggml-file.c+++ b/llama.cpp/ggml-file.c@@ -1,5 +1,20 @@// -*- 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+//+// Copyright 2023 Mozilla Foundation+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.+#define _COSMO_SOURCE#include <cosmo.h>#include <errno.h>diff --git a/llama.cpp/llava/llava-quantize.cc b/llama.cpp/llava/llava-quantize.ccindex 766692e5..93be174d 100644--- a/llama.cpp/llava/llava-quantize.cc+++ b/llama.cpp/llava/llava-quantize.cc@@ -1,5 +1,20 @@-// -*- mode:c++;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-+// -*- 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+//+// Copyright 2023 Mozilla Foundation+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.+#include <stdio.h>#include <stdlib.h>#include "llama.cpp/ggml.h"diff --git a/llama.cpp/metal.c b/llama.cpp/metal.cindex 5a973a13..57f0022a 100644--- a/llama.cpp/metal.c+++ b/llama.cpp/metal.c@@ -1,5 +1,20 @@// -*- 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+//+// Copyright 2023 Mozilla Foundation+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.+#define _COSMO_SOURCE#include <cosmo.h>#include <time.h>diff --git a/llama.cpp/schlep.c b/llama.cpp/schlep.cindex ed7ae769..3004b0a5 100644--- a/llama.cpp/schlep.c+++ b/llama.cpp/schlep.c@@ -1,5 +1,20 @@// -*- 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+//+// Copyright 2023 Mozilla Foundation+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.+#define _COSMO_SOURCE#include <cosmo.h>#include <stdio.h>