Distribute and run LLMs with a single file.
C++ cross-platformggufllama-cpplocal-ailocal-inferencelocal-llmopen-source-aisingle-file-executablespeech-to-text
Write a lot of documentation and man pages
Justine Tunney202e554509fe
diff --git a/Makefile b/Makefileindex 997a35db..e3f6f6ef 100644--- a/Makefile+++ b/Makefile@@ -31,11 +31,13 @@ o/$(MODE)/: o/$(MODE)/llamafile \# for installing to `make PREFIX=/usr/local`.PHONY: installinstall: 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/whisperfilemkdir -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: checkcheck: o/$(MODE)/llamafile/checkdiff --git a/llama.cpp/common.cpp b/llama.cpp/common.cppindex 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_ARGconst 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_parif (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_parif (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_parif (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_parif (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_partmp.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.hindex 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 infoextern 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 scalestd::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_paramstruct 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 utilsvoid llama_batch_clear(struct llama_batch & batch);diff --git a/llama.cpp/imatrix/imatrix.cpp b/llama.cpp/imatrix/imatrix.cppindex 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.cppindex 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.ascindex df24c93c..2fa76cbf 100644--- a/llama.cpp/main/main.1.asc+++ b/llama.cpp/main/main.1.asc@@ -42,7 +42,7 @@[1m-m [4m[22mFNAME[24m, [1m--model [4m[22mFNAME[0mModel path in the GGUF file format.- Default: [4mmodels/7B/ggml‐model‐f16.gguf[0m+ Default: [4mmodels/7B/ggml-model-f16.gguf[0m[1m--mmproj [4m[22mFNAME[0mSpecifies 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 ifthis is less than zero.- Default: ‐1+ Default: -1[1m-t [4m[22mN[24m, [1m--threads [4m[22mN[0mNumber of threads to use during generation.Default: $(nproc)/2- [1m-tb [4m[22mN[24m, [1m--threads‐batch [4m[22mN[0m+ [1m-tb [4m[22mN[24m, [1m--threads-batch [4m[22mN[0mSet 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 [1m--threads[0m- [1m-td [4m[22mN[24m, [1m--threads‐draft [4m[22mN[0m+ [1m-td [4m[22mN[24m, [1m--threads-draft [4m[22mN[0mNumber of threads to use during generation.Default: Same as [1m--threads[0m- [1m-tbd [4m[22mN[24m, [1m--threads‐batch‐draft [4m[22mN[0m+ [1m-tbd [4m[22mN[24m, [1m--threads-batch-draft [4m[22mN[0mNumber of threads to use during batch and prompt processing.- Default: Same as [1m--threads‐draft[0m+ Default: Same as [1m--threads-draft[0m- [1m--in‐prefix‐bos[0m- Prefix BOS to user inputs, preceding the [1m--in‐prefix [22mstring.+ [1m--in-prefix-bos[0m+ Prefix BOS to user inputs, preceding the [1m--in-prefix [22mstring.- [1m--in‐prefix [4m[22mSTRING[0m+ [1m--in-prefix [4m[22mSTRING[0mThis 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 [1m--in‐prefix [22mflag in conjunction- with the [1m--reverse‐prompt [22mflag:+ this is used to insert a space after the reverse prompt. Here's+ an example of how to use the [1m--in-prefix [22mflag in conjunction+ with the [1m--reverse-prompt [22mflag:- [1m./main ‐r "User:" ‐‐in‐prefix " "[0m+ [1m./main -r "User:" --in-prefix " "[0mDefault: empty- [1m--in‐suffix [4m[22mSTRING[0m+ [1m--in-suffix [4m[22mSTRING[0mThis 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 [1m--in‐suffix [22mflag in conjunction with the- [1m--reverse‐prompt [22mflag:+ 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 [1m--in-suffix [22mflag in conjunction with the+ [1m--reverse-prompt [22mflag:- [1m./main ‐r "User:" ‐‐in‐prefix " " ‐‐in‐suffix[0m+ [1m./main -r "User:" --in-prefix " " --in-suffix[0m[1m"Assistant:"[0mDefault: empty- [1m-n [4m[22mN[24m, [1m--n‐predict [4m[22mN[0m+ [1m-n [4m[22mN[24m, [1m--n-predict [4m[22mN[0mNumber of tokens to predict.- [1m- [22m‐1 = infinity- [1m- [22m‐2 = until context filled+ [1m- [22m-1 = infinity+ [1m- [22m-2 = until context filled- Default: ‐1+ Default: -1- [1m-c [4m[22mN[24m, [1m--ctx‐size [4m[22mN[0m+ [1m-c [4m[22mN[24m, [1m--ctx-size [4m[22mN[0mSet the size of the prompt context. A larger context size helpsthe model to better comprehend and generate responses forlonger input or conversations. The LLaMA models were built with@@ -125,27 +125,27 @@Default: 512- [1m-b [4m[22mN[24m, [1m--batch‐size [4m[22mN[0m+ [1m-b [4m[22mN[24m, [1m--batch-size [4m[22mN[0mBatch size for prompt processing.Default: 512- [1m--top‐k [4m[22mN[0m- Top‐k sampling.+ [1m--top-k [4m[22mN[0m+ Top-k sampling.[1m- [22m0 = disabledDefault: 40- [1m--top‐p [4m[22mN[0m- Top‐p sampling.+ [1m--top-p [4m[22mN[0m+ Top-p sampling.[1m- [22m1.0 = disabledDefault: 0.9- [1m--min‐p [4m[22mN[0m- Min‐p sampling.+ [1m--min-p [4m[22mN[0m+ Min-p sampling.[1m- [22m0.0 = disabled@@ -165,29 +165,29 @@Default: 1.0- [1m--repeat‐last‐n [4m[22mN[0m+ [1m--repeat-last-n [4m[22mN[0mLast n tokens to consider for penalize.[1m- [22m0 = disabled- [1m- [22m‐1 = ctx_size+ [1m- [22m-1 = ctx_sizeDefault: 64- [1m--repeat‐penalty [4m[22mN[0m+ [1m--repeat-penalty [4m[22mN[0mPenalize repeat sequence of tokens.[1m- [22m1.0 = disabledDefault: 1.1- [1m--presence‐penalty [4m[22mN[0m+ [1m--presence-penalty [4m[22mN[0mRepeat alpha presence penalty.[1m- [22m0.0 = disabledDefault: 0.0- [1m--frequency‐penalty [4m[22mN[0m+ [1m--frequency-penalty [4m[22mN[0mRepeat alpha frequency penalty.[1m- [22m0.0 = disabled@@ -204,99 +204,99 @@Default: 0- [1m--mirostat‐lr [4m[22mN[0m+ [1m--mirostat-lr [4m[22mN[0mMirostat learning rate, parameter eta.Default: 0.1- [1m--mirostat‐ent [4m[22mN[0m+ [1m--mirostat-ent [4m[22mN[0mMirostat target entropy, parameter tau.Default: 5.0- [1m-l [4m[22mTOKEN_ID(+/‐)BIAS[24m, [1m--logit‐bias [4m[22mTOKEN_ID(+/‐)BIAS[0m+ [1m-l [4m[22mTOKEN_ID(+/-)BIAS[24m, [1m--logit-bias [4m[22mTOKEN_ID(+/-)BIAS[0mModifies the likelihood of token appearing in the completion,- i.e. [1m--logit‐bias [4m[22m15043+1[24m to increase likelihood of token- [4m’[24m [4mHello’[24m, or [1m--logit‐bias [4m[22m15043‐1[24m to decrease likelihood of to‐- ken [4m’[24m [4mHello’[24m.+ i.e. [1m--logit-bias [4m[22m15043+1[24m to increase likelihood of token+ [4m'[24m [4mHello'[24m, or [1m--logit-bias [4m[22m15043-1[24m to decrease likelihood of to‐+ ken [4m'[24m [4mHello'[24m.- [1m-md [4m[22mFNAME[24m, [1m--model‐draft [4m[22mFNAME[0m+ [1m-md [4m[22mFNAME[24m, [1m--model-draft [4m[22mFNAME[0mDraft model for speculative decoding.- Default: [4mmodels/7B/ggml‐model‐f16.gguf[0m+ Default: [4mmodels/7B/ggml-model-f16.gguf[0m- [1m--cfg‐negative‐prompt [4m[22mPROMPT[0m+ [1m--cfg-negative-prompt [4m[22mPROMPT[0mNegative prompt to use for guidance..Default: empty- [1m--cfg‐negative‐prompt‐file [4m[22mFNAME[0m+ [1m--cfg-negative-prompt-file [4m[22mFNAME[0mNegative prompt file to use for guidance.Default: empty- [1m--cfg‐scale [4m[22mN[0m+ [1m--cfg-scale [4m[22mN[0mStrength of guidance.[1m- [22m1.0 = disableDefault: 1.0- [1m--rope‐scaling [4m[22m{none,linear,yarn}[0m+ [1m--rope-scaling [4m[22m{none,linear,yarn}[0mRoPE frequency scaling method, defaults to linear unless speci‐fied by the model- [1m--rope‐scale [4m[22mN[0m+ [1m--rope-scale [4m[22mN[0mRoPE context scaling factor, expands context by a factor of [4mN[0m- where [4mN[24m 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 [4mN[24m 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 modelhave 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 [1m--ctx‐size [22mto 32768 (32k)- and [1m--rope‐scale [22mto 8.+ the fine-tuned model have 32k. That is a scaling factor of 8,+ and should work by setting the above [1m--ctx-size [22mto 32768 (32k)+ and [1m--rope-scale [22mto 8.- [1m--rope‐freq‐base [4m[22mN[0m- RoPE base frequency, used by NTK‐aware scaling.+ [1m--rope-freq-base [4m[22mN[0m+ RoPE base frequency, used by NTK-aware scaling.Default: loaded from model- [1m--rope‐freq‐scale [4m[22mN[0m+ [1m--rope-freq-scale [4m[22mN[0mRoPE frequency scaling factor, expands context by a factor of1/N- [1m--yarn‐orig‐ctx [4m[22mN[0m+ [1m--yarn-orig-ctx [4m[22mN[0mYaRN: original context size of model.Default: 0 = model training context size- [1m--yarn‐ext‐factor [4m[22mN[0m+ [1m--yarn-ext-factor [4m[22mN[0mYaRN: extrapolation mix factor.[1m- [22m0.0 = full interpolationDefault: 1.0- [1m--yarn‐attn‐factor [4m[22mN[0m+ [1m--yarn-attn-factor [4m[22mN[0mYaRN: scale sqrt(t) or attention magnitude.Default: 1.0- [1m--yarn‐beta‐slow [4m[22mN[0m+ [1m--yarn-beta-slow [4m[22mN[0mYaRN: high correction dim or alpha.Default: 1.0- [1m--yarn‐beta‐fast [4m[22mN[0m+ [1m--yarn-beta-fast [4m[22mN[0mYaRN: low correction dim or beta.Default: 32.0- [1m--ignore‐eos[0m+ [1m--ignore-eos[0mIgnore end of stream token and continue generating (implies- [1m--logit‐bias [4m[22m2‐inf[24m)+ [1m--logit-bias [4m[22m2-inf[24m)- [1m--no‐penalize‐nl[0m+ [1m--no-penalize-nl[0mDo not penalize newline token.[1m--temp [4m[22mN[0m@@ -304,16 +304,16 @@Default: 0.8- [1m--logits‐all[0m+ [1m--logits-all[0mReturn logits for all tokens in the batch.Default: disabled[1m--hellaswag[0mCompute HellaSwag score over random tasks from datafile sup‐- plied with ‐f+ plied with -f- [1m--hellaswag‐tasks [4m[22mN[0m+ [1m--hellaswag-tasks [4m[22mN[0mNumber of tasks to use when computing the HellaSwag score.Default: 400@@ -326,7 +326,7 @@model resets its internal context.[1m- [22m0 = no tokens are kept from initial prompt- [1m- [22m‐1 = retain all tokens from initial prompt+ [1m- [22m-1 = retain all tokens from initial promptDefault: 0@@ -338,21 +338,21 @@[1m--chunks [4m[22mN[0mMax number of chunks to process.- [1m- [22m‐1 = all+ [1m- [22m-1 = all- Default: ‐1+ Default: -1[1m-ns [4m[22mN[24m, [1m--sequences [4m[22mN[0mNumber of sequences to decode.Default: 1- [1m-pa [4m[22mN[24m, [1m--p‐accept [4m[22mN[0m+ [1m-pa [4m[22mN[24m, [1m--p-accept [4m[22mN[0mspeculative decoding accept probability.Default: 0.5- [1m-ps [4m[22mN[24m, [1m--p‐split [4m[22mN[0m+ [1m-ps [4m[22mN[24m, [1m--p-split [4m[22mN[0mSpeculative decoding split probability.Default: 0.1@@ -361,8 +361,8 @@Force system to keep model in RAM rather than swapping or com‐pressing.- [1m--no‐mmap[0m- Do not memory‐map model (slower load but may reduce pageouts if+ [1m--no-mmap[0m+ Do not memory-map model (slower load but may reduce pageouts ifnot using mlock).[1m--numa [22mAttempt 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 [4m~/.llamafile/[0m- 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'llbe extracted and linked if possible. Otherwise, [1mllamafile [22mwillskip any attempt to compile GPU support and simply fall back tousing CPU inference.@@ -399,9 +399,9 @@to run on the host machine is determined automaticallybased on the output of the hipInfo command. On Windows,[1mllamafile [22mrelease 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 HIPSDK 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 recommendedthat the SDK be installed anyway. If an AMD GPU could notbe 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 itworks 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 [1mllamafile[0mcommand should be run once from the x64 MSVC command promptwith the [1m--recompile [22mflag passed. The GGML library will@@ -420,50 +420,50 @@[1m- [4m[22mDISABLE[24m: Never use GPU and instead use CPU inference. Thissetting is implied by [1m-ngl [4m[22m0[24m.- [1m-ngl [4m[22mN[24m, [1m--n‐gpu‐layers [4m[22mN[0m+ [1m-ngl [4m[22mN[24m, [1m--n-gpu-layers [4m[22mN[0mNumber of layers to store in VRAM.- [1m-ngld [4m[22mN[24m, [1m--n‐gpu‐layers‐draft [4m[22mN[0m+ [1m-ngld [4m[22mN[24m, [1m--n-gpu-layers-draft [4m[22mN[0mNumber of layers to store in VRAM for the draft model.- [1m-sm [4m[22mSPLIT_MODE[24m, [1m--split‐mode [4m[22mSPLIT_MODE[0m+ [1m-sm [4m[22mSPLIT_MODE[24m, [1m--split-mode [4m[22mSPLIT_MODE[0mHow to split the model across multiple GPUs, one of:[1m- [22mnone: use one GPU only[1m- [22mlayer (default): split layers and KV across GPUs[1m- [22mrow: split rows across GPUs- [1m-ts [4m[22mSPLIT[24m, [1m--tensor‐split [4m[22mSPLIT[0m+ [1m-ts [4m[22mSPLIT[24m, [1m--tensor-split [4m[22mSPLIT[0mWhen using multiple GPUs this option controls how large tensors- should be split across all GPUs. [4mSPLIT[24m is a comma‐separated- list of non‐negative values that assigns the proportion of data+ should be split across all GPUs. [4mSPLIT[24m is a comma-separated+ list of non-negative values that assigns the proportion of datathat 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 thedata is split in proportion to VRAM but this may not be optimalfor 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- [1m-mg [4m[22mi[24m, [1m--main‐gpu [4m[22mi[0m+ [1m-mg [4m[22mi[24m, [1m--main-gpu [4m[22mi[0mThe GPU to use for scratch and small tensors.- [1m-nommq[22m, [1m--no‐mul‐mat‐q[0m+ [1m-nommq[22m, [1m--no-mul-mat-q[0mUse cuBLAS instead of custom mul_mat_q CUDA kernels. Not recom‐mended since this is both slower and uses more VRAM.- [1m--verbose‐prompt[0m+ [1m--verbose-prompt[0mPrint prompt before generation.- [1m--simple‐io[0m+ [1m--simple-io[0mUse basic IO for better compatibility in subprocesses and lim‐ited consoles.[1m--lora [4m[22mFNAME[0m- Apply LoRA adapter (implies [1m--no‐mmap[22m)+ Apply LoRA adapter (implies [1m--no-mmap[22m)- [1m--lora‐scaled [4m[22mFNAME[24m [4mS[0m+ [1m--lora-scaled [4m[22mFNAME[24m [4mS[0mApply LoRA adapter with user defined scaling S (implies- [1m--no‐mmap[22m)+ [1m--no-mmap[22m)- [1m--lora‐base [4m[22mFNAME[0m+ [1m--lora-base [4m[22mFNAME[0mOptional model to use as a base for the layers modified by theLoRA adapter@@ -475,67 +475,67 @@rated by semicolon, for example: top_k;tfs;typi‐cal;top_p;min_p;temp- [1m--samplers‐seq[0m+ [1m--samplers-seq[0mSimplified sequence for samplers that will be used.[1m-cml[22m, [1m--chatml[0m- Run in chatml mode (use with ChatML‐compatible models)+ Run in chatml mode (use with ChatML-compatible models)- [1m-dkvc[22m, [1m--dump‐kv‐cache[0m+ [1m-dkvc[22m, [1m--dump-kv-cache[0mVerbose print of the KV cache.- [1m-nkvo[22m, [1m--no‐kv‐offload[0m+ [1m-nkvo[22m, [1m--no-kv-offload[0mDisable KV offload.- [1m-ctk [4m[22mTYPE[24m, [1m--cache‐type‐k [4m[22mTYPE[0m+ [1m-ctk [4m[22mTYPE[24m, [1m--cache-type-k [4m[22mTYPE[0mKV cache data type for K.- [1m-ctv [4m[22mTYPE[24m, [1m--cache‐type‐v [4m[22mTYPE[0m+ [1m-ctv [4m[22mTYPE[24m, [1m--cache-type-v [4m[22mTYPE[0mKV cache data type for V.- [1m-gan [4m[22mN[24m, [1m--grp‐attn‐n [4m[22mN[0m- Group‐attention factor.+ [1m-gan [4m[22mN[24m, [1m--grp-attn-n [4m[22mN[0m+ Group-attention factor.Default: 1- [1m-gaw [4m[22mN[24m, [1m--grp‐attn‐w [4m[22mN[0m- Group‐attention width.+ [1m-gaw [4m[22mN[24m, [1m--grp-attn-w [4m[22mN[0m+ Group-attention width.Default: 512- [1m-bf [4m[22mFNAME[24m, [1m--binary‐file [4m[22mFNAME[0m+ [1m-bf [4m[22mFNAME[24m, [1m--binary-file [4m[22mFNAME[0mBinary file containing multiple choice tasks.[1m--winogrande[0mCompute Winogrande score over random tasks from datafile sup‐plied by the [1m-f [22mflag.- [1m--winogrande‐tasks [4m[22mN[0m+ [1m--winogrande-tasks [4m[22mN[0mNumber of tasks to use when computing the Winogrande score.Default: 0- [1m--multiple‐choice[0m+ [1m--multiple-choice[0mCompute multiple choice score over random tasks from datafilesupplied by the [1m-f [22mflag.- [1m--multiple‐choice‐tasks [4m[22mN[0m+ [1m--multiple-choice-tasks [4m[22mN[0mNumber of tasks to use when computing the multiple choicescore.Default: 0- [1m--kl‐divergence[0m- Computes KL‐divergence to logits provided via the- [1m--kl‐divergence‐base [22mflag.+ [1m--kl-divergence[0m+ Computes KL-divergence to logits provided via the+ [1m--kl-divergence-base [22mflag.- [1m--save‐all‐logits [4m[22mFNAME[24m, [1m--kl‐divergence‐base [4m[22mFNAME[0m+ [1m--save-all-logits [4m[22mFNAME[24m, [1m--kl-divergence-base [4m[22mFNAME[0mSave logits to filename.- [1m-ptc [4m[22mN[24m, [1m--print‐token‐count [4m[22mN[0m+ [1m-ptc [4m[22mN[24m, [1m--print-token-count [4m[22mN[0mPrint token count every [4mN[24m tokens.- Default: ‐1+ Default: -1[1m--pooling [4m[22mKIND[0mSpecifies pooling type for embeddings. This may be one of:@@ -554,42 +554,42 @@Process prompt escapes sequences (\n, \r, \t, \´, \", \\)[1m-p [4m[22mSTRING[24m, [1m--prompt [4m[22mSTRING[0m- 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:- [1mllamafile ‐m model.gguf ‐p "four score and"[0m+ [1mllamafile -m model.gguf -p "four score and"[0m- Stands a pretty good chance of printing Lincoln’s Gettysburg+ Stands a pretty good chance of printing Lincoln's GettysburgAddress. Prompts can take on a structured format too. Depend‐ing on how your model was trained, it may specify in its docsan instruction notation. With some models that might be:- [1mllamafile ‐p "[INST]Summarize this: $(cat file)[/INST]"[0m+ [1mllamafile -p "[INST]Summarize this: $(cat file)[/INST]"[0mIn most cases, simply colons and newlines will work too:- [1mllamafile ‐e ‐p "User: What is best in life?\nAssistant:"[0m+ [1mllamafile -e -p "User: What is best in life?\nAssistant:"[0m[1m-f [4m[22mFNAME[24m, [1m--file [4m[22mFNAME[0mPrompt file to start generation.[1m--grammar [4m[22mGRAMMAR[0m- BNF‐like grammar to constrain which tokens may be selected when+ BNF-like grammar to constrain which tokens may be selected whengenerating text. For example, the grammar:[1mroot ::= "yes" | "no"[0mwill force the LLM to only output yes or no before exiting.- This is useful for shell scripts when the [1m--no‐display‐prompt[0m+ This is useful for shell scripts when the [1m--no-display-prompt[0mflag is also supplied.- [1m--grammar‐file [4m[22mFNAME[0m+ [1m--grammar-file [4m[22mFNAME[0mFile to read grammar from.[1m--fast [22mPut llamafile into fast math mode. This disables algorithmsthat reduce floating point rounding, e.g. Kahan summation, andcertain functions like expf() will be vectorized but handle un‐- derflows less gracefully. It’s unspecified whether llamafile+ derflows less gracefully. It's unspecified whether llamafileruns in fast or precise math mode when neither flag is speci‐fied.@@ -597,7 +597,7 @@Put llamafile into precise math mode. This enables algorithmsthat reduce floating point rounding, e.g. Kahan summation, andcertain 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 orprecise math mode when neither flag is specified.[1m--trap [22mPut 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.- [1m--prompt‐cache [4m[22mFNAME[0m+ [1m--prompt-cache [4m[22mFNAME[0mFile to cache prompt state for faster startup.Default: none- [1m-fa [4m[22mFNAME[24m, [1m--flash‐attn[0m+ [1m-fa [4m[22mFNAME[24m, [1m--flash-attn[0mEnable Flash Attention. This is a mathematical shortcut thatcan speed up inference for certain models. This feature isstill under active development.- [1m--prompt‐cache‐all[0m+ [1m--prompt-cache-all[0mIf specified, saves user input and generations to cache aswell. Not supported with [1m--interactive [22mor other interactive op‐tions.- [1m--prompt‐cache‐ro[0m+ [1m--prompt-cache-ro[0mIf specified, uses the prompt cache but does not update it.- [1m--random‐prompt[0m+ [1m--random-prompt[0mStart with a randomized prompt.[1m--image [4m[22mIMAGE_FILE[0mPath 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 directlyinto 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 [1m--mmproj [22mflag for supplying the vision model.[1m-i[22m, [1m--interactive[0mRun 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 tothe model.- [1m--interactive‐first[0m+ [1m--interactive-first[0mRun the program in interactive mode and immediately wait foruser input before starting the text generation.@@ -653,7 +653,7 @@signed to work with Alpaca models that excel in completingtasks based on user instructions.- Technical details: The user’s input is internally prefixed with+ Technical details: The user's input is internally prefixed withthe reverse prompt (or "### Instruction:" as the default), andfollowed by "### Response:" (except if you just press Returnwithout any input, to keep generating a longer response).@@ -663,33 +663,33 @@els, tailoring the text generation process to your specificneeds.- [1m-r [4m[22mPROMPT[24m, [1m--reverse‐prompt [4m[22mPROMPT[0m+ [1m-r [4m[22mPROMPT[24m, [1m--reverse-prompt [4m[22mPROMPT[0mSpecify one or multiple reverse prompts to pause text genera‐tion and switch to interactive mode. For example, [1m-r [4m[22m"User:"[0m- 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 interactiveand conversational experience. However, the reverse prompt- doesn’t work when it ends with a space. To overcome this limi‐- tation, you can use the [1m--in‐prefix [22mflag to add a space or any+ doesn't work when it ends with a space. To overcome this limi‐+ tation, you can use the [1m--in-prefix [22mflag to add a space or anyother characters after the reverse prompt.[1m--color[0mEnable colorized output to differentiate visually distinguish‐ing between prompts, user input, and generated text.- [1m--no‐display‐prompt[22m, [1m--silent‐prompt[0m- Don’t echo the prompt itself to standard output.+ [1m--no-display-prompt[22m, [1m--silent-prompt[0m+ Don't echo the prompt itself to standard output.[1m--keep [4m[22mN[0mSpecifies number of tokens to keep from the initial prompt. The- default is ‐1 which means all tokens.+ default is -1 which means all tokens.- [1m--multiline‐input[0m+ [1m--multiline-input[0mAllows you to write or paste multiple lines without ending each- in ’\’.+ in '\'.- [1m--cont‐batching[0m- Enables continuous batching, a.k.a. dynamic batching. is ‐1+ [1m--cont-batching[0m+ Enables continuous batching, a.k.a. dynamic batching. is -1which means all tokens.[1m--embedding[0m@@ -699,8 +699,8 @@have a separate embeddings array computed for each line of textin the prompt. In multiline mode, each embedding array will beprinted on its own line to standard output, where individual- floats are separated by space. If both the [1m--multiline‐input[0m- and [1m--interactive [22mflags are passed, then a pretty‐printed sum‐+ floats are separated by space. If both the [1m--multiline-input[0m+ and [1m--interactive [22mflags are passed, then a pretty-printed sum‐mary of embeddings along with a cosine similarity matrix willbe printed to the terminal.@@ -728,12 +728,12 @@Default: 1- [1m-cb[22m, [1m--cont‐batching[0m+ [1m-cb[22m, [1m--cont-batching[0mEnable continuous batching (a.k.a dynamic batching).Default: disabled- [1m-spf [4m[22mFNAME[24m, [1m--system‐prompt‐file [4m[22mFNAME[0m+ [1m-spf [4m[22mFNAME[24m, [1m--system-prompt-file [4m[22mFNAME[0mSet a file to load a system prompt (initial prompt of allslots), this is useful for chat applications.@@ -749,15 +749,15 @@[1m--nobrowser[0mDo not attempt to open a web browser tab at startup.- [1m-gan [4m[22mN[24m, [1m--grp‐attn‐n [4m[22mN[0m+ [1m-gan [4m[22mN[24m, [1m--grp-attn-n [4m[22mN[0mSet the group attention factor to extend context size through- self‐extend. The default value is [4m1[24m which means disabled. This- flag is used together with [1m--grp‐attn‐w[22m.+ self-extend. The default value is [4m1[24m which means disabled. This+ flag is used together with [1m--grp-attn-w[22m.- [1m-gaw [4m[22mN[24m, [1m--grp‐attn‐w [4m[22mN[0m+ [1m-gaw [4m[22mN[24m, [1m--grp-attn-w [4m[22mN[0mSet the group attention width to extend context size through- self‐extend. The default value is [4m512[24m. This flag is used to‐- gether with [1m--grp‐attn‐n[22m.+ self-extend. The default value is [4m512[24m. This flag is used to‐+ gether with [1m--grp-attn-n[22m.[1mLOG OPTIONS[0mThe following log options are available:@@ -765,110 +765,110 @@[1m-ld [4m[22mLOGDIR[24m, [1m--logdir [4m[22mLOGDIR[0mPath under which to save YAML logs (no logging if unset)- [1m--log‐test[0m+ [1m--log-test[0mRun simple logging test- [1m--log‐disable[0m+ [1m--log-disable[0mDisable trace logs- [1m--log‐enable[0m+ [1m--log-enable[0mEnable trace logs- [1m--log‐file[0m+ [1m--log-file[0mSpecify a log filename (without extension)- [1m--log‐new[0m+ [1m--log-new[0mCreate a separate new log file on start. Each log file willhave unique name: [4m<name>.<ID>.log[0m- [1m--log‐append[0m- Don’t truncate the old log file.+ [1m--log-append[0m+ Don't truncate the old log file.[1mEXAMPLES[0m- 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-13Bweights: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-Instructweights 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 AIassistant Digital Athena which is a large language model trained on thesum 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/nullIf you wanted to write a script to rename all your image files, youcould 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 [1mllamafile [22mis running in thebackground in [1m--server [22mmode.- 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 jsonimport sysjson.dump(json.load(sys.stdin), sys.stdout, indent=2)@@ -888,12 +888,12 @@[1mPROTIP[0mThe [1m-ngl [4m[22m35[24m 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 betuned based on the system hardware and model architecture, in order toachieve optimal performance, and avoid compromising a shared display.[1mSEE ALSO[0m- [4mllamafile‐quantize[24m(1), [4mllamafile‐perplexity[24m(1), [4mllava‐quantize[24m(1),+ [4mllamafile-quantize[24m(1), [4mllamafile-perplexity[24m(1), [4mllava-quantize[24m(1),[4mzipalign[24m(1), [4munzip[24m(1)Mozilla Ocho January 1, 2024 [4mLLAMAFILE[24m(1)diff --git a/llama.cpp/main/main.cpp b/llama.cpp/main/main.cppindex 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 anyLOG("%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.cppindex 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.cppindex 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 ¶ms,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 != 1diff --git a/llamafile/server/BUILD.mk b/llamafile/server/BUILD.mkindex 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.1new file mode 100644index 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 1diff --git a/llamafile/server/main.1.asc b/llamafile/server/main.1.ascnew file mode 100644index 00000000..a9d44167--- /dev/null+++ b/llamafile/server/main.1.asc@@ -0,0 +1,144 @@+[4mLLAMAFILER[24m(1) General Commands Manual [4mLLAMAFILER[24m(1)++[1mNAME[0m+ llamafiler — fast reliable embedding server++[1mSYNOPSIS[0m+ [1mllamafiler -m [4m[22mmodel.gguf[24m [flags...]++[1mDESCRIPTION[0m+ [1mllamafiler [22mis 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.++[1mOPTIONS[0m+ The following options are available:++ [1m--version[0m+ Print version and exit.++ [1m-h[22m, [1m--help[0m+ Show help message and exit.++ [1m-m [4m[22mFNAME[24m, [1m--model [4m[22mFNAME[0m+ 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.++ [1m-l [4m[22mHOSTPORT[24m, [1m--listen [4m[22mHOSTPORT[0m+ 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.++ [1m-w [4m[22mN[24m, [1m--workers [4m[22mN[0m+ Number of HTTP client handling threads.++ [1m--trust [4m[22mCIDR[0m+ 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.++ [1m--ip-header [4m[22mSTR[0m+ 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.++ [1m--token-rate [4m[22mN[0m+ 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.++ [1m--token-burst [4m[22mN[0m+ 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.++ [1m--token-cidr [4m[22mN[0m+ 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.++ [1m--unsecure[0m+ 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.++ [1m-k [4m[22mN[24m, [1m--keepalive [4m[22mN[0m+ 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.++ [1m--http-obuf-size [4m[22mN[0m+ Size of HTTP output buffer size, in bytes. Default is 1048576.++ [1m--http-ibuf-size [4m[22mN[0m+ Size of HTTP input buffer size, in bytes. Default is 1048576.++[1mEXAMPLE[0m+ Here's an example of how you might start this server:++ [1mllamafiler -m all-MiniLM-L6-v2.F32.gguf[0m++ Here's how to send a tokenization request:++ [1mcurl -v http://127.0.0.1:8080/tokenize?prompt=hello+world[0m++ Here's how to send a embedding request:++ [1mcurl -v http://127.0.0.1:8080/embedding?content=hello+world[0m++[1mDOCUMENTATION[0m+ Read our Markdown documentation for additional help and tutorials. See+ llamafile/server/doc/index.md in the source repository on GitHub.++[1mSEE ALSO[0m+ [4mllamafile[24m(1), [4mwhisperfile[24m(1)++Mozilla Ocho August 17, 2024 [4mLLAMAFILER[24m(1)diff --git a/llamafile/server/main.cpp b/llamafile/server/main.cppindex 04f60443..e404ef54 100644--- a/llamafile/server/main.cpp+++ b/llamafile/server/main.cpp@@ -36,20 +36,35 @@ llama_model* g_model;intmain(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 configLoadZipArgs(&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 subsystemstime_init();tokenbucket_init();diff --git a/whisper.cpp/BUILD.mk b/whisper.cpp/BUILD.mkindex 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.cppo/$(MODE)/whisper.cpp: \- o/$(MODE)/whisper.cpp/server \o/$(MODE)/whisper.cpp/maindiff --git a/whisper.cpp/README.md b/whisper.cpp/README.mdindex 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.cppindex 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.mdnew file mode 100644index 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.mdnew file mode 100644index 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.mdnew file mode 100644index 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.mdnew file mode 100644index 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.mdnew file mode 100644index 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.hindex 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.1new file mode 100644index 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 1diff --git a/whisper.cpp/main.1.asc b/whisper.cpp/main.1.ascnew file mode 100644index 00000000..2c5f1c0c--- /dev/null+++ b/whisper.cpp/main.1.asc@@ -0,0 +1,66 @@+[4mWHISPERFILE[24m(1) General Commands Manual [4mWHISPERFILE[24m(1)++[1mNAME[0m+ whisperfile — speech to text engine++[1mSYNOPSIS[0m+ [1mwhisperfile [22m[flags...] [1m-m [4m[22mmodel.gguf[24m [1m-f [4m[22maudio.wav[0m+ [1mwhisperfile [22m[flags...] [1m--server -m [4m[22mmodel.gguf[0m++[1mDESCRIPTION[0m+ [1mwhisperfile [22mis 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.++[1mOPTIONS[0m+ The following options are available:++ [1m--version[0m+ Print version and exit.++ [1m-h[22m, [1m--help[0m+ Show help message and exit.++ [1m--server[0m+ Puts program in HTTP server mode.++ [1m-m [4m[22mFNAME[24m, [1m--model [4m[22mFNAME[0m+ Path of Whisper model weights. See https://hugging‐+ face.co/ggerganov/whisper.cpp++ [1m-f [4m[22mFNAME[24m, [1m--file [4m[22mFNAME[0m+ Path of WAV file to transcribe.++ [1m-tr[22m, [1m--translate[0m+ Translate audio into English text.++ [1m-ot [4m[22mN[24m, [1m--offset-t [4m[22mN[0m+ Time offset in milliseconds.++ [1m-d [4m[22mN[24m, [1m--duration [4m[22mN[0m+ Duration of audio to process in milliseconds.++ [1m-pc[22m, [1m--print-colors[0m+ 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++ [1m-t [4m[22mN[24m, [1m--threads [4m[22mN[0m+ 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.++[1mDOCUMENTATION[0m+ Read our Markdown documentation for additional help and tutorials. See+ whisper.cpp/doc/index.md in the llamafile source repository on GitHub.++[1mSEE ALSO[0m+ [4mllamafile[24m(1), [4mzipalign[24m(1), [4munzip[24m(1)++Mozilla Ocho August 17, 2024 [4mWHISPERFILE[24m(1)diff --git a/whisper.cpp/main.cpp b/whisper.cpp/main.cppindex 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 & paramselse 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 wstatic 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.cppindex 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, servefor (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, serveelse {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.cppindex 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)) {