Distribute and run LLMs with a single file.
C++ cross-platformggufllama-cpplocal-ailocal-inferencelocal-llmopen-source-aisingle-file-executablespeech-to-text
Optimize build latency of C++ headers
Justine Tunney3d5b5645f7e7
diff --git a/llama.cpp/common.h b/llama.cpp/common.hindex fd998513..84b0e14a 100644--- a/llama.cpp/common.h+++ b/llama.cpp/common.h@@ -20,9 +20,9 @@#include <cmath>#include <string>#include <vector>-#include <random>-#include <thread>-#include <unordered_map>+#include <__random/random_device.h> // [jart]+#include <__random/mersenne_twister_engine.h> // [jart]+// #include <unordered_map> // [jart]#include <tuple>#include <cosmo.h>diff --git a/llama.cpp/imatrix/imatrix.1.asc b/llama.cpp/imatrix/imatrix.1.ascindex 6e0cbac2..e4881e26 100644--- a/llama.cpp/imatrix/imatrix.1.asc+++ b/llama.cpp/imatrix/imatrix.1.asc@@ -1,30 +1,61 @@-LLAMAFILE-IMATRIX(1) BSD General Commands Manual LLAMAFILE-IMATRIX(1)+[4mLLAMAFILE-IMATRIX[24m(1) General Commands Manual [4mLLAMAFILE-IMATRIX[24m(1)-NNAAMMEE- llllaammaaffiillee--iimmaattrriixx — importance matrix builder+[1mNAME[0m+ llamafile-imatrix — importance matrix builder-SSYYNNOOPPSSIISS- llllaammaaffiillee--iimmaattrriixx [flags...]+[1mSYNOPSIS[0m+ [1mllamafile-imatrix [22m[flags...] [1m-m [4m[22mmodel.gguf[24m [1m-f [4m[22mtraining.data[0m+ [[1m-o [4m[22mimatrix.dat[24m]-DDEESSCCRRIIPPTTIIOONN- llllaammaaffiillee--iimmaattrriixx Compute an importance matrix for a model and given text- dataset. Can be used during quantization to enchance the quality of the- quantum models.+[1mDESCRIPTION[0m+ [1mllamafile-imatrix [22mCompute an importance matrix for a model and given+ text dataset. Can be used during quantization to enchance the quality+ of the quantum models. More information is available here:+ https://github.com/ggerganov/llama.cpp/pull/4861- More information is available here:- https://github.com/ggerganov/llama.cpp/pull/4861+[1mOPTIONS[0m+ The following options are available:-OOPPTTIIOONNSS- The following options are available:+ [1m--version[0m+ Print version and exit.- ----vveerrssiioonn- Print version and exit.+ [1m-h[22m, [1m--help[0m+ Show help message and exit.- --hh, ----hheellpp- Show help message and exit.+ [1m-m [4m[22mFNAME[24m, [1m--model [4m[22mFNAME[0m+ Model path in the GGUF file format.-SSEEEE AALLSSOO- llamafile(1), llamafile-quantize(1), llamafile-perplexity(1),- llava-quantize(1), zipalign(1), unzip(1)+ Default: [4mmodels/7B/ggml-model-f16.gguf[0m-Llamafile Manual December 5, 2023 Llamafile Manual+ [1m-f [4m[22mFNAME[24m, [1m--file [4m[22mFNAME[0m+ Mandatory path of file containing training data, e.g.+ [4mwiki.train.raw[0m++ [1m-o [4m[22mFNAME[24m, [1m--output-file [4m[22mFNAME[0m+ The name of the file where the computed data will be stored. If+ this flag is missing then [4mimatrix.dat[24m is used.++ [1m-ofreq[22m, [1m--output-frequency[0m+ Specifies how often the so far computed result is saved to+ disk. The default is is 10 (i.e., every 10 chunks).++ [1m-ow[22m, [1m--output-weight[0m+ Specifies if data will be collected for the [4moutput.weight[24m ten‐+ sor. Experience indicates that it is better to not utilize the+ importance matrix when quantizing [4moutput.weight[24m, so this is set+ to false by default.++ [1m--chunks [4m[22mN[0m+ Max number of chunks to process.++ [1m- [22m-1 = all++ Default: -1++[1mPROTIPS[0m+ For faster computation, pass the [1m-ngl [4m[22m9999[24m flag for GPU offloading.++[1mSEE ALSO[0m+ [4mllamafile[24m(1), [4mllamafile-quantize[24m(1)++Llamafile Manual December 5, 2023 [4mLLAMAFILE-IMATRIX[24m(1)diff --git a/llama.cpp/llama-bench/llama-bench.cpp b/llama.cpp/llama-bench/llama-bench.cppindex 07757109..218abd2e 100644--- a/llama.cpp/llama-bench/llama-bench.cpp+++ b/llama.cpp/llama-bench/llama-bench.cpp@@ -4,7 +4,7 @@#include <algorithm>#include <array>#include <cassert>-#include <chrono>+// #include <chrono> [jart]#include <cinttypes>#include <clocale>#include <cmath>diff --git a/llama.cpp/llava/llava-cli.cpp b/llama.cpp/llava/llava-cli.cppindex bc4032d8..3f13271c 100644--- a/llama.cpp/llava/llava-cli.cpp+++ b/llama.cpp/llava/llava-cli.cpp@@ -14,6 +14,7 @@#include <vector>#include <unistd.h>#include <signal.h>+#include <iostream>static bool eval_tokens(struct llama_context * ctx_llama, std::vector<llama_token> tokens, int n_batch, int * n_past) {int N = (int) tokens.size();diff --git a/llama.cpp/log.h b/llama.cpp/log.hindex 376daefd..fc6e7094 100644--- a/llama.cpp/log.h+++ b/llama.cpp/log.h@@ -2,11 +2,12 @@#define LOG_NO_TIMESTAMPS#define LOG_NO_FILE_LINE_FUNCTION-#include <chrono>+// #include <chrono> // [jart]#include <cstring>#include <sstream>-#include <iostream>-#include <thread>+// #include <iostream> // [jart]+#include <__thread/id.h> // [jart]+#include <__thread/thread.h> // [jart]#include <vector>#include <algorithm>#include "llamafile/log.h"diff --git a/llama.cpp/perplexity/perplexity.1.asc b/llama.cpp/perplexity/perplexity.1.ascindex ba693d9b..036e7c8d 100644--- a/llama.cpp/perplexity/perplexity.1.asc+++ b/llama.cpp/perplexity/perplexity.1.asc@@ -1,49 +1,74 @@-LLAMAFILE-PERPLEXITY(1) General Commands Manual LLAMAFILE-PERPLEXITY(1)+[4mLLAMAFILE-PERPLEXITY[24m(1) General Commands Manual [4mLLAMAFILE-PERPLEXITY[24m(1)-NNAAMMEE- llllaammaaffiillee--ppeerrpplleexxiittyy - LLM benchmarking tool+[1mNAME[0m+ llamafile-perplexity — LLM benchmarking tool-SSYYNNOOPPSSIISS- llllaammaaffiillee--ppeerrpplleexxiittyy [flags...]+[1mSYNOPSIS[0m+ [1mllamafile-perplexity [22m[flags...]-DDEESSCCRRIIPPTTIIOONN- Perplexity is one of the most common metrics for evaluating language- models. The llllaammaaffiillee--ppeerrpplleexxiittyy program can be used to gauge the quality- of an LLM implementation. It is defined as the exponentiated average- negative log-likelihood of a sequence, calculated with exponent base e.- Lower perplexity scores are better.+[1mDESCRIPTION[0m+ Perplexity is one of the most common metrics for evaluating language+ models. The [1mllamafile-perplexity [22mprogram can be used to gauge the qual‐+ ity of an LLM implementation. It is defined as the exponentiated aver‐+ age negative log-likelihood of a sequence, calculated with exponent+ base e. Lower perplexity scores are better.-OOPPTTIIOONNSS- The following options are available:+[1mOPTIONS[0m+ The following options are available:- --hh, ----hheellpp- Show help message and exit.+ [1m-h[22m, [1m--help[0m+ Show help message and exit.- --mm _F_N_A_M_E, ----mmooddeell _F_N_A_M_E- Model path (default: models/7B/ggml-model-f16.gguf)+ [1m-m [4m[22mFNAME[24m, [1m--model [4m[22mFNAME[0m+ Model path (default: models/7B/ggml-model-f16.gguf)- --ff _F_N_A_M_E, ----ffiillee _F_N_A_M_E- Raw data input file.+ [1m-f [4m[22mFNAME[24m, [1m--file [4m[22mFNAME[0m+ Raw data input file.- --tt _N, ----tthhrreeaaddss _N- Number of threads to use during generation (default: nproc/2)+ [1m--chunks [4m[22mN[0m+ Max number of chunks to process.- --ss _S_E_E_D, ----sseeeedd _S_E_E_D- Random Number Generator (RNG) seed (default: -1, use random seed- for < 0)+ [1m- [22m-1 = all-EEXXAAMMPPLLEE- One dataset commonly used in the llama.cpp community for measuring- perplexity is wikitext-2-raw. To use it when testing how well both your- model and llamafile are performing you could run the following:+ Default: -1- wget https://cosmo.zip/pub/datasets/wikitext-2-raw/wiki.test.raw- llamafile-perplexity -m model.gguf -f wiki.test.raw -s 31337+ [1m-t [4m[22mN[24m, [1m--threads [4m[22mN[0m+ Number of threads to use during generation (default: nproc/2)- This can sometimes lead to surprising conclusions, like how Q5 weights- might be better for a particular model than Q6.+ [1m-s [4m[22mSEED[24m, [1m--seed [4m[22mSEED[0m+ Random Number Generator (RNG) seed (default: -1, use random+ seed for < 0)-SSEEEE AALLSSOO- llamafile(1)+ [1m--hellaswag[0m+ Compute HellaSwag score over random tasks from datafile sup‐+ plied with -f-Llamafile Manual December 5, 2023 Llamafile Manual+ [1m--hellaswag-tasks [4m[22mN[0m+ Number of tasks to use when computing the HellaSwag score.++ Default: 400++ [1m--winogrande[0m+ Compute Winogrande score over random tasks from datafile sup‐+ plied by the [1m-f [22mflag.++ [1m--winogrande-tasks [4m[22mN[0m+ Number of tasks to use when computing the Winogrande score.++ Default: 0++[1mEXAMPLE[0m+ One dataset commonly used in the llama.cpp community for measuring per‐+ plexity is wikitext-2-raw. To use it when testing how well both your+ model and llamafile are performing you could run the following:++ wget https://cosmo.zip/pub/datasets/wikitext-2-raw/wiki.test.raw+ llamafile-perplexity -m model.gguf -f wiki.test.raw -s 31337++ This can sometimes lead to surprising conclusions, like how Q5 weights+ might be better for a particular model than Q6.++[1mSEE ALSO[0m+ [4mllamafile[24m(1)++Llamafile Manual December 5, 2023 [4mLLAMAFILE-PERPLEXITY[24m(1)diff --git a/llama.cpp/sampling.h b/llama.cpp/sampling.hindex eeaa53b8..293af72b 100644--- a/llama.cpp/sampling.h+++ b/llama.cpp/sampling.h@@ -4,7 +4,7 @@#include "grammar-parser.h"-#include <random>+#include <__random/mersenne_twister_engine.h> // [jart]#include <string>#include <unordered_map>#include <vector>diff --git a/llama.cpp/server/server.cpp b/llama.cpp/server/server.cppindex e3b719e8..88dd6689 100644--- a/llama.cpp/server/server.cpp+++ b/llama.cpp/server/server.cpp@@ -20,7 +20,7 @@#include <cstddef>#include <thread>-#include <chrono>+// #include <chrono> // [jart]#include <condition_variable>#include <atomic>#include <signal.h>diff --git a/llama.cpp/server/utils.h b/llama.cpp/server/utils.hindex cde8548b..5034a512 100644--- a/llama.cpp/server/utils.h+++ b/llama.cpp/server/utils.h@@ -9,6 +9,7 @@#include <mutex>#include <condition_variable>#include <unordered_map>+#include <iostream> // [jart]#include "llama.cpp/json.h"#include "llama.cpp/llava/clip.h"diff --git a/llamafile/chatbot.h b/llamafile/chatbot.hindex a8a6de8a..c92b35a9 100644--- a/llamafile/chatbot.h+++ b/llamafile/chatbot.h@@ -16,8 +16,8 @@// limitations under the License.#pragma once-#include <string>-#include <vector>+#include <__fwd/string.h>+#include <__fwd/vector.h>#define RESET "\e[0m"#define BOLD "\e[1m"diff --git a/llamafile/chatbot_help.cpp b/llamafile/chatbot_help.cppindex 20e62c7c..721e37d0 100644--- a/llamafile/chatbot_help.cpp+++ b/llamafile/chatbot_help.cpp@@ -17,6 +17,8 @@#include "chatbot.h"+#include <vector>+void chatbot_help(const std::vector<std::string> &args) {if (args.size() == 1) {fprintf(stderr, "\diff --git a/llamafile/datauri.h b/llamafile/datauri.hindex d243d977..bc971078 100644--- a/llamafile/datauri.h+++ b/llamafile/datauri.h@@ -16,8 +16,8 @@// limitations under the License.#pragma once-#include <string>-#include <utility>+#include <__fwd/string.h>+#include <string_view>#include <vector>struct DataUri {diff --git a/llamafile/datauri_test.cpp b/llamafile/datauri_test.cppindex a9e18fdf..cbdcac81 100644--- a/llamafile/datauri_test.cpp+++ b/llamafile/datauri_test.cpp@@ -18,6 +18,9 @@#include "datauri.h"#include "image.h"+#include <string>+#include <vector>+namespace {void rfc2397_example1() {diff --git a/llamafile/flags.cpp b/llamafile/flags.cppindex b9b11c9e..3266107e 100644--- a/llamafile/flags.cpp+++ b/llamafile/flags.cpp@@ -27,8 +27,10 @@#include <math.h>#include <stdio.h>#include <stdlib.h>+#include <string>#include <time.h>#include <unistd.h>+#include <vector>#include "llama.cpp/cores.h"#include "llama.cpp/llama.h"diff --git a/llamafile/flags.h b/llamafile/flags.hindex 5a5f7370..3379aa9a 100644--- a/llamafile/flags.h+++ b/llamafile/flags.h@@ -16,7 +16,7 @@// limitations under the License.#pragma once-#include <string>-#include <vector>+#include <__fwd/string.h>+#include <__fwd/vector.h>extern std::vector<std::string> FLAG_headers;diff --git a/llamafile/iso8601.cpp b/llamafile/iso8601.cppindex d2179fb8..974360e5 100644--- a/llamafile/iso8601.cpp+++ b/llamafile/iso8601.cpp@@ -17,11 +17,11 @@#include "string.h"-#include <assert.h>-#include <stdio.h>-#include <stdlib.h>+#include <cassert>+#include <cstdio>+#include <cstdlib>+#include <ctime>#include <string>-#include <time.h>namespace lf {diff --git a/llamafile/parse_cidr.cpp b/llamafile/parse_cidr.cppindex 4b08d085..948bdd85 100644--- a/llamafile/parse_cidr.cpp+++ b/llamafile/parse_cidr.cpp@@ -17,8 +17,9 @@#include "trust.h"+#include <cstring>#include <ctype.h>-#include <string.h>+#include <string>bool parse_cidr(const std::string_view &str, cidr *out_cidr) noexcept {long ip;diff --git a/llamafile/parse_cidr_test.cpp b/llamafile/parse_cidr_test.cppindex a7a5bd00..d0f6e80f 100644--- a/llamafile/parse_cidr_test.cpp+++ b/llamafile/parse_cidr_test.cpp@@ -17,6 +17,8 @@#include "trust.h"+#include <string>+int main(int argc, char *argv[]) {cidr in;diff --git a/llamafile/parse_ip.cpp b/llamafile/parse_ip.cppindex 65be09dd..bec01199 100644--- a/llamafile/parse_ip.cpp+++ b/llamafile/parse_ip.cpp@@ -17,9 +17,10 @@#include "trust.h"-#include <ctype.h>+#include <cctype>+#include <cstring>#include <stdckdint.h>-#include <string.h>+#include <string>long parse_ip(const std::string_view &str) noexcept {int c, j;diff --git a/llamafile/server/atob.cpp b/llamafile/server/atob.cppindex 5f02362e..e8a1b738 100644--- a/llamafile/server/atob.cpp+++ b/llamafile/server/atob.cpp@@ -17,6 +17,8 @@#include "utils.h"+#include <string_view>+boolatob(std::string_view val, bool dflt){diff --git a/llamafile/server/buffer.h b/llamafile/server/buffer.hindex 757a5d15..5a53dd91 100644--- a/llamafile/server/buffer.h+++ b/llamafile/server/buffer.h@@ -16,7 +16,7 @@// limitations under the License.#pragma once-#include <stddef.h>+#include <cstddef>struct Buffer{diff --git a/llamafile/server/client.cpp b/llamafile/server/client.cppindex bebea08b..30b42280 100644--- a/llamafile/server/client.cpp+++ b/llamafile/server/client.cpp@@ -21,10 +21,12 @@#include <fcntl.h>#include <limits.h>#include <string.h>+#include <string>#include <sys/stat.h>#include <sys/uio.h>#include <time.h>#include <unistd.h>+#include <vector>#include "llama.cpp/llama.h"#include "llamafile/flags.h"diff --git a/llamafile/server/fastjson.h b/llamafile/server/fastjson.hindex 5740df98..c0b02ccc 100644--- a/llamafile/server/fastjson.h+++ b/llamafile/server/fastjson.h@@ -16,7 +16,7 @@// limitations under the License.#pragma once-#include <string_view>+#include <__fwd/string_view.h>char*encode_bool(char*, bool) noexcept;diff --git a/llamafile/server/or_empty.cpp b/llamafile/server/or_empty.cppindex 7eb4e01a..93c76dfd 100644--- a/llamafile/server/or_empty.cpp+++ b/llamafile/server/or_empty.cpp@@ -17,6 +17,8 @@#include "utils.h"+#include <string_view>+std::string_viewor_empty(std::optional<std::string_view> x){diff --git a/llamafile/server/server.h b/llamafile/server/server.hindex da7038e2..ebce3a41 100644--- a/llamafile/server/server.h+++ b/llamafile/server/server.h@@ -19,7 +19,6 @@#include <atomic>#include <cosmo.h>#include <pthread.h>-#include <string>struct Slots;struct llama_model;diff --git a/llamafile/server/slot.h b/llamafile/server/slot.hindex c7349c08..ffab94de 100644--- a/llamafile/server/slot.h+++ b/llamafile/server/slot.h@@ -18,7 +18,6 @@#pragma once#include <string>#include <time.h>-#include <utility>#include <vector>struct llama_model;diff --git a/llamafile/server/utils.h b/llamafile/server/utils.hindex 9295a4f7..e5bbdf0e 100644--- a/llamafile/server/utils.h+++ b/llamafile/server/utils.h@@ -16,9 +16,9 @@// limitations under the License.#pragma once+#include <__fwd/string.h>+#include <__fwd/string_view.h>#include <optional>-#include <string>-#include <string_view>extern const signed char kHexToInt[256];diff --git a/llamafile/slurp.cpp b/llamafile/slurp.cppindex 84747d2e..11b3a760 100644--- a/llamafile/slurp.cpp+++ b/llamafile/slurp.cpp@@ -18,6 +18,7 @@#include "string.h"#include <fcntl.h>+#include <string>#include <unistd.h>namespace lf {diff --git a/llamafile/string.cpp b/llamafile/string.cppindex 3f98af5e..85df711f 100644--- a/llamafile/string.cpp+++ b/llamafile/string.cpp@@ -20,6 +20,8 @@#include <cctype>#include <cosmo.h>#include <cstdio>+#include <string>+#include <vector>namespace lf {diff --git a/llamafile/string.h b/llamafile/string.hindex 70667011..52c3fb84 100644--- a/llamafile/string.h+++ b/llamafile/string.h@@ -16,9 +16,10 @@// limitations under the License.#pragma once-#include <string>+#include <__fwd/string.h>+#include <__fwd/string_view.h>+#include <__fwd/vector.h>#include <time.h>-#include <vector>namespace lf {diff --git a/llamafile/trust.cpp b/llamafile/trust.cppindex 761ad0b6..04756262 100644--- a/llamafile/trust.cpp+++ b/llamafile/trust.cpp@@ -17,6 +17,8 @@#include "trust.h"+#include <vector>+std::vector<cidr> FLAG_trust;bool is_trusted_ip(unsigned ip) noexcept {diff --git a/llamafile/trust.h b/llamafile/trust.hindex 682621ab..a410bd0a 100644--- a/llamafile/trust.h+++ b/llamafile/trust.h@@ -16,8 +16,8 @@// limitations under the License.#pragma once-#include <string>-#include <vector>+#include <__fwd/string_view.h>+#include <__fwd/vector.h>struct cidr {unsigned ip;diff --git a/llamafile/vector.h b/llamafile/vector.hindex 7cdaafaf..e86a9dba 100644--- a/llamafile/vector.h+++ b/llamafile/vector.h@@ -16,8 +16,8 @@// limitations under the License.#pragma once+#include <__fwd/vector.h>#include <algorithm>-#include <vector>namespace lf {