Skip to content

Distribute and run LLMs with a single file.

Optimize build latency of C++ headers

Justine Tunney3d5b5645f7e7
diff --git a/llama.cpp/common.h b/llama.cpp/common.h
index 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.asc
index 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)
+LLAMAFILE-IMATRIX(1) General Commands Manual LLAMAFILE-IMATRIX(1)
-NNAAMMEE
- llllaammaaffiillee--iimmaattrriixx — importance matrix builder
+NAME
+ llamafile-imatrix — importance matrix builder
-SSYYNNOOPPSSIISS
- llllaammaaffiillee--iimmaattrriixx [flags...]
+SYNOPSIS
+ llamafile-imatrix [flags...] -m model.gguf -f training.data
+ [-o imatrix.dat]
-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.
+DESCRIPTION
+ llamafile-imatrix Compute 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
+OPTIONS
+ The following options are available:
-OOPPTTIIOONNSS
- The following options are available:
+ --version
+ Print version and exit.
- ----vveerrssiioonn
- Print version and exit.
+ -h, --help
+ Show help message and exit.
- --hh, ----hheellpp
- Show help message and exit.
+ -m FNAME, --model FNAME
+ 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: models/7B/ggml-model-f16.gguf
-Llamafile Manual December 5, 2023 Llamafile Manual
+ -f FNAME, --file FNAME
+ Mandatory path of file containing training data, e.g.
+ wiki.train.raw
+
+ -o FNAME, --output-file FNAME
+ The name of the file where the computed data will be stored. If
+ this flag is missing then imatrix.dat is used.
+
+ -ofreq, --output-frequency
+ Specifies how often the so far computed result is saved to
+ disk. The default is is 10 (i.e., every 10 chunks).
+
+ -ow, --output-weight
+ Specifies if data will be collected for the output.weight ten‐
+ sor. Experience indicates that it is better to not utilize the
+ importance matrix when quantizing output.weight, so this is set
+ to false by default.
+
+ --chunks N
+ Max number of chunks to process.
+
+ - -1 = all
+
+ Default: -1
+
+PROTIPS
+ For faster computation, pass the -ngl 9999 flag for GPU offloading.
+
+SEE ALSO
+ llamafile(1), llamafile-quantize(1)
+
+Llamafile Manual December 5, 2023 LLAMAFILE-IMATRIX(1)
diff --git a/llama.cpp/llama-bench/llama-bench.cpp b/llama.cpp/llama-bench/llama-bench.cpp
index 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.cpp
index 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.h
index 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.asc
index 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)
+LLAMAFILE-PERPLEXITY(1) General Commands Manual LLAMAFILE-PERPLEXITY(1)
-NNAAMMEE
- llllaammaaffiillee--ppeerrpplleexxiittyy - LLM benchmarking tool
+NAME
+ llamafile-perplexity — LLM benchmarking tool
-SSYYNNOOPPSSIISS
- llllaammaaffiillee--ppeerrpplleexxiittyy [flags...]
+SYNOPSIS
+ llamafile-perplexity [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.
+DESCRIPTION
+ Perplexity is one of the most common metrics for evaluating language
+ models. The llamafile-perplexity program 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:
+OPTIONS
+ The following options are available:
- --hh, ----hheellpp
- Show help message and exit.
+ -h, --help
+ 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)
+ -m FNAME, --model FNAME
+ 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.
+ -f FNAME, --file FNAME
+ Raw data input file.
- --tt _N, ----tthhrreeaaddss _N
- Number of threads to use during generation (default: nproc/2)
+ --chunks N
+ 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)
+ - -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
+ -t N, --threads N
+ 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.
+ -s SEED, --seed SEED
+ Random Number Generator (RNG) seed (default: -1, use random
+ seed for < 0)
-SSEEEE AALLSSOO
- llamafile(1)
+ --hellaswag
+ Compute HellaSwag score over random tasks from datafile sup‐
+ plied with -f
-Llamafile Manual December 5, 2023 Llamafile Manual
+ --hellaswag-tasks N
+ Number of tasks to use when computing the HellaSwag score.
+
+ Default: 400
+
+ --winogrande
+ Compute Winogrande score over random tasks from datafile sup‐
+ plied by the -f flag.
+
+ --winogrande-tasks N
+ Number of tasks to use when computing the Winogrande score.
+
+ Default: 0
+
+EXAMPLE
+ 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.
+
+SEE ALSO
+ llamafile(1)
+
+Llamafile Manual December 5, 2023 LLAMAFILE-PERPLEXITY(1)
diff --git a/llama.cpp/sampling.h b/llama.cpp/sampling.h
index 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.cpp
index 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.h
index 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.h
index 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.cpp
index 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.h
index 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.cpp
index 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.cpp
index 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.h
index 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.cpp
index 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.cpp
index 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.cpp
index 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.cpp
index 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.cpp
index 5f02362e..e8a1b738 100644
--- a/llamafile/server/atob.cpp
+++ b/llamafile/server/atob.cpp
@@ -17,6 +17,8 @@
#include "utils.h"
+#include <string_view>
+
bool
atob(std::string_view val, bool dflt)
{
diff --git a/llamafile/server/buffer.h b/llamafile/server/buffer.h
index 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.cpp
index 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.h
index 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.cpp
index 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_view
or_empty(std::optional<std::string_view> x)
{
diff --git a/llamafile/server/server.h b/llamafile/server/server.h
index 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.h
index 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.h
index 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.cpp
index 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.cpp
index 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.h
index 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.cpp
index 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.h
index 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.h
index 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 {