Skip to content

Distribute and run LLMs with a single file.

Write a lot of documentation and man pages

Justine Tunney202e554509fe
diff --git a/Makefile b/Makefile
index 997a35db..e3f6f6ef 100644
--- a/Makefile
+++ b/Makefile
@@ -31,11 +31,13 @@ o/$(MODE)/: o/$(MODE)/llamafile \
# for installing to `make PREFIX=/usr/local`
.PHONY: install
install: llamafile/zipalign.1 \
+ llamafile/server/main.1 \
llama.cpp/main/main.1 \
llama.cpp/imatrix/imatrix.1 \
llama.cpp/quantize/quantize.1 \
llama.cpp/perplexity/perplexity.1 \
llama.cpp/llava/llava-quantize.1 \
+ whisper.cpp/main.1 \
o/$(MODE)/llamafile/zipalign \
o/$(MODE)/llamafile/tokenize \
o/$(MODE)/llama.cpp/main/main \
@@ -62,11 +64,13 @@ install: llamafile/zipalign.1 \
$(INSTALL) o/$(MODE)/whisper.cpp/main $(PREFIX)/bin/whisperfile
mkdir -p $(PREFIX)/share/man/man1
$(INSTALL) -m 0644 llamafile/zipalign.1 $(PREFIX)/share/man/man1/zipalign.1
+ $(INSTALL) -m 0644 llamafile/server/main.1 $(PREFIX)/share/man/man1/llamafiler.1
$(INSTALL) -m 0644 llama.cpp/main/main.1 $(PREFIX)/share/man/man1/llamafile.1
$(INSTALL) -m 0644 llama.cpp/imatrix/imatrix.1 $(PREFIX)/share/man/man1/llamafile-imatrix.1
$(INSTALL) -m 0644 llama.cpp/quantize/quantize.1 $(PREFIX)/share/man/man1/llamafile-quantize.1
$(INSTALL) -m 0644 llama.cpp/perplexity/perplexity.1 $(PREFIX)/share/man/man1/llamafile-perplexity.1
$(INSTALL) -m 0644 llama.cpp/llava/llava-quantize.1 $(PREFIX)/share/man/man1/llava-quantize.1
+ $(INSTALL) -m 0644 whisper.cpp/main.1 $(PREFIX)/share/man/man1/whisperfile.1
.PHONY: check
check: o/$(MODE)/llamafile/check
diff --git a/llama.cpp/common.cpp b/llama.cpp/common.cpp
index c1f68415..73060a9d 100644
--- a/llama.cpp/common.cpp
+++ b/llama.cpp/common.cpp
@@ -640,14 +640,20 @@ bool gpt_params_find_arg(int argc, char ** argv, const std::string & arg, gpt_pa
}
if (arg == "--lora") {
CHECK_ARG
- params.lora_adapter.emplace_back(argv[i], 1.0f);
+ params.lora_adapters.push_back({
+ std::string(argv[i]),
+ 1.0,
+ });
return true;
}
if (arg == "--lora-scaled") {
CHECK_ARG
const char* lora_adapter = argv[i];
CHECK_ARG
- params.lora_adapter.emplace_back(lora_adapter, std::stof(argv[i]));
+ params.lora_adapters.push_back({
+ lora_adapter,
+ std::stof(argv[i]),
+ });
return true;
}
if (arg == "--control-vector") {
@@ -1725,6 +1731,17 @@ std::string string_get_sortable_timestamp() {
return std::string(timestamp_no_ns) + "." + std::string(timestamp_ns);
}
+void string_replace_all(std::string & s, const std::string & search, const std::string & replace) {
+ if (search.empty()) {
+ return; // Avoid infinite loop if 'search' is an empty string
+ }
+ size_t pos = 0;
+ while ((pos = s.find(search, pos)) != std::string::npos) {
+ s.replace(pos, search.length(), replace);
+ pos += replace.length();
+ }
+}
+
void string_process_escapes(std::string & input) {
std::size_t input_len = input.length();
std::size_t output_idx = 0;
@@ -1998,8 +2015,8 @@ std::string fs_get_cache_file(const std::string & filename) {
//
// Model utils
//
-
-std::tuple<struct llama_model *, struct llama_context *> llama_init_from_gpt_params(gpt_params & params) {
+struct llama_init_result llama_init_from_gpt_params(gpt_params & params) {
+ llama_init_result iparams;
auto mparams = llama_model_params_from_gpt_params(params);
llama_model * model = nullptr;
@@ -2014,7 +2031,7 @@ std::tuple<struct llama_model *, struct llama_context *> llama_init_from_gpt_par
if (model == NULL) {
fprintf(stderr, "%s: error: failed to load model '%s'\n", __func__, params.model.c_str());
- return std::make_tuple(nullptr, nullptr);
+ return iparams;
}
auto cparams = llama_context_params_from_gpt_params(params);
@@ -2023,7 +2040,7 @@ std::tuple<struct llama_model *, struct llama_context *> llama_init_from_gpt_par
if (lctx == NULL) {
fprintf(stderr, "%s: error: failed to create context with model '%s'\n", __func__, params.model.c_str());
llama_free_model(model);
- return std::make_tuple(nullptr, nullptr);
+ return iparams;
}
if (!params.control_vectors.empty()) {
@@ -2034,7 +2051,7 @@ std::tuple<struct llama_model *, struct llama_context *> llama_init_from_gpt_par
if (cvec.n_embd == -1) {
llama_free(lctx);
llama_free_model(model);
- return std::make_tuple(nullptr, nullptr);
+ return iparams;
}
int err = llama_control_vector_apply(lctx,
@@ -2046,21 +2063,26 @@ std::tuple<struct llama_model *, struct llama_context *> llama_init_from_gpt_par
if (err) {
llama_free(lctx);
llama_free_model(model);
- return std::make_tuple(nullptr, nullptr);
+ return iparams;
}
}
- for (unsigned int i = 0; i < params.lora_adapter.size(); ++i) {
- const std::string & lora_adapter = std::get<0>(params.lora_adapter[i]);
- float lora_scale = std::get<1>(params.lora_adapter[i]);
- auto adapter = llama_lora_adapter_init(model, lora_adapter.c_str());
- if (adapter == nullptr) {
- fprintf(stderr, "%s: error: failed to apply lora adapter\n", __func__);
+ // load and optionally apply lora adapters
+ for (auto & la : params.lora_adapters) {
+ llama_lora_adapter_container loaded_la;
+ loaded_la.path = la.path;
+ loaded_la.scale = la.scale;
+ loaded_la.adapter = llama_lora_adapter_init(model, la.path.c_str());
+ if (loaded_la.adapter == nullptr) {
+ fprintf(stderr, "%s: error: failed to apply lora adapter '%s'\n", __func__, la.path.c_str());
llama_free(lctx);
llama_free_model(model);
- return std::make_tuple(nullptr, nullptr);
+ return iparams;
}
- llama_lora_adapter_set(lctx, adapter, lora_scale);
+ iparams.lora_adapters.push_back(loaded_la); // copy to list of loaded adapters
+ }
+ if (!params.lora_init_without_apply) {
+ llama_lora_adapters_apply(lctx, iparams.lora_adapters);
}
if (params.ignore_eos) {
@@ -2088,13 +2110,26 @@ std::tuple<struct llama_model *, struct llama_context *> llama_init_from_gpt_par
tmp.clear();
tmp.push_back(decoder_start_token_id);
}
- llama_decode(lctx, llama_batch_get_one(tmp.data(), std::min(tmp.size(), (size_t) params.n_batch), 0, 0));
+ if (llama_model_has_decoder(model)) {
+ llama_decode(lctx, llama_batch_get_one(tmp.data(), std::min(tmp.size(), (size_t) params.n_batch), 0, 0));
+ }
llama_kv_cache_clear(lctx);
llama_synchronize(lctx);
llama_reset_timings(lctx);
}
- return std::make_tuple(model, lctx);
+ iparams.model = model;
+ iparams.context = lctx;
+ return iparams;
+}
+
+void llama_lora_adapters_apply(struct llama_context * ctx, std::vector<llama_lora_adapter_container> & lora_adapters) {
+ llama_lora_adapter_clear(ctx);
+ for (auto & la : lora_adapters) {
+ if (la.scale != 0.0f) {
+ llama_lora_adapter_set(ctx, la.adapter, la.scale);
+ }
+ }
}
struct llama_model_params llama_model_params_from_gpt_params(const gpt_params & params) {
@@ -3126,18 +3161,16 @@ void yaml_dump_non_result_info(FILE * stream, const gpt_params & params, const l
}
fprintf(stream, "lora:\n");
- for (std::tuple<std::string, float> la : params.lora_adapter) {
- if (std::get<1>(la) != 1.0f) {
- continue;
+ for (auto & la : params.lora_adapters) {
+ if (la.scale == 1.0f) {
+ fprintf(stream, " - %s\n", la.path.c_str());
}
- fprintf(stream, " - %s\n", std::get<0>(la).c_str());
}
fprintf(stream, "lora_scaled:\n");
- for (std::tuple<std::string, float> la : params.lora_adapter) {
- if (std::get<1>(la) == 1.0f) {
- continue;
+ for (auto & la : params.lora_adapters) {
+ if (la.scale != 1.0f) {
+ fprintf(stream, " - %s: %f\n", la.path.c_str(), la.scale);
}
- fprintf(stream, " - %s: %f\n", std::get<0>(la).c_str(), std::get<1>(la));
}
fprintf(stream, "main_gpu: %d # default: 0\n", params.main_gpu);
fprintf(stream, "min_keep: %d # default: 0 (disabled)\n", sparams.min_keep);
diff --git a/llama.cpp/common.h b/llama.cpp/common.h
index 05048e11..01129959 100644
--- a/llama.cpp/common.h
+++ b/llama.cpp/common.h
@@ -38,6 +38,15 @@
#define DEFAULT_MODEL_PATH "models/7B/ggml-model-f16.gguf"
+struct llama_lora_adapter_info {
+ std::string path;
+ float scale;
+};
+
+struct llama_lora_adapter_container : llama_lora_adapter_info {
+ struct llama_lora_adapter * adapter;
+};
+
// build info
extern int LLAMA_BUILD_NUMBER;
extern char const * LLAMA_COMMIT;
@@ -131,8 +140,8 @@ struct gpt_params {
std::vector<std::string> antiprompt; // strings upon which more user input is prompted (a.k.a. reverse prompts)
std::vector<llama_model_kv_override> kv_overrides;
- // TODO: avoid tuple, use struct
- std::vector<std::tuple<std::string, float>> lora_adapter; // lora adapter path with user defined scale
+ bool lora_init_without_apply = false; // only load lora to memory, but do not apply it to ctx (user can manually apply lora later using llama_lora_adapter_apply)
+ std::vector<llama_lora_adapter_info> lora_adapters; // lora adapter path with user defined scale
std::vector<llama_control_vector_load_info> control_vectors; // control vector with user defined scale
@@ -282,6 +291,8 @@ std::vector<std::string> string_split(std::string input, char separator);
std::string string_strip(const std::string & str);
std::string string_get_sortable_timestamp();
+void string_replace_all(std::string & s, const std::string & search, const std::string & replace);
+
template<class T>
static std::vector<T> string_split(const std::string & str, char delim) {
std::vector<T> values;
@@ -313,8 +324,13 @@ std::string fs_get_cache_file(const std::string & filename);
// Model utils
//
-// TODO: avoid tuplue, use struct
-std::tuple<struct llama_model *, struct llama_context *> llama_init_from_gpt_params(gpt_params & params);
+struct llama_init_result {
+ struct llama_model * model = nullptr;
+ struct llama_context * context = nullptr;
+ std::vector<llama_lora_adapter_container> lora_adapters;
+};
+
+struct llama_init_result llama_init_from_gpt_params(gpt_params & params);
struct llama_model_params llama_model_params_from_gpt_params (const gpt_params & params);
struct llama_context_params llama_context_params_from_gpt_params(const gpt_params & params);
@@ -322,6 +338,9 @@ struct llama_context_params llama_context_params_from_gpt_params(const gpt_param
struct llama_model * llama_load_model_from_url(const char * model_url, const char * path_model, const char * hf_token, const struct llama_model_params & params);
struct llama_model * llama_load_model_from_hf(const char * repo, const char * file, const char * path_model, const char * hf_token, const struct llama_model_params & params);
+// clear LoRA adapters from context, then apply new list of adapters
+void llama_lora_adapters_apply(struct llama_context * ctx, std::vector<llama_lora_adapter_container> & lora_adapters);
+
// Batch utils
void llama_batch_clear(struct llama_batch & batch);
diff --git a/llama.cpp/imatrix/imatrix.cpp b/llama.cpp/imatrix/imatrix.cpp
index e6423cf4..201c517f 100644
--- a/llama.cpp/imatrix/imatrix.cpp
+++ b/llama.cpp/imatrix/imatrix.cpp
@@ -437,8 +437,8 @@ static void process_logits(
}
static bool compute_imatrix(llama_context * ctx, const gpt_params & params) {
- const bool add_bos = llama_should_add_bos_token(llama_get_model(ctx));
- GGML_ASSERT(llama_add_eos_token(llama_get_model(ctx)) != 1);
+ const bool add_bos = llama_add_bos_token(llama_get_model(ctx));
+ GGML_ASSERT(!llama_add_eos_token(llama_get_model(ctx)));
const int n_ctx = llama_n_ctx(ctx);
auto tim1 = std::chrono::high_resolution_clock::now();
@@ -629,10 +629,10 @@ int main(int argc, char ** argv) {
params.warmup = false;
// init
- llama_model * model;
- llama_context * ctx;
+ llama_init_result llama_init = llama_init_from_gpt_params(params);
- std::tie(model, ctx) = llama_init_from_gpt_params(params);
+ llama_model * model = llama_init.model;
+ llama_context * ctx = llama_init.context;
if (model == nullptr || ctx == nullptr) {
fprintf(stderr, "%s : failed to init\n", __func__);
return 1;
diff --git a/llama.cpp/main/embedding.cpp b/llama.cpp/main/embedding.cpp
index f1463d5b..0bd15933 100644
--- a/llama.cpp/main/embedding.cpp
+++ b/llama.cpp/main/embedding.cpp
@@ -99,11 +99,11 @@ int embedding_cli(int argc, char ** argv) {
llama_backend_init();
llama_numa_init(params.numa);
- llama_model * model;
- llama_context * ctx;
-
// load the model
- std::tie(model, ctx) = llama_init_from_gpt_params(params);
+ llama_init_result llama_init = llama_init_from_gpt_params(params);
+
+ llama_model * model = llama_init.model;
+ llama_context * ctx = llama_init.context;
if (model == NULL) {
fprintf(stderr, "%s: error: unable to load model\n", __func__);
return 1;
diff --git a/llama.cpp/main/main.1.asc b/llama.cpp/main/main.1.asc
index df24c93c..2fa76cbf 100644
--- a/llama.cpp/main/main.1.asc
+++ b/llama.cpp/main/main.1.asc
@@ -42,7 +42,7 @@
-m FNAME, --model FNAME
Model path in the GGUF file format.
- Default: models/7B/ggml‐model‐f16.gguf
+ Default: models/7B/ggml-model-f16.gguf
--mmproj FNAME
Specifies path of the LLaVA vision model in the GGUF file for‐
@@ -53,14 +53,14 @@
Random Number Generator (RNG) seed. A random seed is used if
this is less than zero.
- Default: ‐1
+ Default: -1
-t N, --threads N
Number of threads to use during generation.
Default: $(nproc)/2
- -tb N, --threads‐batch N
+ -tb N, --threads-batch N
Set the number of threads to use during batch and prompt pro‐
cessing. In some systems, it is beneficial to use a higher num‐
ber of threads during batch processing than during generation.
@@ -70,51 +70,51 @@
Default: Same as --threads
- -td N, --threads‐draft N
+ -td N, --threads-draft N
Number of threads to use during generation.
Default: Same as --threads
- -tbd N, --threads‐batch‐draft N
+ -tbd N, --threads-batch-draft N
Number of threads to use during batch and prompt processing.
- Default: Same as --threads‐draft
+ Default: Same as --threads-draft
- --in‐prefix‐bos
- Prefix BOS to user inputs, preceding the --in‐prefix string.
+ --in-prefix-bos
+ Prefix BOS to user inputs, preceding the --in-prefix string.
- --in‐prefix STRING
+ --in-prefix STRING
This flag is used to add a prefix to your input, primarily,
- this is used to insert a space after the reverse prompt. Here’s
- an example of how to use the --in‐prefix flag in conjunction
- with the --reverse‐prompt flag:
+ this is used to insert a space after the reverse prompt. Here's
+ an example of how to use the --in-prefix flag in conjunction
+ with the --reverse-prompt flag:
- ./main ‐r "User:" ‐‐in‐prefix " "
+ ./main -r "User:" --in-prefix " "
Default: empty
- --in‐suffix STRING
+ --in-suffix STRING
This flag is used to add a suffix after your input. This is
- useful for adding an "Assistant:" prompt after the user’s in‐
- put. It’s added after the new‐line character (\n) that’s auto‐
- matically added to the end of the user’s input. Here’s an exam‐
- ple of how to use the --in‐suffix flag in conjunction with the
- --reverse‐prompt flag:
+ useful for adding an "Assistant:" prompt after the user's in‐
+ put. It's added after the new-line character (\n) that's auto‐
+ matically added to the end of the user's input. Here's an exam‐
+ ple of how to use the --in-suffix flag in conjunction with the
+ --reverse-prompt flag:
- ./main ‐r "User:" ‐‐in‐prefix " " ‐‐in‐suffix
+ ./main -r "User:" --in-prefix " " --in-suffix
"Assistant:"
Default: empty
- -n N, --n‐predict N
+ -n N, --n-predict N
Number of tokens to predict.
- - ‐1 = infinity
- - ‐2 = until context filled
+ - -1 = infinity
+ - -2 = until context filled
- Default: ‐1
+ Default: -1
- -c N, --ctx‐size N
+ -c N, --ctx-size N
Set the size of the prompt context. A larger context size helps
the model to better comprehend and generate responses for
longer input or conversations. The LLaMA models were built with
@@ -125,27 +125,27 @@
Default: 512
- -b N, --batch‐size N
+ -b N, --batch-size N
Batch size for prompt processing.
Default: 512
- --top‐k N
- Top‐k sampling.
+ --top-k N
+ Top-k sampling.
- 0 = disabled
Default: 40
- --top‐p N
- Top‐p sampling.
+ --top-p N
+ Top-p sampling.
- 1.0 = disabled
Default: 0.9
- --min‐p N
- Min‐p sampling.
+ --min-p N
+ Min-p sampling.
- 0.0 = disabled
@@ -165,29 +165,29 @@
Default: 1.0
- --repeat‐last‐n N
+ --repeat-last-n N
Last n tokens to consider for penalize.
- 0 = disabled
- - ‐1 = ctx_size
+ - -1 = ctx_size
Default: 64
- --repeat‐penalty N
+ --repeat-penalty N
Penalize repeat sequence of tokens.
- 1.0 = disabled
Default: 1.1
- --presence‐penalty N
+ --presence-penalty N
Repeat alpha presence penalty.
- 0.0 = disabled
Default: 0.0
- --frequency‐penalty N
+ --frequency-penalty N
Repeat alpha frequency penalty.
- 0.0 = disabled
@@ -204,99 +204,99 @@
Default: 0
- --mirostat‐lr N
+ --mirostat-lr N
Mirostat learning rate, parameter eta.
Default: 0.1
- --mirostat‐ent N
+ --mirostat-ent N
Mirostat target entropy, parameter tau.
Default: 5.0
- -l TOKEN_ID(+/‐)BIAS, --logit‐bias TOKEN_ID(+/‐)BIAS
+ -l TOKEN_ID(+/-)BIAS, --logit-bias TOKEN_ID(+/-)BIAS
Modifies the likelihood of token appearing in the completion,
- i.e. --logit‐bias 15043+1 to increase likelihood of token
- ’ Hello’, or --logit‐bias 15043‐1 to decrease likelihood of to‐
- ken ’ Hello’.
+ i.e. --logit-bias 15043+1 to increase likelihood of token
+ ' Hello', or --logit-bias 15043-1 to decrease likelihood of to‐
+ ken ' Hello'.
- -md FNAME, --model‐draft FNAME
+ -md FNAME, --model-draft FNAME
Draft model for speculative decoding.
- Default: models/7B/ggml‐model‐f16.gguf
+ Default: models/7B/ggml-model-f16.gguf
- --cfg‐negative‐prompt PROMPT
+ --cfg-negative-prompt PROMPT
Negative prompt to use for guidance..
Default: empty
- --cfg‐negative‐prompt‐file FNAME
+ --cfg-negative-prompt-file FNAME
Negative prompt file to use for guidance.
Default: empty
- --cfg‐scale N
+ --cfg-scale N
Strength of guidance.
- 1.0 = disable
Default: 1.0
- --rope‐scaling {none,linear,yarn}
+ --rope-scaling {none,linear,yarn}
RoPE frequency scaling method, defaults to linear unless speci‐
fied by the model
- --rope‐scale N
+ --rope-scale N
RoPE context scaling factor, expands context by a factor of N
- where N is the linear scaling factor used by the fine‐tuned
- model. Some fine‐tuned models have extended the context length
- by scaling RoPE. For example, if the original pre‐trained model
+ where N is the linear scaling factor used by the fine-tuned
+ model. Some fine-tuned models have extended the context length
+ by scaling RoPE. For example, if the original pre-trained model
have a context length (max sequence length) of 4096 (4k) and
- the fine‐tuned model have 32k. That is a scaling factor of 8,
- and should work by setting the above --ctx‐size to 32768 (32k)
- and --rope‐scale to 8.
+ the fine-tuned model have 32k. That is a scaling factor of 8,
+ and should work by setting the above --ctx-size to 32768 (32k)
+ and --rope-scale to 8.
- --rope‐freq‐base N
- RoPE base frequency, used by NTK‐aware scaling.
+ --rope-freq-base N
+ RoPE base frequency, used by NTK-aware scaling.
Default: loaded from model
- --rope‐freq‐scale N
+ --rope-freq-scale N
RoPE frequency scaling factor, expands context by a factor of
1/N
- --yarn‐orig‐ctx N
+ --yarn-orig-ctx N
YaRN: original context size of model.
Default: 0 = model training context size
- --yarn‐ext‐factor N
+ --yarn-ext-factor N
YaRN: extrapolation mix factor.
- 0.0 = full interpolation
Default: 1.0
- --yarn‐attn‐factor N
+ --yarn-attn-factor N
YaRN: scale sqrt(t) or attention magnitude.
Default: 1.0
- --yarn‐beta‐slow N
+ --yarn-beta-slow N
YaRN: high correction dim or alpha.
Default: 1.0
- --yarn‐beta‐fast N
+ --yarn-beta-fast N
YaRN: low correction dim or beta.
Default: 32.0
- --ignore‐eos
+ --ignore-eos
Ignore end of stream token and continue generating (implies
- --logit‐bias 2‐inf)
+ --logit-bias 2-inf)
- --no‐penalize‐nl
+ --no-penalize-nl
Do not penalize newline token.
--temp N
@@ -304,16 +304,16 @@
Default: 0.8
- --logits‐all
+ --logits-all
Return logits for all tokens in the batch.
Default: disabled
--hellaswag
Compute HellaSwag score over random tasks from datafile sup‐
- plied with ‐f
+ plied with -f
- --hellaswag‐tasks N
+ --hellaswag-tasks N
Number of tasks to use when computing the HellaSwag score.
Default: 400
@@ -326,7 +326,7 @@
model resets its internal context.
- 0 = no tokens are kept from initial prompt
- - ‐1 = retain all tokens from initial prompt
+ - -1 = retain all tokens from initial prompt
Default: 0
@@ -338,21 +338,21 @@
--chunks N
Max number of chunks to process.
- - ‐1 = all
+ - -1 = all
- Default: ‐1
+ Default: -1
-ns N, --sequences N
Number of sequences to decode.
Default: 1
- -pa N, --p‐accept N
+ -pa N, --p-accept N
speculative decoding accept probability.
Default: 0.5
- -ps N, --p‐split N
+ -ps N, --p-split N
Speculative decoding split probability.
Default: 0.1
@@ -361,8 +361,8 @@
Force system to keep model in RAM rather than swapping or com‐
pressing.
- --no‐mmap
- Do not memory‐map model (slower load but may reduce pageouts if
+ --no-mmap
+ Do not memory-map model (slower load but may reduce pageouts if
not using mlock).
--numa Attempt optimizations that help on some NUMA systems if run
@@ -377,8 +377,8 @@
Never compile GPU support at runtime.
If the appropriate DSO file already exists under ~/.llamafile/
- then it’ll be linked as‐is without question. If a prebuilt DSO
- is present in the PKZIP content of the executable, then it’ll
+ then it'll be linked as-is without question. If a prebuilt DSO
+ is present in the PKZIP content of the executable, then it'll
be extracted and linked if possible. Otherwise, llamafile will
skip any attempt to compile GPU support and simply fall back to
using CPU inference.
@@ -399,9 +399,9 @@
to run on the host machine is determined automatically
based on the output of the hipInfo command. On Windows,
llamafile release binaries are distributed with a tinyBLAS
- DLL so it’ll work out of the box without requiring the HIP
+ DLL so it'll work out of the box without requiring the HIP
SDK to be installed. However, tinyBLAS is slower than
- rocBLAS for batch and image processing, so it’s recommended
+ rocBLAS for batch and image processing, so it's recommended
that the SDK be installed anyway. If an AMD GPU could not
be used for any reason, then a fatal error will be raised.
@@ -409,8 +409,8 @@
for any reason, a fatal error will be raised. On Windows,
NVIDIA GPU support will use our tinyBLAS library, since it
works on stock Windows installs. However, tinyBLAS goes
- slower for batch and image processing. It’s possible to use
- NVIDIA’s closed‐source cuBLAS library instead. To do that,
+ slower for batch and image processing. It's possible to use
+ NVIDIA's closed-source cuBLAS library instead. To do that,
both MSVC and CUDA need to be installed and the llamafile
command should be run once from the x64 MSVC command prompt
with the --recompile flag passed. The GGML library will
@@ -420,50 +420,50 @@
- DISABLE: Never use GPU and instead use CPU inference. This
setting is implied by -ngl 0.
- -ngl N, --n‐gpu‐layers N
+ -ngl N, --n-gpu-layers N
Number of layers to store in VRAM.
- -ngld N, --n‐gpu‐layers‐draft N
+ -ngld N, --n-gpu-layers-draft N
Number of layers to store in VRAM for the draft model.
- -sm SPLIT_MODE, --split‐mode SPLIT_MODE
+ -sm SPLIT_MODE, --split-mode SPLIT_MODE
How to split the model across multiple GPUs, one of:
- none: use one GPU only
- layer (default): split layers and KV across GPUs
- row: split rows across GPUs
- -ts SPLIT, --tensor‐split SPLIT
+ -ts SPLIT, --tensor-split SPLIT
When using multiple GPUs this option controls how large tensors
- should be split across all GPUs. SPLIT is a comma‐separated
- list of non‐negative values that assigns the proportion of data
+ should be split across all GPUs. SPLIT is a comma-separated
+ list of non-negative values that assigns the proportion of data
that each GPU should get in order. For example, "3,2" will as‐
sign 60% of the data to GPU 0 and 40% to GPU 1. By default the
data is split in proportion to VRAM but this may not be optimal
for performance. Requires cuBLAS. How to split tensors across
- multiple GPUs, comma‐separated list of proportions, e.g. 3,1
+ multiple GPUs, comma-separated list of proportions, e.g. 3,1
- -mg i, --main‐gpu i
+ -mg i, --main-gpu i
The GPU to use for scratch and small tensors.
- -nommq, --no‐mul‐mat‐q
+ -nommq, --no-mul-mat-q
Use cuBLAS instead of custom mul_mat_q CUDA kernels. Not recom‐
mended since this is both slower and uses more VRAM.
- --verbose‐prompt
+ --verbose-prompt
Print prompt before generation.
- --simple‐io
+ --simple-io
Use basic IO for better compatibility in subprocesses and lim‐
ited consoles.
--lora FNAME
- Apply LoRA adapter (implies --no‐mmap)
+ Apply LoRA adapter (implies --no-mmap)
- --lora‐scaled FNAME S
+ --lora-scaled FNAME S
Apply LoRA adapter with user defined scaling S (implies
- --no‐mmap)
+ --no-mmap)
- --lora‐base FNAME
+ --lora-base FNAME
Optional model to use as a base for the layers modified by the
LoRA adapter
@@ -475,67 +475,67 @@
rated by semicolon, for example: top_k;tfs;typi‐
cal;top_p;min_p;temp
- --samplers‐seq
+ --samplers-seq
Simplified sequence for samplers that will be used.
-cml, --chatml
- Run in chatml mode (use with ChatML‐compatible models)
+ Run in chatml mode (use with ChatML-compatible models)
- -dkvc, --dump‐kv‐cache
+ -dkvc, --dump-kv-cache
Verbose print of the KV cache.
- -nkvo, --no‐kv‐offload
+ -nkvo, --no-kv-offload
Disable KV offload.
- -ctk TYPE, --cache‐type‐k TYPE
+ -ctk TYPE, --cache-type-k TYPE
KV cache data type for K.
- -ctv TYPE, --cache‐type‐v TYPE
+ -ctv TYPE, --cache-type-v TYPE
KV cache data type for V.
- -gan N, --grp‐attn‐n N
- Group‐attention factor.
+ -gan N, --grp-attn-n N
+ Group-attention factor.
Default: 1
- -gaw N, --grp‐attn‐w N
- Group‐attention width.
+ -gaw N, --grp-attn-w N
+ Group-attention width.
Default: 512
- -bf FNAME, --binary‐file FNAME
+ -bf FNAME, --binary-file FNAME
Binary file containing multiple choice tasks.
--winogrande
Compute Winogrande score over random tasks from datafile sup‐
plied by the -f flag.
- --winogrande‐tasks N
+ --winogrande-tasks N
Number of tasks to use when computing the Winogrande score.
Default: 0
- --multiple‐choice
+ --multiple-choice
Compute multiple choice score over random tasks from datafile
supplied by the -f flag.
- --multiple‐choice‐tasks N
+ --multiple-choice-tasks N
Number of tasks to use when computing the multiple choice
score.
Default: 0
- --kl‐divergence
- Computes KL‐divergence to logits provided via the
- --kl‐divergence‐base flag.
+ --kl-divergence
+ Computes KL-divergence to logits provided via the
+ --kl-divergence-base flag.
- --save‐all‐logits FNAME, --kl‐divergence‐base FNAME
+ --save-all-logits FNAME, --kl-divergence-base FNAME
Save logits to filename.
- -ptc N, --print‐token‐count N
+ -ptc N, --print-token-count N
Print token count every N tokens.
- Default: ‐1
+ Default: -1
--pooling KIND
Specifies pooling type for embeddings. This may be one of:
@@ -554,42 +554,42 @@
Process prompt escapes sequences (\n, \r, \t, \´, \", \\)
-p STRING, --prompt STRING
- Prompt to start text generation. Your LLM works by auto‐com‐
+ Prompt to start text generation. Your LLM works by auto-com‐
pleting this text. For example:
- llamafile ‐m model.gguf ‐p "four score and"
+ llamafile -m model.gguf -p "four score and"
- Stands a pretty good chance of printing Lincoln’s Gettysburg
+ Stands a pretty good chance of printing Lincoln's Gettysburg
Address. Prompts can take on a structured format too. Depend‐
ing on how your model was trained, it may specify in its docs
an instruction notation. With some models that might be:
- llamafile ‐p "[INST]Summarize this: $(cat file)[/INST]"
+ llamafile -p "[INST]Summarize this: $(cat file)[/INST]"
In most cases, simply colons and newlines will work too:
- llamafile ‐e ‐p "User: What is best in life?\nAssistant:"
+ llamafile -e -p "User: What is best in life?\nAssistant:"
-f FNAME, --file FNAME
Prompt file to start generation.
--grammar GRAMMAR
- BNF‐like grammar to constrain which tokens may be selected when
+ BNF-like grammar to constrain which tokens may be selected when
generating text. For example, the grammar:
root ::= "yes" | "no"
will force the LLM to only output yes or no before exiting.
- This is useful for shell scripts when the --no‐display‐prompt
+ This is useful for shell scripts when the --no-display-prompt
flag is also supplied.
- --grammar‐file FNAME
+ --grammar-file FNAME
File to read grammar from.
--fast Put llamafile into fast math mode. This disables algorithms
that reduce floating point rounding, e.g. Kahan summation, and
certain functions like expf() will be vectorized but handle un‐
- derflows less gracefully. It’s unspecified whether llamafile
+ derflows less gracefully. It's unspecified whether llamafile
runs in fast or precise math mode when neither flag is speci‐
fied.
@@ -597,7 +597,7 @@
Put llamafile into precise math mode. This enables algorithms
that reduce floating point rounding, e.g. Kahan summation, and
certain functions like expf() will always handle subnormals
- correctly. It’s unspecified whether llamafile runs in fast or
+ correctly. It's unspecified whether llamafile runs in fast or
precise math mode when neither flag is specified.
--trap Put llamafile into math trapping mode. When floating point ex‐
@@ -609,42 +609,42 @@
curred. This is useful for troubleshooting when reporting is‐
sues. USing this feature will disable sandboxing. Math trap‐
ping is only possible if your CPU supports it. That is gener‐
- ally the case on AMD64, however it’s less common on ARM64.
+ ally the case on AMD64, however it's less common on ARM64.
- --prompt‐cache FNAME
+ --prompt-cache FNAME
File to cache prompt state for faster startup.
Default: none
- -fa FNAME, --flash‐attn
+ -fa FNAME, --flash-attn
Enable Flash Attention. This is a mathematical shortcut that
can speed up inference for certain models. This feature is
still under active development.
- --prompt‐cache‐all
+ --prompt-cache-all
If specified, saves user input and generations to cache as
well. Not supported with --interactive or other interactive op‐
tions.
- --prompt‐cache‐ro
+ --prompt-cache-ro
If specified, uses the prompt cache but does not update it.
- --random‐prompt
+ --random-prompt
Start with a randomized prompt.
--image IMAGE_FILE
Path to an image file. This should be used with multimodal mod‐
- els. Alternatively, it’s possible to embed an image directly
+ els. Alternatively, it's possible to embed an image directly
into the prompt instead; in which case, it must be base64 en‐
coded into an HTML img tag URL with the image/jpeg MIME type.
See also the --mmproj flag for supplying the vision model.
-i, --interactive
Run the program in interactive mode, allowing users to engage
- in real‐time conversations or provide specific instructions to
+ in real-time conversations or provide specific instructions to
the model.
- --interactive‐first
+ --interactive-first
Run the program in interactive mode and immediately wait for
user input before starting the text generation.
@@ -653,7 +653,7 @@
signed to work with Alpaca models that excel in completing
tasks based on user instructions.
- Technical details: The user’s input is internally prefixed with
+ Technical details: The user's input is internally prefixed with
the reverse prompt (or "### Instruction:" as the default), and
followed by "### Response:" (except if you just press Return
without any input, to keep generating a longer response).
@@ -663,33 +663,33 @@
els, tailoring the text generation process to your specific
needs.
- -r PROMPT, --reverse‐prompt PROMPT
+ -r PROMPT, --reverse-prompt PROMPT
Specify one or multiple reverse prompts to pause text genera‐
tion and switch to interactive mode. For example, -r "User:"
- can be used to jump back into the conversation whenever it’s
- the user’s turn to speak. This helps create a more interactive
+ can be used to jump back into the conversation whenever it's
+ the user's turn to speak. This helps create a more interactive
and conversational experience. However, the reverse prompt
- doesn’t work when it ends with a space. To overcome this limi‐
- tation, you can use the --in‐prefix flag to add a space or any
+ doesn't work when it ends with a space. To overcome this limi‐
+ tation, you can use the --in-prefix flag to add a space or any
other characters after the reverse prompt.
--color
Enable colorized output to differentiate visually distinguish‐
ing between prompts, user input, and generated text.
- --no‐display‐prompt, --silent‐prompt
- Don’t echo the prompt itself to standard output.
+ --no-display-prompt, --silent-prompt
+ Don't echo the prompt itself to standard output.
--keep N
Specifies number of tokens to keep from the initial prompt. The
- default is ‐1 which means all tokens.
+ default is -1 which means all tokens.
- --multiline‐input
+ --multiline-input
Allows you to write or paste multiple lines without ending each
- in ’\’.
+ in '\'.
- --cont‐batching
- Enables continuous batching, a.k.a. dynamic batching. is ‐1
+ --cont-batching
+ Enables continuous batching, a.k.a. dynamic batching. is -1
which means all tokens.
--embedding
@@ -699,8 +699,8 @@
have a separate embeddings array computed for each line of text
in the prompt. In multiline mode, each embedding array will be
printed on its own line to standard output, where individual
- floats are separated by space. If both the --multiline‐input
- and --interactive flags are passed, then a pretty‐printed sum‐
+ floats are separated by space. If both the --multiline-input
+ and --interactive flags are passed, then a pretty-printed sum‐
mary of embeddings along with a cosine similarity matrix will
be printed to the terminal.
@@ -728,12 +728,12 @@
Default: 1
- -cb, --cont‐batching
+ -cb, --cont-batching
Enable continuous batching (a.k.a dynamic batching).
Default: disabled
- -spf FNAME, --system‐prompt‐file FNAME
+ -spf FNAME, --system-prompt-file FNAME
Set a file to load a system prompt (initial prompt of all
slots), this is useful for chat applications.
@@ -749,15 +749,15 @@
--nobrowser
Do not attempt to open a web browser tab at startup.
- -gan N, --grp‐attn‐n N
+ -gan N, --grp-attn-n N
Set the group attention factor to extend context size through
- self‐extend. The default value is 1 which means disabled. This
- flag is used together with --grp‐attn‐w.
+ self-extend. The default value is 1 which means disabled. This
+ flag is used together with --grp-attn-w.
- -gaw N, --grp‐attn‐w N
+ -gaw N, --grp-attn-w N
Set the group attention width to extend context size through
- self‐extend. The default value is 512. This flag is used to‐
- gether with --grp‐attn‐n.
+ self-extend. The default value is 512. This flag is used to‐
+ gether with --grp-attn-n.
LOG OPTIONS
The following log options are available:
@@ -765,110 +765,110 @@
-ld LOGDIR, --logdir LOGDIR
Path under which to save YAML logs (no logging if unset)
- --log‐test
+ --log-test
Run simple logging test
- --log‐disable
+ --log-disable
Disable trace logs
- --log‐enable
+ --log-enable
Enable trace logs
- --log‐file
+ --log-file
Specify a log filename (without extension)
- --log‐new
+ --log-new
Create a separate new log file on start. Each log file will
have unique name: <name>.<ID>.log
- --log‐append
- Don’t truncate the old log file.
+ --log-append
+ Don't truncate the old log file.
EXAMPLES
- Here’s an example of how to run llama.cpp’s built‐in HTTP server. This
- example uses LLaVA v1.5‐7B, a multimodal LLM that works with
- llama.cpp’s recently‐added support for image inputs.
+ Here's an example of how to run llama.cpp's built-in HTTP server. This
+ example uses LLaVA v1.5-7B, a multimodal LLM that works with
+ llama.cpp's recently-added support for image inputs.
llamafile \
- ‐m llava‐v1.5‐7b‐Q8_0.gguf \
- ‐‐mmproj llava‐v1.5‐7b‐mmproj‐Q8_0.gguf \
- ‐‐host 0.0.0.0
+ -m llava-v1.5-7b-Q8_0.gguf \
+ --mmproj llava-v1.5-7b-mmproj-Q8_0.gguf \
+ --host 0.0.0.0
- Here’s an example of how to generate code for a libc function using the
- llama.cpp command line interface, utilizing WizardCoder‐Python‐13B
+ Here's an example of how to generate code for a libc function using the
+ llama.cpp command line interface, utilizing WizardCoder-Python-13B
weights:
llamafile \
- ‐m wizardcoder‐python‐13b‐v1.0.Q8_0.gguf ‐‐temp 0 ‐r ’}\n’ ‐r ’```\n’ \
- ‐e ‐p ’```c\nvoid *memcpy(void *dst, const void *src, size_t size) {\n’
+ -m wizardcoder-python-13b-v1.0.Q8_0.gguf --temp 0 -r '}\n' -r '```\n' \
+ -e -p '```c\nvoid *memcpy(void *dst, const void *src, size_t size) {\n'
- Here’s a similar example that instead utilizes Mistral‐7B‐Instruct
+ Here's a similar example that instead utilizes Mistral-7B-Instruct
weights for prose composition:
llamafile \
- ‐m mistral‐7b‐instruct‐v0.2.Q5_K_M.gguf \
- ‐p ’[INST]Write a story about llamas[/INST]’
+ -m mistral-7b-instruct-v0.2.Q5_K_M.gguf \
+ -p '[INST]Write a story about llamas[/INST]'
- Here’s an example of how llamafile can be used as an interactive chat‐
+ Here's an example of how llamafile can be used as an interactive chat‐
bot that lets you query knowledge contained in training data:
- llamafile ‐m llama‐65b‐Q5_K.gguf ‐p ’
+ llamafile -m llama-65b-Q5_K.gguf -p '
The following is a conversation between a Researcher and their helpful AI
assistant Digital Athena which is a large language model trained on the
sum of human knowledge.
Researcher: Good morning.
Digital Athena: How can I help you today?
- Researcher:’ ‐‐interactive ‐‐color ‐‐batch_size 1024 ‐‐ctx_size 4096 \
- ‐‐keep ‐1 ‐‐temp 0 ‐‐mirostat 2 ‐‐in‐prefix ’ ’ ‐‐interactive‐first \
- ‐‐in‐suffix ’Digital Athena:’ ‐‐reverse‐prompt ’Researcher:’
+ Researcher:' --interactive --color --batch_size 1024 --ctx_size 4096 \
+ --keep -1 --temp 0 --mirostat 2 --in-prefix ' ' --interactive-first \
+ --in-suffix 'Digital Athena:' --reverse-prompt 'Researcher:'
- Here’s an example of how you can use llamafile to summarize HTML URLs:
+ Here's an example of how you can use llamafile to summarize HTML URLs:
(
- echo ’[INST]Summarize the following text:’
- links ‐codepage utf‐8 \
- ‐force‐html \
- ‐width 500 \
- ‐dump https://www.poetryfoundation.org/poems/48860/the‐raven |
- sed ’s/ */ /g’
- echo ’[/INST]’
+ echo '[INST]Summarize the following text:'
+ links -codepage utf-8 \
+ -force-html \
+ -width 500 \
+ -dump https://www.poetryfoundation.org/poems/48860/the-raven |
+ sed 's/ */ /g'
+ echo '[/INST]'
) | llamafile \
- ‐m mistral‐7b‐instruct‐v0.2.Q5_K_M.gguf \
- ‐f /dev/stdin \
- ‐c 0 \
- ‐‐temp 0 \
- ‐n 500 \
- ‐‐no‐display‐prompt 2>/dev/null
-
- Here’s how you can use llamafile to describe a jpg/png/gif/bmp image:
-
- llamafile ‐‐temp 0 \
- ‐‐image lemurs.jpg \
- ‐m llava‐v1.5‐7b‐Q4_K.gguf \
- ‐‐mmproj llava‐v1.5‐7b‐mmproj‐Q4_0.gguf \
- ‐e ‐p ’### User: What do you see?\n### Assistant: ’ \
- ‐‐no‐display‐prompt 2>/dev/null
+ -m mistral-7b-instruct-v0.2.Q5_K_M.gguf \
+ -f /dev/stdin \
+ -c 0 \
+ --temp 0 \
+ -n 500 \
+ --no-display-prompt 2>/dev/null
+
+ Here's how you can use llamafile to describe a jpg/png/gif/bmp image:
+
+ llamafile --temp 0 \
+ --image lemurs.jpg \
+ -m llava-v1.5-7b-Q4_K.gguf \
+ --mmproj llava-v1.5-7b-mmproj-Q4_0.gguf \
+ -e -p '### User: What do you see?\n### Assistant: ' \
+ --no-display-prompt 2>/dev/null
If you wanted to write a script to rename all your image files, you
could use the following command to generate a safe filename:
- llamafile ‐‐temp 0 \
- ‐‐image ~/Pictures/lemurs.jpg \
- ‐m llava‐v1.5‐7b‐Q4_K.gguf \
- ‐‐mmproj llava‐v1.5‐7b‐mmproj‐Q4_0.gguf \
- ‐‐grammar ’root ::= [a‐z]+ (" " [a‐z]+)+’ \
- ‐e ‐p ’### User: The image has...\n### Assistant: ’ \
- ‐‐no‐display‐prompt 2>/dev/null |
- sed ‐e’s/ /_/g’ ‐e’s/$/.jpg/’
+ llamafile --temp 0 \
+ --image ~/Pictures/lemurs.jpg \
+ -m llava-v1.5-7b-Q4_K.gguf \
+ --mmproj llava-v1.5-7b-mmproj-Q4_0.gguf \
+ --grammar 'root ::= [a-z]+ (" " [a-z]+)+' \
+ -e -p '### User: The image has...\n### Assistant: ' \
+ --no-display-prompt 2>/dev/null |
+ sed -e's/ /_/g' -e's/$/.jpg/'
three_baby_lemurs_on_the_back_of_an_adult_lemur.jpg
- Here’s an example of how to make an API request to the OpenAI API com‐
+ Here's an example of how to make an API request to the OpenAI API com‐
patible completions endpoint when your llamafile is running in the
background in --server mode.
- curl ‐s http://localhost:8080/v1/chat/completions \
- ‐H "Content‐Type: application/json" ‐d ’{
- "model": "gpt‐3.5‐turbo",
+ curl -s http://localhost:8080/v1/chat/completions \
+ -H "Content-Type: application/json" -d '{
+ "model": "gpt-3.5-turbo",
"stream": true,
"messages": [
{
@@ -880,7 +880,7 @@
"content": "Compose a poem that explains FORTRAN."
}
]
- }’ | python3 ‐c ’
+ }' | python3 -c '
import json
import sys
json.dump(json.load(sys.stdin), sys.stdout, indent=2)
@@ -888,12 +888,12 @@
PROTIP
The -ngl 35 flag needs to be passed in order to use GPUs made by NVIDIA
- and AMD. It’s not enabled by default since it sometimes needs to be
+ and AMD. It's not enabled by default since it sometimes needs to be
tuned based on the system hardware and model architecture, in order to
achieve optimal performance, and avoid compromising a shared display.
SEE ALSO
- llamafile‐quantize(1), llamafile‐perplexity(1), llava‐quantize(1),
+ llamafile-quantize(1), llamafile-perplexity(1), llava-quantize(1),
zipalign(1), unzip(1)
Mozilla Ocho January 1, 2024 LLAMAFILE(1)
diff --git a/llama.cpp/main/main.cpp b/llama.cpp/main/main.cpp
index cad9c765..8ca23abd 100644
--- a/llama.cpp/main/main.cpp
+++ b/llama.cpp/main/main.cpp
@@ -294,7 +294,10 @@ int main(int argc, char ** argv) {
// load the model and apply lora adapter, if any
LOG("%s: load the model and apply lora adapter, if any\n", __func__);
- std::tie(model, ctx) = llama_init_from_gpt_params(params);
+ llama_init_result llama_init = llama_init_from_gpt_params(params);
+
+ model = llama_init.model;
+ ctx = llama_init.context;
if (sparams.cfg_scale > 1.f) {
struct llama_context_params lparams = llama_context_params_from_gpt_params(params);
ctx_guidance = llama_new_context_with_model(model, lparams);
@@ -351,7 +354,7 @@ int main(int argc, char ** argv) {
}
}
- const bool add_bos = llama_should_add_bos_token(model);
+ const bool add_bos = llama_add_bos_token(model);
if (!llama_model_has_encoder(model)) {
GGML_ASSERT(llama_add_eos_token(model) != 1);
}
diff --git a/llama.cpp/perplexity/perplexity.cpp b/llama.cpp/perplexity/perplexity.cpp
index a2d302fb..fd455921 100644
--- a/llama.cpp/perplexity/perplexity.cpp
+++ b/llama.cpp/perplexity/perplexity.cpp
@@ -342,8 +342,8 @@ static results_perplexity perplexity_v2(llama_context * ctx, const gpt_params &
// Output: `perplexity: 13.5106 [114/114]`
// BOS tokens will be added for each chunk before eval
- const bool add_bos = llama_should_add_bos_token(llama_get_model(ctx));
- GGML_ASSERT(llama_add_eos_token(llama_get_model(ctx)) != 1);
+ const bool add_bos = llama_add_bos_token(llama_get_model(ctx));
+ GGML_ASSERT(!llama_add_eos_token(llama_get_model(ctx)));
fprintf(stderr, "%s: tokenizing the input ..\n", __func__);
@@ -482,8 +482,8 @@ static results_perplexity perplexity(llama_context * ctx, const gpt_params & par
// Output: `perplexity: 13.5106 [114/114]`
// BOS tokens will be added for each chunk before eval
- const bool add_bos = llama_should_add_bos_token(llama_get_model(ctx));
- GGML_ASSERT(llama_add_eos_token(llama_get_model(ctx)) != 1);
+ const bool add_bos = llama_add_bos_token(llama_get_model(ctx));
+ GGML_ASSERT(!llama_add_eos_token(llama_get_model(ctx)));
std::ofstream logits_stream;
if (!params.logits_file.empty()) {
@@ -1735,8 +1735,8 @@ static void kl_divergence(llama_context * ctx, const gpt_params & params) {
const int n_batch = params.n_batch;
const int num_batches = (n_ctx + n_batch - 1)/n_batch;
const int nv = 2*((n_vocab + 1)/2) + 4;
- const bool add_bos = llama_should_add_bos_token(llama_get_model(ctx));
- GGML_ASSERT(llama_add_eos_token(llama_get_model(ctx)) != 1);
+ const bool add_bos = llama_add_bos_token(llama_get_model(ctx));
+ GGML_ASSERT(!llama_add_eos_token(llama_get_model(ctx)));
std::vector<uint16_t> log_probs_uint16(size_t(n_ctx - 1 - n_ctx/2) * nv);
std::vector<float> kld_values(size_t(n_ctx - 1 - n_ctx/2)*n_chunk);
@@ -2034,11 +2034,11 @@ int main(int argc, char ** argv) {
llama_backend_init();
llama_numa_init(params.numa);
- llama_model * model;
- llama_context * ctx;
-
// load the model and apply lora adapter, if any
- std::tie(model, ctx) = llama_init_from_gpt_params(params);
+ llama_init_result llama_init = llama_init_from_gpt_params(params);
+
+ llama_model * model = llama_init.model;
+ llama_context * ctx = llama_init.context;
if (model == NULL) {
fprintf(stderr, "%s: error: unable to load model\n", __func__);
return 1;
diff --git a/llama.cpp/server/server.cpp b/llama.cpp/server/server.cpp
index 85269182..6b690c89 100644
--- a/llama.cpp/server/server.cpp
+++ b/llama.cpp/server/server.cpp
@@ -444,7 +444,9 @@ struct llama_server_context
}
}
- std::tie(model, ctx) = llama_init_from_gpt_params(params);
+ llama_init_result llama_init = llama_init_from_gpt_params(params);
+ model = llama_init.model;
+ ctx = llama_init.context;
if (model == nullptr)
{
LOG_ERROR("unable to load model", {{"model", params.model}});
@@ -2156,8 +2158,6 @@ static void server_print_usage(const char *argv0, const gpt_params &params,
printf(" model path (default: %s)\n", params.model.c_str());
printf(" -a ALIAS, --alias ALIAS\n");
printf(" set an alias for the model, will be added as `model` field in completion response\n");
- printf(" --lora FNAME apply LoRA adapter (implies --no-mmap)\n");
- printf(" --lora-base FNAME optional model to use as a base for the layers modified by the LoRA adapter\n");
printf(" --host ip address to listen (default (default: %s)\n", sparams.hostname.c_str());
printf(" --port PORT port to listen (default (default: %d)\n", sparams.port);
printf(" --path PUBLIC_PATH path from which to serve static files (default %s)\n", sparams.public_path.c_str());
@@ -2499,32 +2499,6 @@ static void server_params_parse(int argc, char **argv, server_params &sparams,
}
params.main_gpu = std::stoi(argv[i]);
}
- else if (arg == "--lora")
- {
- if (++i >= argc)
- {
- invalid_param = true;
- break;
- }
- params.lora_adapter.emplace_back(argv[i], 1.0f);
- params.use_mmap = false;
- }
- else if (arg == "--lora-scaled")
- {
- if (++i >= argc)
- {
- invalid_param = true;
- break;
- }
- const char * lora_adapter = argv[i];
- if (++i >= argc)
- {
- invalid_param = true;
- break;
- }
- params.lora_adapter.emplace_back(lora_adapter, std::stof(argv[i]));
- params.use_mmap = false;
- }
else if (arg == "-v" || arg == "--verbose")
{
#if SERVER_VERBOSE != 1
diff --git a/llamafile/server/BUILD.mk b/llamafile/server/BUILD.mk
index 37276db3..66019571 100644
--- a/llamafile/server/BUILD.mk
+++ b/llamafile/server/BUILD.mk
@@ -16,6 +16,7 @@ o/$(MODE)/llamafile/server/server.a: \
o/$(MODE)/llamafile/server/main: \
o/$(MODE)/llamafile/server/main.o \
+ o/$(MODE)/llamafile/server/main.1.asc.zip.o \
o/$(MODE)/llamafile/server/server.a \
o/$(MODE)/llama.cpp/llama.cpp.a \
o/$(MODE)/llama.cpp/llava/llava.a \
diff --git a/llamafile/server/main.1 b/llamafile/server/main.1
new file mode 100644
index 00000000..f711a3a0
--- /dev/null
+++ b/llamafile/server/main.1
@@ -0,0 +1,121 @@
+.Dd August 17, 2024
+.Dt LLAMAFILER 1
+.Os Mozilla Ocho
+.Sh NAME
+.Nm llamafiler
+.Nd fast reliable embedding server
+.Sh SYNOPSIS
+.Nm
+.Fl m Ar model.gguf
+.Op flags...
+.Sh DESCRIPTION
+.Nm
+is a brand new HTTP server for Large Language Models (LLMs). To date,
+its development has been focused on doing fewer things really well, and
+right now that's serving embeddings. It offers you 3.4x the performance,
+stronger security, client request prioritization, request preemption, as
+well as request isolation that helps ensure software bugs won't cause
+the whole server to crash.
+.Sh OPTIONS
+The following options are available:
+.Bl -tag -width indent
+.It Fl Fl version
+Print version and exit.
+.It Fl h , Fl Fl help
+Show help message and exit.
+.It Fl m Ar FNAME , Fl Fl model Ar FNAME
+Path of GGUF model weights. Each server process is currently limited to
+serving only one model. If you need to host multiple models, then it's
+recommended that you run multiple instances of llamafiler behind a
+reverse proxy such as NGINX or Redbean.
+.It Fl l Ar HOSTPORT , Fl Fl listen Ar HOSTPORT
+Specifies the local [HOST:]PORT on which the HTTP server should listen.
+By default this is 0.0.0.0:8080 which means llamafiler will bind to port
+8080 on every locally available IPv4 network interface. This option may
+currently only be specified once.
+.It Fl w Ar N , Fl Fl workers Ar N
+Number of HTTP client handling threads.
+.It Fl Fl trust Ar CIDR
+Adds a network to the trusted network list. This argument is specified
+in the form IPV4/MASKBITS, e.g. 192.168.0.0/24. By default, all clients
+are untrusted, which means they're subject to token bucket throttling,
+and additional security precautions that may cause request handling to
+go slightly slower. Therefore this flag is important to use if you want
+to accurately benchmark llamafiler, since the server will otherwise see
+the benchmark as a DDOS and deprioritize its traffic accordingly.
+.It Fl Fl ip-header Ar STR
+If this flag is passed a value, e.g. X-Forwarded-For, then any trusted
+may send this header to your llamafile server to let it know what the
+true effective client IPv4 address actually is. After this happens the
+default security restrictions, e.g. token bucket, will be measured and
+applied against that IPv4 address and its adjacent networks.
+.It Fl Fl token-rate Ar N
+Specifies how many times per second a token is dropped in each bucket.
+This setting is used to define a limitation on how many TCP connects and
+HTTP messages each chunk of the IPv4 address space is permitted to send
+to llamafiler over a sustained period of time. The default token rate is
+1, which means that, on a long enough timeline, a class-C network will
+be deprioritized if it sends more than one request per second. No real
+penalty actually applies though until the server runs out of resources,
+e.g. HTTP request workers.
+.It Fl Fl token-burst Ar N
+Specifies how many HTTP requests and TCP connects a given slice of the
+IPv4 address space is permitted to send within a short period of time,
+before token bucket restrictions kick in, and cause the client to be
+deprioritized. By default, this value is set to 100. It may be tuned to
+any value between 1 and 127 inclusive.
+.It Fl Fl token-cidr Ar N
+Specifies IPv4 address space granularity of token bucket algorithm, in
+network bits. By default, this value is set to 24 which means individual
+IPv4 addresses are viewed as being representative members of a class-C
+network, or in other words, each group of 256 IPv4 addresses is lumped
+together. If one IP in the group does something bad, then bad things
+happen to all the other IPv4 addresses in that granule. This number may
+be set to any integer between 3 and 32 inclusive. Specifying a higher
+number will trade away system memory to increase network specificity.
+For example, using 32 means that 4 billion individual token buckets will
+be created. By default, a background thread drops one token in each
+bucket every second, so that could potentially be a lot of busy work. A
+value of three means that everyone on the Internet who talks to your
+server will have to fight over only eight token buckets in total.
+.It Fl Fl unsecure
+Disables sandboxing. By default, llamafiler puts itself in a SECCOMP BPF
+sandbox, so that even if your server gets hacked in the worst possible
+way (some kind of C++ memory bug) then there's very little damage an
+attacker will be able to do. This works by restricting system calls
+using Cosmopolitan Libc's implementation of pledge() which is currently
+only supported on Linux (other OSes will simply be unsecured by
+default). The pledge security policy that's used by default is "stdio
+anet" which means that only relatively harmless system calls like
+read(), write(), and accept() are allowed once the server has finished
+initializing. It's not possible for remotely executed code to do things
+like launch subprocesses, read or write to the filesystem, or initiate a
+new connection to a server.
+.It Fl k Ar N , Fl Fl keepalive Ar N
+Specifies the TCP keepalive interval in seconds. This value is passed
+along to both TCP_KEEPIDLE and TCP_KEEPINTVL if they're supported by the
+host operating system. If this value is greater than 0, then the the
+SO_KEEPALIVE and TCP_NODELAY options are enabled on network sockets, if
+supported by the host operating system. The default keepalive is 5.
+.It Fl Fl http-obuf-size Ar N
+Size of HTTP output buffer size, in bytes. Default is 1048576.
+.It Fl Fl http-ibuf-size Ar N
+Size of HTTP input buffer size, in bytes. Default is 1048576.
+.Sh EXAMPLE
+Here's an example of how you might start this server:
+.Pp
+.Dl "llamafiler -m all-MiniLM-L6-v2.F32.gguf"
+.Pp
+Here's how to send a tokenization request:
+.Pp
+.Dl "curl -v http://127.0.0.1:8080/tokenize?prompt=hello+world"
+.Pp
+Here's how to send a embedding request:
+.Pp
+.Dl "curl -v http://127.0.0.1:8080/embedding?content=hello+world"
+.Sh DOCUMENTATION
+Read our Markdown documentation for additional help and tutorials. See
+llamafile/server/doc/index.md in the source repository on GitHub.
+.Sh SEE ALSO
+.Xr llamafile 1 ,
+.Xr whisperfile 1
diff --git a/llamafile/server/main.1.asc b/llamafile/server/main.1.asc
new file mode 100644
index 00000000..a9d44167
--- /dev/null
+++ b/llamafile/server/main.1.asc
@@ -0,0 +1,144 @@
+LLAMAFILER(1) General Commands Manual LLAMAFILER(1)
+
+NAME
+ llamafiler — fast reliable embedding server
+
+SYNOPSIS
+ llamafiler -m model.gguf [flags...]
+
+DESCRIPTION
+ llamafiler is a brand new HTTP server for Large Language Models (LLMs).
+ To date, its development has been focused on doing fewer things really
+ well, and right now that's serving embeddings. It offers you 3.4x the
+ performance, stronger security, client request prioritization, request
+ preemption, as well as request isolation that helps ensure software
+ bugs won't cause the whole server to crash.
+
+OPTIONS
+ The following options are available:
+
+ --version
+ Print version and exit.
+
+ -h, --help
+ Show help message and exit.
+
+ -m FNAME, --model FNAME
+ Path of GGUF model weights. Each server process is currently
+ limited to serving only one model. If you need to host multiple
+ models, then it's recommended that you run multiple instances
+ of llamafiler behind a reverse proxy such as NGINX or Redbean.
+
+ -l HOSTPORT, --listen HOSTPORT
+ Specifies the local [HOST:]PORT on which the HTTP server should
+ listen. By default this is 0.0.0.0:8080 which means llamafiler
+ will bind to port 8080 on every locally available IPv4 network
+ interface. This option may currently only be specified once.
+
+ -w N, --workers N
+ Number of HTTP client handling threads.
+
+ --trust CIDR
+ Adds a network to the trusted network list. This argument is
+ specified in the form IPV4/MASKBITS, e.g. 192.168.0.0/24. By
+ default, all clients are untrusted, which means they're subject
+ to token bucket throttling, and additional security precautions
+ that may cause request handling to go slightly slower. There‐
+ fore this flag is important to use if you want to accurately
+ benchmark llamafiler, since the server will otherwise see the
+ benchmark as a DDOS and deprioritize its traffic accordingly.
+
+ --ip-header STR
+ If this flag is passed a value, e.g. X-Forwarded-For, then any
+ trusted may send this header to your llamafile server to let it
+ know what the true effective client IPv4 address actually is.
+ After this happens the default security restrictions, e.g. to‐
+ ken bucket, will be measured and applied against that IPv4 ad‐
+ dress and its adjacent networks.
+
+ --token-rate N
+ Specifies how many times per second a token is dropped in each
+ bucket. This setting is used to define a limitation on how
+ many TCP connects and HTTP messages each chunk of the IPv4 ad‐
+ dress space is permitted to send to llamafiler over a sustained
+ period of time. The default token rate is 1, which means that,
+ on a long enough timeline, a class-C network will be depriori‐
+ tized if it sends more than one request per second. No real
+ penalty actually applies though until the server runs out of
+ resources, e.g. HTTP request workers.
+
+ --token-burst N
+ Specifies how many HTTP requests and TCP connects a given slice
+ of the IPv4 address space is permitted to send within a short
+ period of time, before token bucket restrictions kick in, and
+ cause the client to be deprioritized. By default, this value is
+ set to 100. It may be tuned to any value between 1 and 127 in‐
+ clusive.
+
+ --token-cidr N
+ Specifies IPv4 address space granularity of token bucket algo‐
+ rithm, in network bits. By default, this value is set to 24
+ which means individual IPv4 addresses are viewed as being rep‐
+ resentative members of a class-C network, or in other words,
+ each group of 256 IPv4 addresses is lumped together. If one IP
+ in the group does something bad, then bad things happen to all
+ the other IPv4 addresses in that granule. This number may be
+ set to any integer between 3 and 32 inclusive. Specifying a
+ higher number will trade away system memory to increase network
+ specificity. For example, using 32 means that 4 billion indi‐
+ vidual token buckets will be created. By default, a background
+ thread drops one token in each bucket every second, so that
+ could potentially be a lot of busy work. A value of three means
+ that everyone on the Internet who talks to your server will
+ have to fight over only eight token buckets in total.
+
+ --unsecure
+ Disables sandboxing. By default, llamafiler puts itself in a
+ SECCOMP BPF sandbox, so that even if your server gets hacked in
+ the worst possible way (some kind of C++ memory bug) then
+ there's very little damage an attacker will be able to do. This
+ works by restricting system calls using Cosmopolitan Libc's im‐
+ plementation of pledge() which is currently only supported on
+ Linux (other OSes will simply be unsecured by default). The
+ pledge security policy that's used by default is "stdio anet"
+ which means that only relatively harmless system calls like
+ read(), write(), and accept() are allowed once the server has
+ finished initializing. It's not possible for remotely executed
+ code to do things like launch subprocesses, read or write to
+ the filesystem, or initiate a new connection to a server.
+
+ -k N, --keepalive N
+ Specifies the TCP keepalive interval in seconds. This value is
+ passed along to both TCP_KEEPIDLE and TCP_KEEPINTVL if they're
+ supported by the host operating system. If this value is
+ greater than 0, then the the SO_KEEPALIVE and TCP_NODELAY op‐
+ tions are enabled on network sockets, if supported by the host
+ operating system. The default keepalive is 5.
+
+ --http-obuf-size N
+ Size of HTTP output buffer size, in bytes. Default is 1048576.
+
+ --http-ibuf-size N
+ Size of HTTP input buffer size, in bytes. Default is 1048576.
+
+EXAMPLE
+ Here's an example of how you might start this server:
+
+ llamafiler -m all-MiniLM-L6-v2.F32.gguf
+
+ Here's how to send a tokenization request:
+
+ curl -v http://127.0.0.1:8080/tokenize?prompt=hello+world
+
+ Here's how to send a embedding request:
+
+ curl -v http://127.0.0.1:8080/embedding?content=hello+world
+
+DOCUMENTATION
+ Read our Markdown documentation for additional help and tutorials. See
+ llamafile/server/doc/index.md in the source repository on GitHub.
+
+SEE ALSO
+ llamafile(1), whisperfile(1)
+
+Mozilla Ocho August 17, 2024 LLAMAFILER(1)
diff --git a/llamafile/server/main.cpp b/llamafile/server/main.cpp
index 04f60443..e404ef54 100644
--- a/llamafile/server/main.cpp
+++ b/llamafile/server/main.cpp
@@ -36,20 +36,35 @@ llama_model* g_model;
int
main(int argc, char* argv[])
{
- ShowCrashReports();
+ mallopt(M_GRANULARITY, 2 * 1024 * 1024);
+ mallopt(M_MMAP_THRESHOLD, 16 * 1024 * 1024);
+ mallopt(M_TRIM_THRESHOLD, 128 * 1024 * 1024);
+ FLAG_gpu = LLAMAFILE_GPU_DISABLE;
llamafile_check_cpu();
+ ShowCrashReports();
+
if (llamafile_has(argv, "--version")) {
puts("llamafiler v" LLAMAFILE_VERSION_STRING);
exit(0);
}
- mallopt(M_GRANULARITY, 2 * 1024 * 1024);
- mallopt(M_MMAP_THRESHOLD, 16 * 1024 * 1024);
- mallopt(M_TRIM_THRESHOLD, 128 * 1024 * 1024);
+ if (llamafile_has(argv, "-h") || llamafile_has(argv, "-help") ||
+ llamafile_has(argv, "--help")) {
+ llamafile_help("/zip/llamafile/server/main.1.asc");
+ __builtin_unreachable();
+ }
// get config
LoadZipArgs(&argc, &argv);
llamafile_get_flags(argc, argv);
+
+ // bounce users wanting gpu support (not ready yet)
+ if (FLAG_n_gpu_layers) {
+ fprintf(stderr, "error: llamafiler doesn't support gpu yet\n");
+ return 1;
+ }
+
+ // initialize subsystems
time_init();
tokenbucket_init();
diff --git a/whisper.cpp/BUILD.mk b/whisper.cpp/BUILD.mk
index 218e9ce7..eafa9eb5 100644
--- a/whisper.cpp/BUILD.mk
+++ b/whisper.cpp/BUILD.mk
@@ -29,19 +29,14 @@ $(WHISPER_CPP_OBJS): private \
-Wno-alloc-size-larger-than \
-Wno-deprecated-declarations
-o/$(MODE)/whisper.cpp/server: \
- o/$(MODE)/whisper.cpp/server.o \
- o/$(MODE)/whisper.cpp/whisper.cpp.a \
- o/$(MODE)/llama.cpp/llama.cpp.a
-
o/$(MODE)/whisper.cpp/main: \
o/$(MODE)/whisper.cpp/main.o \
+ o/$(MODE)/whisper.cpp/main.1.asc.zip.o \
o/$(MODE)/whisper.cpp/whisper.cpp.a \
- o/$(MODE)/llama.cpp/llama.cpp.a
+ o/$(MODE)/llama.cpp/llama.cpp.a \
$(WHISPER_CPP_OBJS): whisper.cpp/BUILD.mk
.PHONY: o/$(MODE)/whisper.cpp
o/$(MODE)/whisper.cpp: \
- o/$(MODE)/whisper.cpp/server \
o/$(MODE)/whisper.cpp/main
diff --git a/whisper.cpp/README.md b/whisper.cpp/README.md
index fe483985..1daca316 100644
--- a/whisper.cpp/README.md
+++ b/whisper.cpp/README.md
@@ -1,43 +1,8 @@
# whisperfile
-whisperfile lets you turn .wav files into .txt files,
-using a single file.
+Whisperfile is a high-performance implementation of [OpenAI's
+Whisper](https://github.com/openai/whisper) model that's based off the
+[whisper.cpp](https://github.com/ggerganov/whisper.cpp) software written
+by Georgi Gerganov, et al.
-## Getting Started
-
-You can use the tiny model. Here's JFK talking.
-
-```
-wget -O whisper-tiny.en-q5_1.bin https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-tiny.en-q5_1.bin
-make -j o//whisper.cpp
-o//whisper.cpp/main -m whisper-tiny.en-q5_1.bin -f whisper.cpp/jfk.wav --no-prints
-```
-
-Here's how you turn an Edgar Allen Poe MP3 into a WAV file.
-
-```
-sudo apt install sox libsox-fmt-all
-wget https://archive.org/download/raven/raven_poe_64kb.mp3
-sox raven_poe_64kb.mp3 -r 16k raven_poe_64kb.wav
-```
-
-The tiny model may get some words wrong. For example, it might think
-"quoth" is "quof". You can solve that using the medium model, which
-enables whisperfile to decode The Raven perfectly. However it's slower.
-
-```
-wget https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-medium.en.bin
-o//whisper.cpp/main -m ggml-medium.en.bin -f raven_poe_64kb.wav --no-prints
-```
-
-Lastly, there's the large model, which is the best, but also slowest.
-
-```
-wget -O whisper-large-v3.bin https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-large-v3.bin
-o//whisper.cpp/main -m whisper-large-v3.bin -f raven_poe_64kb.wav --no-prints
-```
-
-### GPU Mode
-
-Pass the `--gpu auto` flag to use GPU mode. This can be particularly
-helpful in speeding up the medium and large models.
+See the [Whisperfile Documentation](doc/index.md) for more details.
diff --git a/whisper.cpp/common.cpp b/whisper.cpp/common.cpp
index c210707e..67fd25cf 100644
--- a/whisper.cpp/common.cpp
+++ b/whisper.cpp/common.cpp
@@ -224,7 +224,7 @@ bool sam_params_parse(int argc, char ** argv, sam_params & params) {
exit(0);
} else {
fprintf(stderr, "error: unknown argument: %s\n", arg.c_str());
- sam_print_usage(argc, argv, params);
+ // sam_print_usage(argc, argv, params); // [jart]
exit(0);
}
}
diff --git a/whisper.cpp/doc/getting-started.md b/whisper.cpp/doc/getting-started.md
new file mode 100644
index 00000000..9405f599
--- /dev/null
+++ b/whisper.cpp/doc/getting-started.md
@@ -0,0 +1,83 @@
+## Getting Started with Whisperfile
+
+This tutorial will explain how to turn speech from audio files into
+plain text, using the whisperfile software and OpenAI's whisper model.
+
+### (1) Download Model
+
+First, you need to obtain the model weights. The tiny quantized weights
+are the smallest and fastest to get started with. They work reasonably
+well. The transcribed output is readable, even though it may misspell or
+misunderstand some words.
+
+```
+wget -O whisper-tiny.en-q5_1.bin https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-tiny.en-q5_1.bin
+```
+
+### (2) Build Software
+
+Now build the whisperfile software from source. You need to have modern
+GNU Make installed. On Debian you can say `sudo apt install make`. On
+other platforms like Windows and MacOS (where Apple distributes a very
+old version of make) you can download a portable pre-built executable
+from <https://cosmo.zip/pub/cosmos/bin/>.
+
+```
+make -j o//whisper.cpp/main
+```
+
+### (3) Run Program
+
+Now that the software is compiled, here's an example of how to turn
+speech into text. Included in this repository is a .wav file holding a
+short clip of John F. Kennedy speaking. You can transcribe it using:
+
+```
+o//whisper.cpp/main -m whisper-tiny.en-q5_1.bin -f whisper.cpp/jfk.wav --no-prints
+```
+
+The `--no-prints` is optional. It's helpful in avoiding a lot of verbose
+logging and statistical information from being printed, which is useful
+when writing shell scripts.
+
+## Converting MP3 to WAV
+
+Whisperfile only currently understands .wav files. So if you have files
+in a different audio format, you need to convert them to wav beforehand.
+One great tool for doing that is sox (your swiss army knife for audio).
+It's easily installed and used on Debian systems as follows:
+
+```
+sudo apt install sox libsox-fmt-all
+wget https://archive.org/download/raven/raven_poe_64kb.mp3
+sox raven_poe_64kb.mp3 -r 16k raven_poe_64kb.wav
+```
+
+## Higher Quality Models
+
+The tiny model may get some words wrong. For example, it might think
+"quoth" is "quof". You can solve that using the medium model, which
+enables whisperfile to decode The Raven perfectly. However it's slower.
+
+```
+wget https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-medium.en.bin
+o//whisper.cpp/main -m ggml-medium.en.bin -f raven_poe_64kb.wav --no-prints
+```
+
+Lastly, there's the large model, which is the best, but also slowest.
+
+```
+wget -O whisper-large-v3.bin https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-large-v3.bin
+o//whisper.cpp/main -m whisper-large-v3.bin -f raven_poe_64kb.wav --no-prints
+```
+
+## Installation
+
+If you like whisperfile, you can also install it as a systemwide command
+named `whisperfile` along with other useful tools and utilities provided
+by the llamafile project.
+
+```
+make -j
+sudo make install
+```
diff --git a/whisper.cpp/doc/gpu.md b/whisper.cpp/doc/gpu.md
new file mode 100644
index 00000000..998fbf53
--- /dev/null
+++ b/whisper.cpp/doc/gpu.md
@@ -0,0 +1,4 @@
+# Using Whisperfile with GPUs
+
+Pass the `--gpu auto` flag to use GPU mode. This can be particularly
+helpful in speeding up the medium and large models.
diff --git a/whisper.cpp/doc/index.md b/whisper.cpp/doc/index.md
new file mode 100644
index 00000000..17cb7e14
--- /dev/null
+++ b/whisper.cpp/doc/index.md
@@ -0,0 +1,13 @@
+# Whisperfile Documentation
+
+Whisperfile is a high-performance implementation of [OpenAI's
+Whisper](https://github.com/openai/whisper) model that's based off the
+[whisper.cpp](https://github.com/ggerganov/whisper.cpp) software written
+by Georgi Gerganov, et al.
+
+## Index
+
+- [Getting Started](getting-started.md)
+- [Packaging](packaging.md)
+- [Using GPUs](gpu.md)
+- [Speech Translation](translate.md)
diff --git a/whisper.cpp/doc/packaging.md b/whisper.cpp/doc/packaging.md
new file mode 100644
index 00000000..041fda24
--- /dev/null
+++ b/whisper.cpp/doc/packaging.md
@@ -0,0 +1,94 @@
+# How to make a Whisperfile
+
+Whisperfile is designed to be a single-file solution for speech-to-text.
+This tutorial will explain how you can merge the whisperfile executable
+and OpenAI's model weights into a unified executable.
+
+We'll be using Cosmopolitan Libc's "ZipOS" read-only filesystem and its
+`.args` file convention for specifying default arguments.
+
+## Prerequisites
+
+To get started you first need the `zipalign` command. This is our
+recommended solution for adding artifacts to a .zip file (note: the
+whisperfile executable is both a zip file and executable). If `zipalign`
+isn't already installed on your system, then you can build it from
+source as follows:
+
+```
+make -j o//llamafile/zipalign
+```
+
+Now you can either obtain a prebuilt `whisperfile` executable from our
+GitHub releases page, or build one from source yourself.
+
+```
+make -j o//whisper.cpp/main
+cp o//whisper.cpp/main whisperfile
+```
+
+Next, choose your favorite weights. For the purposes of this tutorial,
+we'll be using the tiny q5\_1 quantized whisper weights.
+
+```
+wget -O whisper-tiny.en-q5_1.bin https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-tiny.en-q5_1.bin
+```
+
+## Instructions
+
+
+First, embed your weights inside your whisperfile. We're going to pass
+the `-0` flag to disable PKZIP DEFLATE compression since it isn't
+profitable on weights files.
+
+```
+zipalign -0 whisperfile whisper-tiny.en-q5_1.bin
+```
+
+Your weights are now embedded. You can list the embedded files using
+`unzip -vl whisperfile` to confirm that it's there. Once the asset is
+inside, Cosmopolitan Libc will make it available under the synthetic
+`/zip/...` root directory, via the standard I/O APIs. So if `unzip -vl`
+lists the asset as being named `whisper-tiny.en-q5_1.bin` then the
+executable may access it at the path `/zip/whisper-tiny.en-q5_1.bin`.
+
+```
+./whisperfile -m /zip/whisper-tiny.en-q5_1.bin -f whisper.cpp/jfk.wav
+```
+
+It's now safe to delete the original weights file.
+
+```
+rm -f whisper-tiny.en-q5_1.bin
+```
+
+Next, to avoid needing to say `-m whisper-tiny.en-q5_1.bin` each time
+you run your whisperfile, you can embed an additional file with the name
+`.args` which specifies your default program arguments. You can do that
+by first creating a file named `.args` in the current directory with the
+following contents:
+
+```
+-m
+/zip/whisper-tiny.en-q5_1.bin
+...
+```
+
+As we can see, it's a simple file format that accepts one argument per
+line. This way arguments can have spaces if needed, in which case quotes
+should not be used (this isn't a shell script). The format also has one
+special argument which is `...`. This should go at the end of the file.
+It's where any additional CLI-specified args will be filled-in later on.
+
+Now embed the `.args` file inside your whisperfile using `zipalign`.
+
+```
+zipalign whisperfile .args
+rm -f .args
+```
+
+And congratulations, you now have a self-contained whisperfile!
+
+```
+./whisperfile -f whisper.cpp/jfk.wav
+```
diff --git a/whisper.cpp/doc/translate.md b/whisper.cpp/doc/translate.md
new file mode 100644
index 00000000..4d0e546f
--- /dev/null
+++ b/whisper.cpp/doc/translate.md
@@ -0,0 +1,21 @@
+# Speech Translation with Whisperfile
+
+Whisperfile is not only able to transcribe speech to text. It's able to
+translate that speech into English too, at the same time. All you have
+to do is pass the `-tr` or `--translate` flag.
+
+### Choosing a Model
+
+In order for translation to work, you need to be using a multilingual
+model. On <https://huggingface.co/ggerganov/whisper.cpp/> the files that
+have `.en` in the name are English-only; you can't use those for
+translation. One model that does work well in translation mode is
+[`ggml-medium-q5_0.bin`](https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-medium-q5_0.bin?download=true).
+
+### Language Override
+
+By default, the source language will be auto-detected. This works great
+except for recordings with multiple languages. For example, if you have
+a recording with a little bit of English at the beginning, but the rest
+is in French, then you may want to pass the `-l fr` flag, to explicitly
+specify the source language as French.
diff --git a/whisper.cpp/dr_wav.h b/whisper.cpp/dr_wav.h
index fd3e95b3..61f813b1 100644
--- a/whisper.cpp/dr_wav.h
+++ b/whisper.cpp/dr_wav.h
@@ -2553,404 +2553,402 @@ DRWAV_API drwav_uint64 drwav_target_write_size_bytes(const drwav_data_format* pF
#include <errno.h>
static drwav_result drwav_result_from_errno(int e)
{
- switch (e)
- {
- case 0: return DRWAV_SUCCESS;
+ // [jart] errno toil
+ if (e == 0) return DRWAV_SUCCESS;
#ifdef EPERM
- case EPERM: return DRWAV_INVALID_OPERATION;
+ if (e == EPERM) return DRWAV_INVALID_OPERATION;
#endif
#ifdef ENOENT
- case ENOENT: return DRWAV_DOES_NOT_EXIST;
+ if (e == ENOENT) return DRWAV_DOES_NOT_EXIST;
#endif
#ifdef ESRCH
- case ESRCH: return DRWAV_DOES_NOT_EXIST;
+ if (e == ESRCH) return DRWAV_DOES_NOT_EXIST;
#endif
#ifdef EINTR
- case EINTR: return DRWAV_INTERRUPT;
+ if (e == EINTR) return DRWAV_INTERRUPT;
#endif
#ifdef EIO
- case EIO: return DRWAV_IO_ERROR;
+ if (e == EIO) return DRWAV_IO_ERROR;
#endif
#ifdef ENXIO
- case ENXIO: return DRWAV_DOES_NOT_EXIST;
+ if (e == ENXIO) return DRWAV_DOES_NOT_EXIST;
#endif
#ifdef E2BIG
- case E2BIG: return DRWAV_INVALID_ARGS;
+ if (e == E2BIG) return DRWAV_INVALID_ARGS;
#endif
#ifdef ENOEXEC
- case ENOEXEC: return DRWAV_INVALID_FILE;
+ if (e == ENOEXEC) return DRWAV_INVALID_FILE;
#endif
#ifdef EBADF
- case EBADF: return DRWAV_INVALID_FILE;
+ if (e == EBADF) return DRWAV_INVALID_FILE;
#endif
#ifdef ECHILD
- case ECHILD: return DRWAV_ERROR;
+ if (e == ECHILD) return DRWAV_ERROR;
#endif
#ifdef EAGAIN
- case EAGAIN: return DRWAV_UNAVAILABLE;
+ if (e == EAGAIN) return DRWAV_UNAVAILABLE;
#endif
#ifdef ENOMEM
- case ENOMEM: return DRWAV_OUT_OF_MEMORY;
+ if (e == ENOMEM) return DRWAV_OUT_OF_MEMORY;
#endif
#ifdef EACCES
- case EACCES: return DRWAV_ACCESS_DENIED;
+ if (e == EACCES) return DRWAV_ACCESS_DENIED;
#endif
#ifdef EFAULT
- case EFAULT: return DRWAV_BAD_ADDRESS;
+ if (e == EFAULT) return DRWAV_BAD_ADDRESS;
#endif
#ifdef ENOTBLK
- case ENOTBLK: return DRWAV_ERROR;
+ if (e == ENOTBLK) return DRWAV_ERROR;
#endif
#ifdef EBUSY
- case EBUSY: return DRWAV_BUSY;
+ if (e == EBUSY) return DRWAV_BUSY;
#endif
#ifdef EEXIST
- case EEXIST: return DRWAV_ALREADY_EXISTS;
+ if (e == EEXIST) return DRWAV_ALREADY_EXISTS;
#endif
#ifdef EXDEV
- case EXDEV: return DRWAV_ERROR;
+ if (e == EXDEV) return DRWAV_ERROR;
#endif
#ifdef ENODEV
- case ENODEV: return DRWAV_DOES_NOT_EXIST;
+ if (e == ENODEV) return DRWAV_DOES_NOT_EXIST;
#endif
#ifdef ENOTDIR
- case ENOTDIR: return DRWAV_NOT_DIRECTORY;
+ if (e == ENOTDIR) return DRWAV_NOT_DIRECTORY;
#endif
#ifdef EISDIR
- case EISDIR: return DRWAV_IS_DIRECTORY;
+ if (e == EISDIR) return DRWAV_IS_DIRECTORY;
#endif
#ifdef EINVAL
- case EINVAL: return DRWAV_INVALID_ARGS;
+ if (e == EINVAL) return DRWAV_INVALID_ARGS;
#endif
#ifdef ENFILE
- case ENFILE: return DRWAV_TOO_MANY_OPEN_FILES;
+ if (e == ENFILE) return DRWAV_TOO_MANY_OPEN_FILES;
#endif
#ifdef EMFILE
- case EMFILE: return DRWAV_TOO_MANY_OPEN_FILES;
+ if (e == EMFILE) return DRWAV_TOO_MANY_OPEN_FILES;
#endif
#ifdef ENOTTY
- case ENOTTY: return DRWAV_INVALID_OPERATION;
+ if (e == ENOTTY) return DRWAV_INVALID_OPERATION;
#endif
#ifdef ETXTBSY
- case ETXTBSY: return DRWAV_BUSY;
+ if (e == ETXTBSY) return DRWAV_BUSY;
#endif
#ifdef EFBIG
- case EFBIG: return DRWAV_TOO_BIG;
+ if (e == EFBIG) return DRWAV_TOO_BIG;
#endif
#ifdef ENOSPC
- case ENOSPC: return DRWAV_NO_SPACE;
+ if (e == ENOSPC) return DRWAV_NO_SPACE;
#endif
#ifdef ESPIPE
- case ESPIPE: return DRWAV_BAD_SEEK;
+ if (e == ESPIPE) return DRWAV_BAD_SEEK;
#endif
#ifdef EROFS
- case EROFS: return DRWAV_ACCESS_DENIED;
+ if (e == EROFS) return DRWAV_ACCESS_DENIED;
#endif
#ifdef EMLINK
- case EMLINK: return DRWAV_TOO_MANY_LINKS;
+ if (e == EMLINK) return DRWAV_TOO_MANY_LINKS;
#endif
#ifdef EPIPE
- case EPIPE: return DRWAV_BAD_PIPE;
+ if (e == EPIPE) return DRWAV_BAD_PIPE;
#endif
#ifdef EDOM
- case EDOM: return DRWAV_OUT_OF_RANGE;
+ if (e == EDOM) return DRWAV_OUT_OF_RANGE;
#endif
#ifdef ERANGE
- case ERANGE: return DRWAV_OUT_OF_RANGE;
+ if (e == ERANGE) return DRWAV_OUT_OF_RANGE;
#endif
#ifdef EDEADLK
- case EDEADLK: return DRWAV_DEADLOCK;
+ if (e == EDEADLK) return DRWAV_DEADLOCK;
#endif
#ifdef ENAMETOOLONG
- case ENAMETOOLONG: return DRWAV_PATH_TOO_LONG;
+ if (e == ENAMETOOLONG) return DRWAV_PATH_TOO_LONG;
#endif
#ifdef ENOLCK
- case ENOLCK: return DRWAV_ERROR;
+ if (e == ENOLCK) return DRWAV_ERROR;
#endif
#ifdef ENOSYS
- case ENOSYS: return DRWAV_NOT_IMPLEMENTED;
+ if (e == ENOSYS) return DRWAV_NOT_IMPLEMENTED;
#endif
#ifdef ENOTEMPTY
- case ENOTEMPTY: return DRWAV_DIRECTORY_NOT_EMPTY;
+ if (e == ENOTEMPTY) return DRWAV_DIRECTORY_NOT_EMPTY;
#endif
#ifdef ELOOP
- case ELOOP: return DRWAV_TOO_MANY_LINKS;
+ if (e == ELOOP) return DRWAV_TOO_MANY_LINKS;
#endif
#ifdef ENOMSG
- case ENOMSG: return DRWAV_NO_MESSAGE;
+ if (e == ENOMSG) return DRWAV_NO_MESSAGE;
#endif
#ifdef EIDRM
- case EIDRM: return DRWAV_ERROR;
+ if (e == EIDRM) return DRWAV_ERROR;
#endif
#ifdef ECHRNG
- case ECHRNG: return DRWAV_ERROR;
+ if (e == ECHRNG) return DRWAV_ERROR;
#endif
#ifdef EL2NSYNC
- case EL2NSYNC: return DRWAV_ERROR;
+ if (e == EL2NSYNC) return DRWAV_ERROR;
#endif
#ifdef EL3HLT
- case EL3HLT: return DRWAV_ERROR;
+ if (e == EL3HLT) return DRWAV_ERROR;
#endif
#ifdef EL3RST
- case EL3RST: return DRWAV_ERROR;
+ if (e == EL3RST) return DRWAV_ERROR;
#endif
#ifdef ELNRNG
- case ELNRNG: return DRWAV_OUT_OF_RANGE;
+ if (e == ELNRNG) return DRWAV_OUT_OF_RANGE;
#endif
#ifdef EUNATCH
- case EUNATCH: return DRWAV_ERROR;
+ if (e == EUNATCH) return DRWAV_ERROR;
#endif
#ifdef ENOCSI
- case ENOCSI: return DRWAV_ERROR;
+ if (e == ENOCSI) return DRWAV_ERROR;
#endif
#ifdef EL2HLT
- case EL2HLT: return DRWAV_ERROR;
+ if (e == EL2HLT) return DRWAV_ERROR;
#endif
#ifdef EBADE
- case EBADE: return DRWAV_ERROR;
+ if (e == EBADE) return DRWAV_ERROR;
#endif
#ifdef EBADR
- case EBADR: return DRWAV_ERROR;
+ if (e == EBADR) return DRWAV_ERROR;
#endif
#ifdef EXFULL
- case EXFULL: return DRWAV_ERROR;
+ if (e == EXFULL) return DRWAV_ERROR;
#endif
#ifdef ENOANO
- case ENOANO: return DRWAV_ERROR;
+ if (e == ENOANO) return DRWAV_ERROR;
#endif
#ifdef EBADRQC
- case EBADRQC: return DRWAV_ERROR;
+ if (e == EBADRQC) return DRWAV_ERROR;
#endif
#ifdef EBADSLT
- case EBADSLT: return DRWAV_ERROR;
+ if (e == EBADSLT) return DRWAV_ERROR;
#endif
#ifdef EBFONT
- case EBFONT: return DRWAV_INVALID_FILE;
+ if (e == EBFONT) return DRWAV_INVALID_FILE;
#endif
#ifdef ENOSTR
- case ENOSTR: return DRWAV_ERROR;
+ if (e == ENOSTR) return DRWAV_ERROR;
#endif
#ifdef ENODATA
- case ENODATA: return DRWAV_NO_DATA_AVAILABLE;
+ if (e == ENODATA) return DRWAV_NO_DATA_AVAILABLE;
#endif
#ifdef ETIME
- case ETIME: return DRWAV_TIMEOUT;
+ if (e == ETIME) return DRWAV_TIMEOUT;
#endif
#ifdef ENOSR
- case ENOSR: return DRWAV_NO_DATA_AVAILABLE;
+ if (e == ENOSR) return DRWAV_NO_DATA_AVAILABLE;
#endif
#ifdef ENONET
- case ENONET: return DRWAV_NO_NETWORK;
+ if (e == ENONET) return DRWAV_NO_NETWORK;
#endif
#ifdef ENOPKG
- case ENOPKG: return DRWAV_ERROR;
+ if (e == ENOPKG) return DRWAV_ERROR;
#endif
#ifdef EREMOTE
- case EREMOTE: return DRWAV_ERROR;
+ if (e == EREMOTE) return DRWAV_ERROR;
#endif
#ifdef ENOLINK
- case ENOLINK: return DRWAV_ERROR;
+ if (e == ENOLINK) return DRWAV_ERROR;
#endif
#ifdef EADV
- case EADV: return DRWAV_ERROR;
+ if (e == EADV) return DRWAV_ERROR;
#endif
#ifdef ESRMNT
- case ESRMNT: return DRWAV_ERROR;
+ if (e == ESRMNT) return DRWAV_ERROR;
#endif
#ifdef ECOMM
- case ECOMM: return DRWAV_ERROR;
+ if (e == ECOMM) return DRWAV_ERROR;
#endif
#ifdef EPROTO
- case EPROTO: return DRWAV_ERROR;
+ if (e == EPROTO) return DRWAV_ERROR;
#endif
#ifdef EMULTIHOP
- case EMULTIHOP: return DRWAV_ERROR;
+ if (e == EMULTIHOP) return DRWAV_ERROR;
#endif
#ifdef EDOTDOT
- case EDOTDOT: return DRWAV_ERROR;
+ if (e == EDOTDOT) return DRWAV_ERROR;
#endif
#ifdef EBADMSG
- case EBADMSG: return DRWAV_BAD_MESSAGE;
+ if (e == EBADMSG) return DRWAV_BAD_MESSAGE;
#endif
#ifdef EOVERFLOW
- case EOVERFLOW: return DRWAV_TOO_BIG;
+ if (e == EOVERFLOW) return DRWAV_TOO_BIG;
#endif
#ifdef ENOTUNIQ
- case ENOTUNIQ: return DRWAV_NOT_UNIQUE;
+ if (e == ENOTUNIQ) return DRWAV_NOT_UNIQUE;
#endif
#ifdef EBADFD
- case EBADFD: return DRWAV_ERROR;
+ if (e == EBADFD) return DRWAV_ERROR;
#endif
#ifdef EREMCHG
- case EREMCHG: return DRWAV_ERROR;
+ if (e == EREMCHG) return DRWAV_ERROR;
#endif
#ifdef ELIBACC
- case ELIBACC: return DRWAV_ACCESS_DENIED;
+ if (e == ELIBACC) return DRWAV_ACCESS_DENIED;
#endif
#ifdef ELIBBAD
- case ELIBBAD: return DRWAV_INVALID_FILE;
+ if (e == ELIBBAD) return DRWAV_INVALID_FILE;
#endif
#ifdef ELIBSCN
- case ELIBSCN: return DRWAV_INVALID_FILE;
+ if (e == ELIBSCN) return DRWAV_INVALID_FILE;
#endif
#ifdef ELIBMAX
- case ELIBMAX: return DRWAV_ERROR;
+ if (e == ELIBMAX) return DRWAV_ERROR;
#endif
#ifdef ELIBEXEC
- case ELIBEXEC: return DRWAV_ERROR;
+ if (e == ELIBEXEC) return DRWAV_ERROR;
#endif
#ifdef EILSEQ
- case EILSEQ: return DRWAV_INVALID_DATA;
+ if (e == EILSEQ) return DRWAV_INVALID_DATA;
#endif
#ifdef ERESTART
- case ERESTART: return DRWAV_ERROR;
+ if (e == ERESTART) return DRWAV_ERROR;
#endif
#ifdef ESTRPIPE
- case ESTRPIPE: return DRWAV_ERROR;
+ if (e == ESTRPIPE) return DRWAV_ERROR;
#endif
#ifdef EUSERS
- case EUSERS: return DRWAV_ERROR;
+ if (e == EUSERS) return DRWAV_ERROR;
#endif
#ifdef ENOTSOCK
- case ENOTSOCK: return DRWAV_NOT_SOCKET;
+ if (e == ENOTSOCK) return DRWAV_NOT_SOCKET;
#endif
#ifdef EDESTADDRREQ
- case EDESTADDRREQ: return DRWAV_NO_ADDRESS;
+ if (e == EDESTADDRREQ) return DRWAV_NO_ADDRESS;
#endif
#ifdef EMSGSIZE
- case EMSGSIZE: return DRWAV_TOO_BIG;
+ if (e == EMSGSIZE) return DRWAV_TOO_BIG;
#endif
#ifdef EPROTOTYPE
- case EPROTOTYPE: return DRWAV_BAD_PROTOCOL;
+ if (e == EPROTOTYPE) return DRWAV_BAD_PROTOCOL;
#endif
#ifdef ENOPROTOOPT
- case ENOPROTOOPT: return DRWAV_PROTOCOL_UNAVAILABLE;
+ if (e == ENOPROTOOPT) return DRWAV_PROTOCOL_UNAVAILABLE;
#endif
#ifdef EPROTONOSUPPORT
- case EPROTONOSUPPORT: return DRWAV_PROTOCOL_NOT_SUPPORTED;
+ if (e == EPROTONOSUPPORT) return DRWAV_PROTOCOL_NOT_SUPPORTED;
#endif
#ifdef ESOCKTNOSUPPORT
- case ESOCKTNOSUPPORT: return DRWAV_SOCKET_NOT_SUPPORTED;
+ if (e == ESOCKTNOSUPPORT) return DRWAV_SOCKET_NOT_SUPPORTED;
#endif
#ifdef EOPNOTSUPP
- case EOPNOTSUPP: return DRWAV_INVALID_OPERATION;
+ if (e == EOPNOTSUPP) return DRWAV_INVALID_OPERATION;
#endif
#ifdef EPFNOSUPPORT
- case EPFNOSUPPORT: return DRWAV_PROTOCOL_FAMILY_NOT_SUPPORTED;
+ if (e == EPFNOSUPPORT) return DRWAV_PROTOCOL_FAMILY_NOT_SUPPORTED;
#endif
#ifdef EAFNOSUPPORT
- case EAFNOSUPPORT: return DRWAV_ADDRESS_FAMILY_NOT_SUPPORTED;
+ if (e == EAFNOSUPPORT) return DRWAV_ADDRESS_FAMILY_NOT_SUPPORTED;
#endif
#ifdef EADDRINUSE
- case EADDRINUSE: return DRWAV_ALREADY_IN_USE;
+ if (e == EADDRINUSE) return DRWAV_ALREADY_IN_USE;
#endif
#ifdef EADDRNOTAVAIL
- case EADDRNOTAVAIL: return DRWAV_ERROR;
+ if (e == EADDRNOTAVAIL) return DRWAV_ERROR;
#endif
#ifdef ENETDOWN
- case ENETDOWN: return DRWAV_NO_NETWORK;
+ if (e == ENETDOWN) return DRWAV_NO_NETWORK;
#endif
#ifdef ENETUNREACH
- case ENETUNREACH: return DRWAV_NO_NETWORK;
+ if (e == ENETUNREACH) return DRWAV_NO_NETWORK;
#endif
#ifdef ENETRESET
- case ENETRESET: return DRWAV_NO_NETWORK;
+ if (e == ENETRESET) return DRWAV_NO_NETWORK;
#endif
#ifdef ECONNABORTED
- case ECONNABORTED: return DRWAV_NO_NETWORK;
+ if (e == ECONNABORTED) return DRWAV_NO_NETWORK;
#endif
#ifdef ECONNRESET
- case ECONNRESET: return DRWAV_CONNECTION_RESET;
+ if (e == ECONNRESET) return DRWAV_CONNECTION_RESET;
#endif
#ifdef ENOBUFS
- case ENOBUFS: return DRWAV_NO_SPACE;
+ if (e == ENOBUFS) return DRWAV_NO_SPACE;
#endif
#ifdef EISCONN
- case EISCONN: return DRWAV_ALREADY_CONNECTED;
+ if (e == EISCONN) return DRWAV_ALREADY_CONNECTED;
#endif
#ifdef ENOTCONN
- case ENOTCONN: return DRWAV_NOT_CONNECTED;
+ if (e == ENOTCONN) return DRWAV_NOT_CONNECTED;
#endif
#ifdef ESHUTDOWN
- case ESHUTDOWN: return DRWAV_ERROR;
+ if (e == ESHUTDOWN) return DRWAV_ERROR;
#endif
#ifdef ETOOMANYREFS
- case ETOOMANYREFS: return DRWAV_ERROR;
+ if (e == ETOOMANYREFS) return DRWAV_ERROR;
#endif
#ifdef ETIMEDOUT
- case ETIMEDOUT: return DRWAV_TIMEOUT;
+ if (e == ETIMEDOUT) return DRWAV_TIMEOUT;
#endif
#ifdef ECONNREFUSED
- case ECONNREFUSED: return DRWAV_CONNECTION_REFUSED;
+ if (e == ECONNREFUSED) return DRWAV_CONNECTION_REFUSED;
#endif
#ifdef EHOSTDOWN
- case EHOSTDOWN: return DRWAV_NO_HOST;
+ if (e == EHOSTDOWN) return DRWAV_NO_HOST;
#endif
#ifdef EHOSTUNREACH
- case EHOSTUNREACH: return DRWAV_NO_HOST;
+ if (e == EHOSTUNREACH) return DRWAV_NO_HOST;
#endif
#ifdef EALREADY
- case EALREADY: return DRWAV_IN_PROGRESS;
+ if (e == EALREADY) return DRWAV_IN_PROGRESS;
#endif
#ifdef EINPROGRESS
- case EINPROGRESS: return DRWAV_IN_PROGRESS;
+ if (e == EINPROGRESS) return DRWAV_IN_PROGRESS;
#endif
#ifdef ESTALE
- case ESTALE: return DRWAV_INVALID_FILE;
+ if (e == ESTALE) return DRWAV_INVALID_FILE;
#endif
#ifdef EUCLEAN
- case EUCLEAN: return DRWAV_ERROR;
+ if (e == EUCLEAN) return DRWAV_ERROR;
#endif
#ifdef ENOTNAM
- case ENOTNAM: return DRWAV_ERROR;
+ if (e == ENOTNAM) return DRWAV_ERROR;
#endif
#ifdef ENAVAIL
- case ENAVAIL: return DRWAV_ERROR;
+ if (e == ENAVAIL) return DRWAV_ERROR;
#endif
#ifdef EISNAM
- case EISNAM: return DRWAV_ERROR;
+ if (e == EISNAM) return DRWAV_ERROR;
#endif
#ifdef EREMOTEIO
- case EREMOTEIO: return DRWAV_IO_ERROR;
+ if (e == EREMOTEIO) return DRWAV_IO_ERROR;
#endif
#ifdef EDQUOT
- case EDQUOT: return DRWAV_NO_SPACE;
+ if (e == EDQUOT) return DRWAV_NO_SPACE;
#endif
#ifdef ENOMEDIUM
- case ENOMEDIUM: return DRWAV_DOES_NOT_EXIST;
+ if (e == ENOMEDIUM) return DRWAV_DOES_NOT_EXIST;
#endif
#ifdef EMEDIUMTYPE
- case EMEDIUMTYPE: return DRWAV_ERROR;
+ if (e == EMEDIUMTYPE) return DRWAV_ERROR;
#endif
#ifdef ECANCELED
- case ECANCELED: return DRWAV_CANCELLED;
+ if (e == ECANCELED) return DRWAV_CANCELLED;
#endif
#ifdef ENOKEY
- case ENOKEY: return DRWAV_ERROR;
+ if (e == ENOKEY) return DRWAV_ERROR;
#endif
#ifdef EKEYEXPIRED
- case EKEYEXPIRED: return DRWAV_ERROR;
+ if (e == EKEYEXPIRED) return DRWAV_ERROR;
#endif
#ifdef EKEYREVOKED
- case EKEYREVOKED: return DRWAV_ERROR;
+ if (e == EKEYREVOKED) return DRWAV_ERROR;
#endif
#ifdef EKEYREJECTED
- case EKEYREJECTED: return DRWAV_ERROR;
+ if (e == EKEYREJECTED) return DRWAV_ERROR;
#endif
#ifdef EOWNERDEAD
- case EOWNERDEAD: return DRWAV_ERROR;
+ if (e == EOWNERDEAD) return DRWAV_ERROR;
#endif
#ifdef ENOTRECOVERABLE
- case ENOTRECOVERABLE: return DRWAV_ERROR;
+ if (e == ENOTRECOVERABLE) return DRWAV_ERROR;
#endif
#ifdef ERFKILL
- case ERFKILL: return DRWAV_ERROR;
+ if (e == ERFKILL) return DRWAV_ERROR;
#endif
#ifdef EHWPOISON
- case EHWPOISON: return DRWAV_ERROR;
+ if (e == EHWPOISON) return DRWAV_ERROR;
#endif
- default: return DRWAV_ERROR;
- }
+ return DRWAV_ERROR;
}
static drwav_result drwav_fopen(FILE** ppFile, const char* pFilePath, const char* pOpenMode)
diff --git a/whisper.cpp/main.1 b/whisper.cpp/main.1
new file mode 100644
index 00000000..8f9723da
--- /dev/null
+++ b/whisper.cpp/main.1
@@ -0,0 +1,60 @@
+.Dd August 17, 2024
+.Dt WHISPERFILE 1
+.Os Mozilla Ocho
+.Sh NAME
+.Nm whisperfile
+.Nd speech to text engine
+.Sh SYNOPSIS
+.Nm
+.Op flags...
+.Fl m Ar model.gguf
+.Fl f Ar audio.wav
+.Nm
+.Op flags...
+.Fl Fl server
+.Fl m Ar model.gguf
+.Sh DESCRIPTION
+.Nm
+is a high-performance implementation of OpenAI's Whisper model that's
+based off the whisper.cpp software written by Georgi Gerganov, et al.
+It's able to convert speech to text. It can also translate different
+languages into English while transcribing.
+.Sh OPTIONS
+The following options are available:
+.Bl -tag -width indent
+.It Fl Fl version
+Print version and exit.
+.It Fl h , Fl Fl help
+Show help message and exit.
+.It Fl Fl server
+Puts program in HTTP server mode.
+.It Fl m Ar FNAME , Fl Fl model Ar FNAME
+Path of Whisper model weights. See
+https://huggingface.co/ggerganov/whisper.cpp
+.It Fl f Ar FNAME , Fl Fl file Ar FNAME
+Path of WAV file to transcribe.
+.It Fl tr , Fl Fl translate
+Translate audio into English text.
+.It Fl ot Ar N , Fl Fl offset-t Ar N
+Time offset in milliseconds.
+.It Fl d Ar N , Fl Fl duration Ar N
+Duration of audio to process in milliseconds.
+.It Fl pc , Fl Fl print-colors
+Enables CLI printing of ANSI color codes.
+.Pp
+Transcribed text will appear in the terminal on a spectrum of color
+ranging from green to red. Green means the model
+.It Fl t Ar N , Fl Fl threads Ar N
+Overrides number of threads to use.
+.Pp
+The default is the number of cores available on the current system. On
+systems with hyperthreading, that's half the number of CPUs reported by
+the system. On systems that have efficiency cores, e.g. Intel Alderlake,
+the default behavior is to use only the performance cores.
+.Sh DOCUMENTATION
+Read our Markdown documentation for additional help and tutorials. See
+whisper.cpp/doc/index.md in the llamafile source repository on GitHub.
+.Sh SEE ALSO
+.Xr llamafile 1 ,
+.Xr zipalign 1 ,
+.Xr unzip 1
diff --git a/whisper.cpp/main.1.asc b/whisper.cpp/main.1.asc
new file mode 100644
index 00000000..2c5f1c0c
--- /dev/null
+++ b/whisper.cpp/main.1.asc
@@ -0,0 +1,66 @@
+WHISPERFILE(1) General Commands Manual WHISPERFILE(1)
+
+NAME
+ whisperfile — speech to text engine
+
+SYNOPSIS
+ whisperfile [flags...] -m model.gguf -f audio.wav
+ whisperfile [flags...] --server -m model.gguf
+
+DESCRIPTION
+ whisperfile is a high-performance implementation of OpenAI's Whisper
+ model that's based off the whisper.cpp software written by Georgi
+ Gerganov, et al. It's able to convert speech to text. It can also
+ translate different languages into English while transcribing.
+
+OPTIONS
+ The following options are available:
+
+ --version
+ Print version and exit.
+
+ -h, --help
+ Show help message and exit.
+
+ --server
+ Puts program in HTTP server mode.
+
+ -m FNAME, --model FNAME
+ Path of Whisper model weights. See https://hugging‐
+ face.co/ggerganov/whisper.cpp
+
+ -f FNAME, --file FNAME
+ Path of WAV file to transcribe.
+
+ -tr, --translate
+ Translate audio into English text.
+
+ -ot N, --offset-t N
+ Time offset in milliseconds.
+
+ -d N, --duration N
+ Duration of audio to process in milliseconds.
+
+ -pc, --print-colors
+ Enables CLI printing of ANSI color codes.
+
+ Transcribed text will appear in the terminal on a spectrum of
+ color ranging from green to red. Green means the model
+
+ -t N, --threads N
+ Overrides number of threads to use.
+
+ The default is the number of cores available on the current
+ system. On systems with hyperthreading, that's half the number
+ of CPUs reported by the system. On systems that have efficiency
+ cores, e.g. Intel Alderlake, the default behavior is to use
+ only the performance cores.
+
+DOCUMENTATION
+ Read our Markdown documentation for additional help and tutorials. See
+ whisper.cpp/doc/index.md in the llamafile source repository on GitHub.
+
+SEE ALSO
+ llamafile(1), zipalign(1), unzip(1)
+
+Mozilla Ocho August 17, 2024 WHISPERFILE(1)
diff --git a/whisper.cpp/main.cpp b/whisper.cpp/main.cpp
index 8600af3a..214eba92 100644
--- a/whisper.cpp/main.cpp
+++ b/whisper.cpp/main.cpp
@@ -1,5 +1,7 @@
// -*- mode:c++;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-
// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi
+#include "llamafile/version.h"
+#include "llamafile/llamafile.h"
#include "common.h"
#include "whisper.h"
@@ -13,6 +15,7 @@
#include <thread>
#include <vector>
#include <cstring>
+#include <cosmo.h>
#include "llamafile/llamafile.h"
#include "llamafile/debug.h"
@@ -211,8 +214,8 @@ static bool whisper_params_parse(int argc, char ** argv, whisper_params & params
else if ( arg == "--grammar-rule") { params.grammar_rule = argv[++i]; }
else if ( arg == "--grammar-penalty") { params.grammar_penalty = std::stof(argv[++i]); }
else {
- fprintf(stderr, "error: unknown argument: %s\n", arg.c_str());
- whisper_print_usage(argc, argv, params);
+ fprintf(stderr, "error: unknown argument: %s\n", arg.c_str()); // [jart]
+ // whisper_print_usage(argc, argv, params); // [jart]
exit(0);
}
}
@@ -943,13 +946,36 @@ static bool output_lrc(struct whisper_context * ctx, const char * fname, const w
static void cb_log_disable(enum ggml_log_level , const char * , void * ) { }
+int whisper_server_main(int argc, char ** argv);
+
int main(int argc, char ** argv) {
- whisper_params params;
+ mallopt(M_GRANULARITY, 1 * 1024 * 1024);
+ mallopt(M_MMAP_THRESHOLD, 1 * 1024 * 1024);
+ mallopt(M_TRIM_THRESHOLD, 32 * 1024 * 1024);
+ FLAG_gpu = LLAMAFILE_GPU_DISABLE; // pass `--gpu auto` to enable it
+ llamafile_check_cpu();
ShowCrashReports();
- // [jart] disable GPU by default (pass `--gpu auto` to enable it)
- FLAG_gpu = LLAMAFILE_GPU_DISABLE;
+ if (llamafile_has(argv, "--version")) {
+ puts("whisperfile v" LLAMAFILE_VERSION_STRING);
+ return 0;
+ }
+
+ if (llamafile_has(argv, "-h") ||
+ llamafile_has(argv, "-help") ||
+ llamafile_has(argv, "--help")) {
+ llamafile_help("/zip/whisper.cpp/main.1.asc");
+ __builtin_unreachable();
+ }
+
+ LoadZipArgs(&argc, &argv);
+
+ if (!llamafile_has(argv, "--cli") &&
+ (llamafile_has(argv, "--server") ||
+ !llamafile_has(argv, "-f"))) {
+ return whisper_server_main(argc, argv);
+ }
// If the only argument starts with "@", read arguments line-by-line
// from the given file.
@@ -980,6 +1006,7 @@ int main(int argc, char ** argv) {
}
}
+ whisper_params params;
if (whisper_params_parse(argc, argv, params) == false) {
whisper_print_usage(argc, argv, params);
return 1;
diff --git a/whisper.cpp/server.cpp b/whisper.cpp/server.cpp
index 93ce5442..4a11708d 100644
--- a/whisper.cpp/server.cpp
+++ b/whisper.cpp/server.cpp
@@ -1,5 +1,6 @@
// -*- mode:c++;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-
// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi
+#include "llamafile/debug.h"
#include "common.h"
#include "whisper.h"
@@ -148,6 +149,38 @@ bool whisper_params_parse(int argc, char ** argv, whisper_params & params, serve
for (int i = 1; i < argc; i++) {
std::string arg = argv[i];
+ if (arg == "--log-disable") {
+ FLAG_log_disable = true;
+ } else if (arg == "--fast") {
+ FLAG_fast = true;
+ } else if (arg == "--precise") {
+ FLAG_precise = true;
+ } else if (arg == "--trace") {
+ FLAG_trace = true;
+ } else if (arg == "--trap") {
+ FLAG_trap = true;
+ FLAG_unsecure = true; // for better backtraces
+ llamafile_trapping_enabled(+1);
+ } else if (arg == "--unsecure") {
+ FLAG_unsecure = true;
+ } else if (arg == "--nocompile") {
+ FLAG_nocompile = true;
+ } else if (arg == "--recompile") {
+ FLAG_recompile = true;
+ } else if (arg == "--tinyblas") {
+ FLAG_tinyblas = true; // undocumented
+ } else if (arg == "--gpu") {
+ if (++i >= argc) {
+ fprintf(stderr, "error: missing --gpu flag value\n");
+ exit(1);
+ }
+ FLAG_gpu = llamafile_gpu_parse(argv[i]);
+ if (FLAG_gpu == LLAMAFILE_GPU_ERROR) {
+ fprintf(stderr, "error: invalid --gpu flag value: %s\n", argv[i]);
+ exit(1);
+ }
+ } else
+
if (arg == "-h" || arg == "--help") {
whisper_print_usage(argc, argv, params, sparams);
exit(0);
@@ -211,7 +244,7 @@ bool whisper_params_parse(int argc, char ** argv, whisper_params & params, serve
else {
fprintf(stderr, "error: unknown argument: %s\n", arg.c_str());
- whisper_print_usage(argc, argv, params, sparams);
+ // whisper_print_usage(argc, argv, params, sparams); // [jart]
exit(0);
}
}
@@ -501,17 +534,12 @@ void get_req_parameters(const Request & req, whisper_params & params)
} // namespace
-int main(int argc, char ** argv) {
+int whisper_server_main(int argc, char ** argv) {
whisper_params params;
server_params sparams;
std::mutex whisper_mutex;
- // [jart] disable GPU by default (pass `--gpu auto` to enable it)
- FLAG_gpu = LLAMAFILE_GPU_DISABLE;
-
- LoadZipArgs(&argc, &argv);
-
if (whisper_params_parse(argc, argv, params, sparams) == false) {
whisper_print_usage(argc, argv, params, sparams);
return 1;
diff --git a/whisper.cpp/whisper.cpp b/whisper.cpp/whisper.cpp
index f7b71784..f8c18a59 100644
--- a/whisper.cpp/whisper.cpp
+++ b/whisper.cpp/whisper.cpp
@@ -2867,8 +2867,8 @@ static bool whisper_decode_internal(
logits = gf->nodes[gf->n_nodes - 1];
if (batch.n_tokens < 16) {
- if (n_threads > 20)
- n_threads = 20;
+ if (n_threads > 23)
+ n_threads = 23;
}
if (!ggml_graph_compute_helper(sched, gf, n_threads)) {