@fugood/llama.node 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CMakeLists.txt +1 -10
- package/bin/darwin/arm64/llama-node.node +0 -0
- package/bin/darwin/x64/llama-node.node +0 -0
- package/bin/linux/arm64/llama-node.node +0 -0
- package/bin/linux/x64/llama-node.node +0 -0
- package/bin/linux-vulkan/arm64/llama-node.node +0 -0
- package/bin/linux-vulkan/x64/llama-node.node +0 -0
- package/bin/win32/arm64/llama-node.node +0 -0
- package/bin/win32/arm64/node.lib +0 -0
- package/bin/win32/x64/llama-node.node +0 -0
- package/bin/win32/x64/node.lib +0 -0
- package/bin/win32-vulkan/arm64/llama-node.node +0 -0
- package/bin/win32-vulkan/arm64/node.lib +0 -0
- package/bin/win32-vulkan/x64/llama-node.node +0 -0
- package/bin/win32-vulkan/x64/node.lib +0 -0
- package/package.json +6 -4
- package/src/LlamaCompletionWorker.cpp +6 -6
- package/src/LlamaContext.cpp +7 -9
- package/src/common.hpp +2 -1
- package/src/llama.cpp/.github/workflows/build.yml +98 -24
- package/src/llama.cpp/.github/workflows/close-issue.yml +5 -0
- package/src/llama.cpp/.github/workflows/docker.yml +43 -34
- package/src/llama.cpp/.github/workflows/nix-ci-aarch64.yml +7 -0
- package/src/llama.cpp/.github/workflows/nix-ci.yml +7 -0
- package/src/llama.cpp/.github/workflows/python-check-requirements.yml +2 -4
- package/src/llama.cpp/.github/workflows/python-type-check.yml +3 -1
- package/src/llama.cpp/.github/workflows/server.yml +7 -0
- package/src/llama.cpp/CMakeLists.txt +20 -8
- package/src/llama.cpp/common/CMakeLists.txt +12 -10
- package/src/llama.cpp/common/arg.cpp +2006 -0
- package/src/llama.cpp/common/arg.h +77 -0
- package/src/llama.cpp/common/common.cpp +496 -1632
- package/src/llama.cpp/common/common.h +161 -63
- package/src/llama.cpp/common/console.cpp +3 -0
- package/src/llama.cpp/common/log.cpp +401 -0
- package/src/llama.cpp/common/log.h +66 -698
- package/src/llama.cpp/common/ngram-cache.cpp +3 -0
- package/src/llama.cpp/common/sampling.cpp +348 -350
- package/src/llama.cpp/common/sampling.h +62 -139
- package/src/llama.cpp/common/stb_image.h +5990 -6398
- package/src/llama.cpp/common/train.cpp +2 -0
- package/src/llama.cpp/docs/build.md +36 -1
- package/src/llama.cpp/examples/CMakeLists.txt +0 -1
- package/src/llama.cpp/examples/baby-llama/baby-llama.cpp +1 -2
- package/src/llama.cpp/examples/batched/batched.cpp +39 -55
- package/src/llama.cpp/examples/batched-bench/batched-bench.cpp +34 -44
- package/src/llama.cpp/examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp +55 -52
- package/src/llama.cpp/examples/cvector-generator/cvector-generator.cpp +15 -15
- package/src/llama.cpp/examples/cvector-generator/pca.hpp +3 -13
- package/src/llama.cpp/examples/embedding/embedding.cpp +143 -87
- package/src/llama.cpp/examples/eval-callback/eval-callback.cpp +33 -33
- package/src/llama.cpp/examples/export-lora/export-lora.cpp +36 -35
- package/src/llama.cpp/examples/gbnf-validator/gbnf-validator.cpp +14 -39
- package/src/llama.cpp/examples/gen-docs/CMakeLists.txt +5 -0
- package/src/llama.cpp/examples/gen-docs/gen-docs.cpp +83 -0
- package/src/llama.cpp/examples/gguf-split/gguf-split.cpp +58 -39
- package/src/llama.cpp/examples/gritlm/gritlm.cpp +34 -27
- package/src/llama.cpp/examples/imatrix/imatrix.cpp +59 -62
- package/src/llama.cpp/examples/infill/infill.cpp +117 -132
- package/src/llama.cpp/examples/llama-bench/llama-bench.cpp +265 -58
- package/src/llama.cpp/examples/llama.android/llama/src/main/cpp/llama-android.cpp +29 -22
- package/src/llama.cpp/examples/llava/CMakeLists.txt +7 -0
- package/src/llama.cpp/examples/llava/clip.cpp +685 -150
- package/src/llama.cpp/examples/llava/clip.h +11 -2
- package/src/llama.cpp/examples/llava/llava-cli.cpp +47 -58
- package/src/llama.cpp/examples/llava/llava.cpp +110 -24
- package/src/llama.cpp/examples/llava/llava.h +2 -3
- package/src/llama.cpp/examples/llava/minicpmv-cli.cpp +323 -0
- package/src/llama.cpp/examples/llava/requirements.txt +1 -0
- package/src/llama.cpp/examples/lookahead/lookahead.cpp +42 -43
- package/src/llama.cpp/examples/lookup/lookup-create.cpp +10 -8
- package/src/llama.cpp/examples/lookup/lookup-stats.cpp +23 -22
- package/src/llama.cpp/examples/lookup/lookup.cpp +40 -43
- package/src/llama.cpp/examples/main/main.cpp +210 -262
- package/src/llama.cpp/examples/parallel/parallel.cpp +49 -49
- package/src/llama.cpp/examples/passkey/passkey.cpp +42 -50
- package/src/llama.cpp/examples/perplexity/perplexity.cpp +187 -200
- package/src/llama.cpp/examples/quantize/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/quantize/quantize.cpp +27 -9
- package/src/llama.cpp/examples/quantize-stats/quantize-stats.cpp +2 -3
- package/src/llama.cpp/examples/retrieval/retrieval.cpp +49 -44
- package/src/llama.cpp/examples/rpc/rpc-server.cpp +24 -1
- package/src/llama.cpp/examples/save-load-state/save-load-state.cpp +32 -35
- package/src/llama.cpp/examples/server/CMakeLists.txt +3 -5
- package/src/llama.cpp/examples/server/server.cpp +1027 -1073
- package/src/llama.cpp/examples/server/tests/requirements.txt +2 -1
- package/src/llama.cpp/examples/server/utils.hpp +107 -105
- package/src/llama.cpp/examples/simple/simple.cpp +35 -41
- package/src/llama.cpp/examples/speculative/speculative.cpp +129 -103
- package/src/llama.cpp/examples/sycl/run-llama2.sh +10 -19
- package/src/llama.cpp/examples/sycl/win-run-llama2.bat +1 -1
- package/src/llama.cpp/examples/tokenize/tokenize.cpp +25 -27
- package/src/llama.cpp/ggml/CMakeLists.txt +14 -3
- package/src/llama.cpp/ggml/include/ggml-alloc.h +3 -3
- package/src/llama.cpp/ggml/include/ggml-backend.h +145 -60
- package/src/llama.cpp/ggml/include/ggml-blas.h +3 -3
- package/src/llama.cpp/ggml/include/ggml-cann.h +15 -19
- package/src/llama.cpp/ggml/include/ggml-cuda.h +16 -16
- package/src/llama.cpp/ggml/include/ggml-metal.h +5 -8
- package/src/llama.cpp/ggml/include/ggml-rpc.h +5 -5
- package/src/llama.cpp/ggml/include/ggml-sycl.h +8 -8
- package/src/llama.cpp/ggml/include/ggml-vulkan.h +7 -7
- package/src/llama.cpp/ggml/include/ggml.h +293 -186
- package/src/llama.cpp/ggml/src/CMakeLists.txt +86 -44
- package/src/llama.cpp/ggml/src/ggml-aarch64.c +2135 -1119
- package/src/llama.cpp/ggml/src/ggml-alloc.c +6 -0
- package/src/llama.cpp/ggml/src/ggml-backend-impl.h +152 -70
- package/src/llama.cpp/ggml/src/{ggml-backend.c → ggml-backend.cpp} +606 -286
- package/src/llama.cpp/ggml/src/ggml-blas.cpp +9 -10
- package/src/llama.cpp/ggml/src/ggml-cann/acl_tensor.cpp +4 -27
- package/src/llama.cpp/ggml/src/ggml-cann/acl_tensor.h +32 -4
- package/src/llama.cpp/ggml/src/ggml-cann/aclnn_ops.cpp +179 -41
- package/src/llama.cpp/ggml/src/ggml-cann/common.h +1 -0
- package/src/llama.cpp/ggml/src/ggml-cann/kernels/CMakeLists.txt +2 -1
- package/src/llama.cpp/ggml/src/ggml-cann/kernels/ascendc_kernels.h +2 -0
- package/src/llama.cpp/ggml/src/ggml-cann/kernels/quantize_float_to_q4_0.cpp +278 -0
- package/src/llama.cpp/ggml/src/ggml-cann.cpp +215 -216
- package/src/llama.cpp/ggml/src/ggml-common.h +20 -0
- package/src/llama.cpp/ggml/src/ggml-cpu-impl.h +614 -0
- package/src/llama.cpp/ggml/src/ggml-cuda/vendors/cuda.h +14 -0
- package/src/llama.cpp/ggml/src/ggml-cuda/vendors/hip.h +178 -0
- package/src/llama.cpp/ggml/src/ggml-cuda/vendors/musa.h +134 -0
- package/src/llama.cpp/ggml/src/ggml-impl.h +49 -603
- package/src/llama.cpp/ggml/src/ggml-kompute.cpp +4 -24
- package/src/llama.cpp/ggml/src/ggml-quants.c +972 -92
- package/src/llama.cpp/ggml/src/ggml-quants.h +15 -0
- package/src/llama.cpp/ggml/src/ggml-rpc.cpp +116 -66
- package/src/llama.cpp/ggml/src/ggml-sycl/backend.hpp +3 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/common.cpp +11 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/common.hpp +52 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/conv.cpp +99 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/conv.hpp +21 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/convert.cpp +57 -57
- package/src/llama.cpp/ggml/src/ggml-sycl/convert.hpp +1 -1
- package/src/llama.cpp/ggml/src/ggml-sycl/dequantize.hpp +106 -106
- package/src/llama.cpp/ggml/src/ggml-sycl/dmmv.cpp +4 -4
- package/src/llama.cpp/ggml/src/ggml-sycl/dpct/helper.hpp +16 -3
- package/src/llama.cpp/ggml/src/ggml-sycl/gemm.hpp +101 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/im2col.cpp +125 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/im2col.hpp +23 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/mmvq.cpp +1 -1
- package/src/llama.cpp/ggml/src/ggml-sycl/norm.cpp +6 -3
- package/src/llama.cpp/ggml/src/ggml-sycl/presets.hpp +2 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/rope.cpp +1 -1
- package/src/llama.cpp/ggml/src/ggml-sycl/tsembd.cpp +71 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/tsembd.hpp +21 -0
- package/src/llama.cpp/ggml/src/ggml-sycl.cpp +97 -169
- package/src/llama.cpp/ggml/src/ggml-vulkan.cpp +1508 -1124
- package/src/llama.cpp/ggml/src/ggml.c +3001 -1647
- package/src/llama.cpp/ggml/src/llamafile/sgemm.cpp +192 -0
- package/src/llama.cpp/ggml/src/vulkan-shaders/CMakeLists.txt +2 -0
- package/src/llama.cpp/ggml/src/vulkan-shaders/vulkan-shaders-gen.cpp +88 -40
- package/src/llama.cpp/include/llama.h +241 -264
- package/src/llama.cpp/models/ggml-vocab-chameleon.gguf.inp +112 -0
- package/src/llama.cpp/models/ggml-vocab-chameleon.gguf.out +46 -0
- package/src/llama.cpp/requirements/requirements-convert_legacy_llama.txt +1 -1
- package/src/llama.cpp/src/llama-grammar.cpp +721 -122
- package/src/llama.cpp/src/llama-grammar.h +120 -15
- package/src/llama.cpp/src/llama-impl.h +156 -1
- package/src/llama.cpp/src/llama-sampling.cpp +1375 -303
- package/src/llama.cpp/src/llama-sampling.h +20 -47
- package/src/llama.cpp/src/llama-vocab.cpp +343 -120
- package/src/llama.cpp/src/llama-vocab.h +33 -17
- package/src/llama.cpp/src/llama.cpp +4247 -1525
- package/src/llama.cpp/src/unicode-data.cpp +6 -4
- package/src/llama.cpp/src/unicode-data.h +4 -4
- package/src/llama.cpp/src/unicode.cpp +15 -7
- package/src/llama.cpp/tests/CMakeLists.txt +3 -0
- package/src/llama.cpp/tests/test-arg-parser.cpp +131 -0
- package/src/llama.cpp/tests/test-backend-ops.cpp +1592 -289
- package/src/llama.cpp/tests/test-barrier.cpp +93 -0
- package/src/llama.cpp/tests/test-grad0.cpp +187 -70
- package/src/llama.cpp/tests/test-grammar-integration.cpp +23 -38
- package/src/llama.cpp/tests/test-grammar-parser.cpp +6 -4
- package/src/llama.cpp/tests/test-json-schema-to-grammar.cpp +6 -4
- package/src/llama.cpp/tests/test-llama-grammar.cpp +9 -8
- package/src/llama.cpp/tests/test-log.cpp +39 -0
- package/src/llama.cpp/tests/test-quantize-fns.cpp +6 -0
- package/src/llama.cpp/tests/test-rope.cpp +1 -1
- package/src/llama.cpp/tests/test-sampling.cpp +157 -98
- package/src/llama.cpp/tests/test-tokenizer-0.cpp +55 -35
- package/patches/llama.patch +0 -22
- package/src/llama.cpp/.github/workflows/bench.yml +0 -310
- package/src/llama.cpp/common/grammar-parser.cpp +0 -536
- package/src/llama.cpp/common/grammar-parser.h +0 -29
- package/src/llama.cpp/examples/benchmark/CMakeLists.txt +0 -6
- package/src/llama.cpp/examples/benchmark/benchmark-matmult.cpp +0 -275
|
@@ -0,0 +1,2006 @@
|
|
|
1
|
+
#include "arg.h"
|
|
2
|
+
|
|
3
|
+
#include "log.h"
|
|
4
|
+
#include "sampling.h"
|
|
5
|
+
|
|
6
|
+
#include <algorithm>
|
|
7
|
+
#include <climits>
|
|
8
|
+
#include <cstdarg>
|
|
9
|
+
#include <fstream>
|
|
10
|
+
#include <regex>
|
|
11
|
+
#include <set>
|
|
12
|
+
#include <string>
|
|
13
|
+
#include <thread>
|
|
14
|
+
#include <vector>
|
|
15
|
+
|
|
16
|
+
#include "json-schema-to-grammar.h"
|
|
17
|
+
|
|
18
|
+
using json = nlohmann::ordered_json;
|
|
19
|
+
|
|
20
|
+
llama_arg & llama_arg::set_examples(std::initializer_list<enum llama_example> examples) {
|
|
21
|
+
this->examples = std::move(examples);
|
|
22
|
+
return *this;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
llama_arg & llama_arg::set_env(const char * env) {
|
|
26
|
+
help = help + "\n(env: " + env + ")";
|
|
27
|
+
this->env = env;
|
|
28
|
+
return *this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
llama_arg & llama_arg::set_sparam() {
|
|
32
|
+
is_sparam = true;
|
|
33
|
+
return *this;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
bool llama_arg::in_example(enum llama_example ex) {
|
|
37
|
+
return examples.find(ex) != examples.end();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
bool llama_arg::get_value_from_env(std::string & output) {
|
|
41
|
+
if (env == nullptr) return false;
|
|
42
|
+
char * value = std::getenv(env);
|
|
43
|
+
if (value) {
|
|
44
|
+
output = value;
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
bool llama_arg::has_value_from_env() {
|
|
51
|
+
return env != nullptr && std::getenv(env);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static std::vector<std::string> break_str_into_lines(std::string input, size_t max_char_per_line) {
|
|
55
|
+
std::vector<std::string> result;
|
|
56
|
+
std::istringstream iss(input);
|
|
57
|
+
std::string line;
|
|
58
|
+
auto add_line = [&](const std::string& l) {
|
|
59
|
+
if (l.length() <= max_char_per_line) {
|
|
60
|
+
result.push_back(l);
|
|
61
|
+
} else {
|
|
62
|
+
std::istringstream line_stream(l);
|
|
63
|
+
std::string word, current_line;
|
|
64
|
+
while (line_stream >> word) {
|
|
65
|
+
if (current_line.length() + !current_line.empty() + word.length() > max_char_per_line) {
|
|
66
|
+
if (!current_line.empty()) result.push_back(current_line);
|
|
67
|
+
current_line = word;
|
|
68
|
+
} else {
|
|
69
|
+
current_line += (!current_line.empty() ? " " : "") + word;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (!current_line.empty()) result.push_back(current_line);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
while (std::getline(iss, line)) {
|
|
76
|
+
add_line(line);
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
std::string llama_arg::to_string() {
|
|
82
|
+
// params for printing to console
|
|
83
|
+
const static int n_leading_spaces = 40;
|
|
84
|
+
const static int n_char_per_line_help = 70; // TODO: detect this based on current console
|
|
85
|
+
std::string leading_spaces(n_leading_spaces, ' ');
|
|
86
|
+
|
|
87
|
+
std::ostringstream ss;
|
|
88
|
+
for (const auto arg : args) {
|
|
89
|
+
if (arg == args.front()) {
|
|
90
|
+
if (args.size() == 1) {
|
|
91
|
+
ss << arg;
|
|
92
|
+
} else {
|
|
93
|
+
// first arg is usually abbreviation, we need padding to make it more beautiful
|
|
94
|
+
auto tmp = std::string(arg) + ", ";
|
|
95
|
+
auto spaces = std::string(std::max(0, 7 - (int)tmp.size()), ' ');
|
|
96
|
+
ss << tmp << spaces;
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
ss << arg << (arg != args.back() ? ", " : "");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (value_hint) ss << " " << value_hint;
|
|
103
|
+
if (value_hint_2) ss << " " << value_hint_2;
|
|
104
|
+
if (ss.tellp() > n_leading_spaces - 3) {
|
|
105
|
+
// current line is too long, add new line
|
|
106
|
+
ss << "\n" << leading_spaces;
|
|
107
|
+
} else {
|
|
108
|
+
// padding between arg and help, same line
|
|
109
|
+
ss << std::string(leading_spaces.size() - ss.tellp(), ' ');
|
|
110
|
+
}
|
|
111
|
+
const auto help_lines = break_str_into_lines(help, n_char_per_line_help);
|
|
112
|
+
for (const auto & line : help_lines) {
|
|
113
|
+
ss << (&line == &help_lines.front() ? "" : leading_spaces) << line << "\n";
|
|
114
|
+
}
|
|
115
|
+
return ss.str();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
//
|
|
119
|
+
// utils
|
|
120
|
+
//
|
|
121
|
+
|
|
122
|
+
#ifdef __GNUC__
|
|
123
|
+
#ifdef __MINGW32__
|
|
124
|
+
#define LLAMA_COMMON_ATTRIBUTE_FORMAT(...) __attribute__((format(gnu_printf, __VA_ARGS__)))
|
|
125
|
+
#else
|
|
126
|
+
#define LLAMA_COMMON_ATTRIBUTE_FORMAT(...) __attribute__((format(printf, __VA_ARGS__)))
|
|
127
|
+
#endif
|
|
128
|
+
#else
|
|
129
|
+
#define LLAMA_COMMON_ATTRIBUTE_FORMAT(...)
|
|
130
|
+
#endif
|
|
131
|
+
|
|
132
|
+
LLAMA_COMMON_ATTRIBUTE_FORMAT(1, 2)
|
|
133
|
+
static std::string format(const char * fmt, ...) {
|
|
134
|
+
va_list ap;
|
|
135
|
+
va_list ap2;
|
|
136
|
+
va_start(ap, fmt);
|
|
137
|
+
va_copy(ap2, ap);
|
|
138
|
+
int size = vsnprintf(NULL, 0, fmt, ap);
|
|
139
|
+
GGML_ASSERT(size >= 0 && size < INT_MAX); // NOLINT
|
|
140
|
+
std::vector<char> buf(size + 1);
|
|
141
|
+
int size2 = vsnprintf(buf.data(), size + 1, fmt, ap2);
|
|
142
|
+
GGML_ASSERT(size2 == size);
|
|
143
|
+
va_end(ap2);
|
|
144
|
+
va_end(ap);
|
|
145
|
+
return std::string(buf.data(), size);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
static void gpt_params_handle_model_default(gpt_params & params) {
|
|
149
|
+
if (!params.hf_repo.empty()) {
|
|
150
|
+
// short-hand to avoid specifying --hf-file -> default it to --model
|
|
151
|
+
if (params.hf_file.empty()) {
|
|
152
|
+
if (params.model.empty()) {
|
|
153
|
+
throw std::invalid_argument("error: --hf-repo requires either --hf-file or --model\n");
|
|
154
|
+
}
|
|
155
|
+
params.hf_file = params.model;
|
|
156
|
+
} else if (params.model.empty()) {
|
|
157
|
+
params.model = fs_get_cache_file(string_split(params.hf_file, '/').back());
|
|
158
|
+
}
|
|
159
|
+
} else if (!params.model_url.empty()) {
|
|
160
|
+
if (params.model.empty()) {
|
|
161
|
+
auto f = string_split(params.model_url, '#').front();
|
|
162
|
+
f = string_split(f, '?').front();
|
|
163
|
+
params.model = fs_get_cache_file(string_split(f, '/').back());
|
|
164
|
+
}
|
|
165
|
+
} else if (params.model.empty()) {
|
|
166
|
+
params.model = DEFAULT_MODEL_PATH;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
//
|
|
171
|
+
// CLI argument parsing functions
|
|
172
|
+
//
|
|
173
|
+
|
|
174
|
+
static bool gpt_params_parse_ex(int argc, char ** argv, gpt_params_context & ctx_arg) {
|
|
175
|
+
std::string arg;
|
|
176
|
+
const std::string arg_prefix = "--";
|
|
177
|
+
gpt_params & params = ctx_arg.params;
|
|
178
|
+
|
|
179
|
+
std::unordered_map<std::string, llama_arg *> arg_to_options;
|
|
180
|
+
for (auto & opt : ctx_arg.options) {
|
|
181
|
+
for (const auto & arg : opt.args) {
|
|
182
|
+
arg_to_options[arg] = &opt;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// handle environment variables
|
|
187
|
+
for (auto & opt : ctx_arg.options) {
|
|
188
|
+
std::string value;
|
|
189
|
+
if (opt.get_value_from_env(value)) {
|
|
190
|
+
try {
|
|
191
|
+
if (opt.handler_void && (value == "1" || value == "true")) {
|
|
192
|
+
opt.handler_void(params);
|
|
193
|
+
}
|
|
194
|
+
if (opt.handler_int) {
|
|
195
|
+
opt.handler_int(params, std::stoi(value));
|
|
196
|
+
}
|
|
197
|
+
if (opt.handler_string) {
|
|
198
|
+
opt.handler_string(params, value);
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
} catch (std::exception & e) {
|
|
202
|
+
throw std::invalid_argument(format(
|
|
203
|
+
"error while handling environment variable \"%s\": %s\n\n", opt.env, e.what()));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// handle command line arguments
|
|
209
|
+
auto check_arg = [&](int i) {
|
|
210
|
+
if (i+1 >= argc) {
|
|
211
|
+
throw std::invalid_argument("expected value for argument");
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
for (int i = 1; i < argc; i++) {
|
|
216
|
+
const std::string arg_prefix = "--";
|
|
217
|
+
|
|
218
|
+
std::string arg = argv[i];
|
|
219
|
+
if (arg.compare(0, arg_prefix.size(), arg_prefix) == 0) {
|
|
220
|
+
std::replace(arg.begin(), arg.end(), '_', '-');
|
|
221
|
+
}
|
|
222
|
+
if (arg_to_options.find(arg) == arg_to_options.end()) {
|
|
223
|
+
throw std::invalid_argument(format("error: invalid argument: %s", arg.c_str()));
|
|
224
|
+
}
|
|
225
|
+
auto opt = *arg_to_options[arg];
|
|
226
|
+
if (opt.has_value_from_env()) {
|
|
227
|
+
fprintf(stderr, "warn: %s environment variable is set, but will be overwritten by command line argument %s\n", opt.env, arg.c_str());
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
if (opt.handler_void) {
|
|
231
|
+
opt.handler_void(params);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// arg with single value
|
|
236
|
+
check_arg(i);
|
|
237
|
+
std::string val = argv[++i];
|
|
238
|
+
if (opt.handler_int) {
|
|
239
|
+
opt.handler_int(params, std::stoi(val));
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
if (opt.handler_string) {
|
|
243
|
+
opt.handler_string(params, val);
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// arg with 2 values
|
|
248
|
+
check_arg(i);
|
|
249
|
+
std::string val2 = argv[++i];
|
|
250
|
+
if (opt.handler_str_str) {
|
|
251
|
+
opt.handler_str_str(params, val, val2);
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
} catch (std::exception & e) {
|
|
255
|
+
throw std::invalid_argument(format(
|
|
256
|
+
"error while handling argument \"%s\": %s\n\n"
|
|
257
|
+
"usage:\n%s\n\nto show complete usage, run with -h",
|
|
258
|
+
arg.c_str(), e.what(), arg_to_options[arg]->to_string().c_str()));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
postprocess_cpu_params(params.cpuparams, nullptr);
|
|
263
|
+
postprocess_cpu_params(params.cpuparams_batch, ¶ms.cpuparams);
|
|
264
|
+
postprocess_cpu_params(params.draft_cpuparams, ¶ms.cpuparams);
|
|
265
|
+
postprocess_cpu_params(params.draft_cpuparams_batch, ¶ms.cpuparams_batch);
|
|
266
|
+
|
|
267
|
+
if (params.prompt_cache_all && (params.interactive || params.interactive_first)) {
|
|
268
|
+
throw std::invalid_argument("error: --prompt-cache-all not supported in interactive mode yet\n");
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
gpt_params_handle_model_default(params);
|
|
272
|
+
|
|
273
|
+
if (params.escape) {
|
|
274
|
+
string_process_escapes(params.prompt);
|
|
275
|
+
string_process_escapes(params.input_prefix);
|
|
276
|
+
string_process_escapes(params.input_suffix);
|
|
277
|
+
for (auto & antiprompt : params.antiprompt) {
|
|
278
|
+
string_process_escapes(antiprompt);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (!params.kv_overrides.empty()) {
|
|
283
|
+
params.kv_overrides.emplace_back();
|
|
284
|
+
params.kv_overrides.back().key[0] = 0;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (params.reranking && params.embedding) {
|
|
288
|
+
throw std::invalid_argument("error: either --embedding or --reranking can be specified, but not both");
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
static void gpt_params_print_usage(gpt_params_context & ctx_arg) {
|
|
295
|
+
auto print_options = [](std::vector<llama_arg *> & options) {
|
|
296
|
+
for (llama_arg * opt : options) {
|
|
297
|
+
printf("%s", opt->to_string().c_str());
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
std::vector<llama_arg *> common_options;
|
|
302
|
+
std::vector<llama_arg *> sparam_options;
|
|
303
|
+
std::vector<llama_arg *> specific_options;
|
|
304
|
+
for (auto & opt : ctx_arg.options) {
|
|
305
|
+
// in case multiple LLAMA_EXAMPLE_* are set, we prioritize the LLAMA_EXAMPLE_* matching current example
|
|
306
|
+
if (opt.is_sparam) {
|
|
307
|
+
sparam_options.push_back(&opt);
|
|
308
|
+
} else if (opt.in_example(ctx_arg.ex)) {
|
|
309
|
+
specific_options.push_back(&opt);
|
|
310
|
+
} else {
|
|
311
|
+
common_options.push_back(&opt);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
printf("----- common params -----\n\n");
|
|
315
|
+
print_options(common_options);
|
|
316
|
+
printf("\n\n----- sampling params -----\n\n");
|
|
317
|
+
print_options(sparam_options);
|
|
318
|
+
// TODO: maybe convert enum llama_example to string
|
|
319
|
+
printf("\n\n----- example-specific params -----\n\n");
|
|
320
|
+
print_options(specific_options);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
bool gpt_params_parse(int argc, char ** argv, gpt_params & params, llama_example ex, void(*print_usage)(int, char **)) {
|
|
324
|
+
auto ctx_arg = gpt_params_parser_init(params, ex, print_usage);
|
|
325
|
+
const gpt_params params_org = ctx_arg.params; // the example can modify the default params
|
|
326
|
+
|
|
327
|
+
try {
|
|
328
|
+
if (!gpt_params_parse_ex(argc, argv, ctx_arg)) {
|
|
329
|
+
ctx_arg.params = params_org;
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
if (ctx_arg.params.usage) {
|
|
333
|
+
gpt_params_print_usage(ctx_arg);
|
|
334
|
+
if (ctx_arg.print_usage) {
|
|
335
|
+
ctx_arg.print_usage(argc, argv);
|
|
336
|
+
}
|
|
337
|
+
exit(0);
|
|
338
|
+
}
|
|
339
|
+
} catch (const std::invalid_argument & ex) {
|
|
340
|
+
fprintf(stderr, "%s\n", ex.what());
|
|
341
|
+
ctx_arg.params = params_org;
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
return true;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
gpt_params_context gpt_params_parser_init(gpt_params & params, llama_example ex, void(*print_usage)(int, char **)) {
|
|
349
|
+
gpt_params_context ctx_arg(params);
|
|
350
|
+
ctx_arg.print_usage = print_usage;
|
|
351
|
+
ctx_arg.ex = ex;
|
|
352
|
+
|
|
353
|
+
std::string sampler_type_chars;
|
|
354
|
+
std::string sampler_type_names;
|
|
355
|
+
for (const auto & sampler : params.sparams.samplers) {
|
|
356
|
+
sampler_type_chars += gpt_sampler_type_to_chr(sampler);
|
|
357
|
+
sampler_type_names += gpt_sampler_type_to_str(sampler) + ";";
|
|
358
|
+
}
|
|
359
|
+
sampler_type_names.pop_back();
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* filter options by example
|
|
364
|
+
* rules:
|
|
365
|
+
* - all examples inherit options from LLAMA_EXAMPLE_COMMON
|
|
366
|
+
* - if LLAMA_EXAMPLE_* is set (other than COMMON), we only show the option in the corresponding example
|
|
367
|
+
* - if both {LLAMA_EXAMPLE_COMMON, LLAMA_EXAMPLE_*,} are set, we will prioritize the LLAMA_EXAMPLE_* matching current example
|
|
368
|
+
*/
|
|
369
|
+
auto add_opt = [&](llama_arg arg) {
|
|
370
|
+
if (arg.in_example(ex) || arg.in_example(LLAMA_EXAMPLE_COMMON)) {
|
|
371
|
+
ctx_arg.options.push_back(std::move(arg));
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
add_opt(llama_arg(
|
|
377
|
+
{"-h", "--help", "--usage"},
|
|
378
|
+
"print usage and exit",
|
|
379
|
+
[](gpt_params & params) {
|
|
380
|
+
params.usage = true;
|
|
381
|
+
}
|
|
382
|
+
));
|
|
383
|
+
add_opt(llama_arg(
|
|
384
|
+
{"--version"},
|
|
385
|
+
"show version and build info",
|
|
386
|
+
[](gpt_params &) {
|
|
387
|
+
fprintf(stderr, "version: %d (%s)\n", LLAMA_BUILD_NUMBER, LLAMA_COMMIT);
|
|
388
|
+
fprintf(stderr, "built with %s for %s\n", LLAMA_COMPILER, LLAMA_BUILD_TARGET);
|
|
389
|
+
exit(0);
|
|
390
|
+
}
|
|
391
|
+
));
|
|
392
|
+
add_opt(llama_arg(
|
|
393
|
+
{"--verbose-prompt"},
|
|
394
|
+
format("print a verbose prompt before generation (default: %s)", params.verbose_prompt ? "true" : "false"),
|
|
395
|
+
[](gpt_params & params) {
|
|
396
|
+
params.verbose_prompt = true;
|
|
397
|
+
}
|
|
398
|
+
));
|
|
399
|
+
add_opt(llama_arg(
|
|
400
|
+
{"--no-display-prompt"},
|
|
401
|
+
format("don't print prompt at generation (default: %s)", !params.display_prompt ? "true" : "false"),
|
|
402
|
+
[](gpt_params & params) {
|
|
403
|
+
params.display_prompt = false;
|
|
404
|
+
}
|
|
405
|
+
).set_examples({LLAMA_EXAMPLE_MAIN}));
|
|
406
|
+
add_opt(llama_arg(
|
|
407
|
+
{"-co", "--color"},
|
|
408
|
+
format("colorise output to distinguish prompt and user input from generations (default: %s)", params.use_color ? "true" : "false"),
|
|
409
|
+
[](gpt_params & params) {
|
|
410
|
+
params.use_color = true;
|
|
411
|
+
}
|
|
412
|
+
).set_examples({LLAMA_EXAMPLE_MAIN, LLAMA_EXAMPLE_INFILL, LLAMA_EXAMPLE_SPECULATIVE, LLAMA_EXAMPLE_LOOKUP}));
|
|
413
|
+
add_opt(llama_arg(
|
|
414
|
+
{"-t", "--threads"}, "N",
|
|
415
|
+
format("number of threads to use during generation (default: %d)", params.cpuparams.n_threads),
|
|
416
|
+
[](gpt_params & params, int value) {
|
|
417
|
+
params.cpuparams.n_threads = value;
|
|
418
|
+
if (params.cpuparams.n_threads <= 0) {
|
|
419
|
+
params.cpuparams.n_threads = std::thread::hardware_concurrency();
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
).set_env("LLAMA_ARG_THREADS"));
|
|
423
|
+
add_opt(llama_arg(
|
|
424
|
+
{"-tb", "--threads-batch"}, "N",
|
|
425
|
+
"number of threads to use during batch and prompt processing (default: same as --threads)",
|
|
426
|
+
[](gpt_params & params, int value) {
|
|
427
|
+
params.cpuparams_batch.n_threads = value;
|
|
428
|
+
if (params.cpuparams_batch.n_threads <= 0) {
|
|
429
|
+
params.cpuparams_batch.n_threads = std::thread::hardware_concurrency();
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
));
|
|
433
|
+
add_opt(llama_arg(
|
|
434
|
+
{"-td", "--threads-draft"}, "N",
|
|
435
|
+
"number of threads to use during generation (default: same as --threads)",
|
|
436
|
+
[](gpt_params & params, int value) {
|
|
437
|
+
params.draft_cpuparams.n_threads = value;
|
|
438
|
+
if (params.draft_cpuparams.n_threads <= 0) {
|
|
439
|
+
params.draft_cpuparams.n_threads = std::thread::hardware_concurrency();
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
|
|
443
|
+
add_opt(llama_arg(
|
|
444
|
+
{"-tbd", "--threads-batch-draft"}, "N",
|
|
445
|
+
"number of threads to use during batch and prompt processing (default: same as --threads-draft)",
|
|
446
|
+
[](gpt_params & params, int value) {
|
|
447
|
+
params.draft_cpuparams_batch.n_threads = value;
|
|
448
|
+
if (params.draft_cpuparams_batch.n_threads <= 0) {
|
|
449
|
+
params.draft_cpuparams_batch.n_threads = std::thread::hardware_concurrency();
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
|
|
453
|
+
add_opt(llama_arg(
|
|
454
|
+
{"-C", "--cpu-mask"}, "M",
|
|
455
|
+
"CPU affinity mask: arbitrarily long hex. Complements cpu-range (default: \"\")",
|
|
456
|
+
[](gpt_params & params, const std::string & mask) {
|
|
457
|
+
params.cpuparams.mask_valid = true;
|
|
458
|
+
if (!parse_cpu_mask(mask, params.cpuparams.cpumask)) {
|
|
459
|
+
throw std::invalid_argument("invalid cpumask");
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
));
|
|
463
|
+
add_opt(llama_arg(
|
|
464
|
+
{"-Cr", "--cpu-range"}, "lo-hi",
|
|
465
|
+
"range of CPUs for affinity. Complements --cpu-mask",
|
|
466
|
+
[](gpt_params & params, const std::string & range) {
|
|
467
|
+
params.cpuparams.mask_valid = true;
|
|
468
|
+
if (!parse_cpu_range(range, params.cpuparams.cpumask)) {
|
|
469
|
+
throw std::invalid_argument("invalid range");
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
));
|
|
473
|
+
add_opt(llama_arg(
|
|
474
|
+
{"--cpu-strict"}, "<0|1>",
|
|
475
|
+
format("use strict CPU placement (default: %u)\n", (unsigned) params.cpuparams.strict_cpu),
|
|
476
|
+
[](gpt_params & params, const std::string & value) {
|
|
477
|
+
params.cpuparams.strict_cpu = std::stoul(value);
|
|
478
|
+
}
|
|
479
|
+
));
|
|
480
|
+
add_opt(llama_arg(
|
|
481
|
+
{"--prio"}, "N",
|
|
482
|
+
format("set process/thread priority : 0-normal, 1-medium, 2-high, 3-realtime (default: %d)\n", params.cpuparams.priority),
|
|
483
|
+
[](gpt_params & params, int prio) {
|
|
484
|
+
if (prio < 0 || prio > 3) {
|
|
485
|
+
throw std::invalid_argument("invalid value");
|
|
486
|
+
}
|
|
487
|
+
params.cpuparams.priority = (enum ggml_sched_priority) prio;
|
|
488
|
+
}
|
|
489
|
+
));
|
|
490
|
+
add_opt(llama_arg(
|
|
491
|
+
{"--poll"}, "<0...100>",
|
|
492
|
+
format("use polling level to wait for work (0 - no polling, default: %u)\n", (unsigned) params.cpuparams.poll),
|
|
493
|
+
[](gpt_params & params, const std::string & value) {
|
|
494
|
+
params.cpuparams.poll = std::stoul(value);
|
|
495
|
+
}
|
|
496
|
+
));
|
|
497
|
+
add_opt(llama_arg(
|
|
498
|
+
{"-Cb", "--cpu-mask-batch"}, "M",
|
|
499
|
+
"CPU affinity mask: arbitrarily long hex. Complements cpu-range-batch (default: same as --cpu-mask)",
|
|
500
|
+
[](gpt_params & params, const std::string & mask) {
|
|
501
|
+
params.cpuparams_batch.mask_valid = true;
|
|
502
|
+
if (!parse_cpu_mask(mask, params.cpuparams_batch.cpumask)) {
|
|
503
|
+
throw std::invalid_argument("invalid cpumask");
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
));
|
|
507
|
+
add_opt(llama_arg(
|
|
508
|
+
{"-Crb", "--cpu-range-batch"}, "lo-hi",
|
|
509
|
+
"ranges of CPUs for affinity. Complements --cpu-mask-batch",
|
|
510
|
+
[](gpt_params & params, const std::string & range) {
|
|
511
|
+
params.cpuparams_batch.mask_valid = true;
|
|
512
|
+
if (!parse_cpu_range(range, params.cpuparams_batch.cpumask)) {
|
|
513
|
+
throw std::invalid_argument("invalid range");
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
));
|
|
517
|
+
add_opt(llama_arg(
|
|
518
|
+
{"--cpu-strict-batch"}, "<0|1>",
|
|
519
|
+
"use strict CPU placement (default: same as --cpu-strict)",
|
|
520
|
+
[](gpt_params & params, int value) {
|
|
521
|
+
params.cpuparams_batch.strict_cpu = value;
|
|
522
|
+
}
|
|
523
|
+
));
|
|
524
|
+
add_opt(llama_arg(
|
|
525
|
+
{"--prio-batch"}, "N",
|
|
526
|
+
format("set process/thread priority : 0-normal, 1-medium, 2-high, 3-realtime (default: %d)\n", params.cpuparams_batch.priority),
|
|
527
|
+
[](gpt_params & params, int prio) {
|
|
528
|
+
if (prio < 0 || prio > 3) {
|
|
529
|
+
throw std::invalid_argument("invalid value");
|
|
530
|
+
}
|
|
531
|
+
params.cpuparams_batch.priority = (enum ggml_sched_priority) prio;
|
|
532
|
+
}
|
|
533
|
+
));
|
|
534
|
+
add_opt(llama_arg(
|
|
535
|
+
{"--poll-batch"}, "<0|1>",
|
|
536
|
+
"use polling to wait for work (default: same as --poll)",
|
|
537
|
+
[](gpt_params & params, int value) {
|
|
538
|
+
params.cpuparams_batch.poll = value;
|
|
539
|
+
}
|
|
540
|
+
));
|
|
541
|
+
add_opt(llama_arg(
|
|
542
|
+
{"-Cd", "--cpu-mask-draft"}, "M",
|
|
543
|
+
"Draft model CPU affinity mask. Complements cpu-range-draft (default: same as --cpu-mask)",
|
|
544
|
+
[](gpt_params & params, const std::string & mask) {
|
|
545
|
+
params.draft_cpuparams.mask_valid = true;
|
|
546
|
+
if (!parse_cpu_mask(mask, params.draft_cpuparams.cpumask)) {
|
|
547
|
+
throw std::invalid_argument("invalid cpumask");
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
|
|
551
|
+
add_opt(llama_arg(
|
|
552
|
+
{"-Crd", "--cpu-range-draft"}, "lo-hi",
|
|
553
|
+
"Ranges of CPUs for affinity. Complements --cpu-mask-draft",
|
|
554
|
+
[](gpt_params & params, const std::string & range) {
|
|
555
|
+
params.draft_cpuparams.mask_valid = true;
|
|
556
|
+
if (!parse_cpu_range(range, params.draft_cpuparams.cpumask)) {
|
|
557
|
+
throw std::invalid_argument("invalid range");
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
|
|
561
|
+
add_opt(llama_arg(
|
|
562
|
+
{"--cpu-strict-draft"}, "<0|1>",
|
|
563
|
+
"Use strict CPU placement for draft model (default: same as --cpu-strict)",
|
|
564
|
+
[](gpt_params & params, int value) {
|
|
565
|
+
params.draft_cpuparams.strict_cpu = value;
|
|
566
|
+
}
|
|
567
|
+
).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
|
|
568
|
+
add_opt(llama_arg(
|
|
569
|
+
{"--prio-draft"}, "N",
|
|
570
|
+
format("set draft process/thread priority : 0-normal, 1-medium, 2-high, 3-realtime (default: %d)\n", params.draft_cpuparams.priority),
|
|
571
|
+
[](gpt_params & params, int prio) {
|
|
572
|
+
if (prio < 0 || prio > 3) {
|
|
573
|
+
throw std::invalid_argument("invalid value");
|
|
574
|
+
}
|
|
575
|
+
params.draft_cpuparams.priority = (enum ggml_sched_priority) prio;
|
|
576
|
+
}
|
|
577
|
+
).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
|
|
578
|
+
add_opt(llama_arg(
|
|
579
|
+
{"--poll-draft"}, "<0|1>",
|
|
580
|
+
"Use polling to wait for draft model work (default: same as --poll])",
|
|
581
|
+
[](gpt_params & params, int value) {
|
|
582
|
+
params.draft_cpuparams.poll = value;
|
|
583
|
+
}
|
|
584
|
+
).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
|
|
585
|
+
add_opt(llama_arg(
|
|
586
|
+
{"-Cbd", "--cpu-mask-batch-draft"}, "M",
|
|
587
|
+
"Draft model CPU affinity mask. Complements cpu-range-draft (default: same as --cpu-mask)",
|
|
588
|
+
[](gpt_params & params, const std::string & mask) {
|
|
589
|
+
params.draft_cpuparams_batch.mask_valid = true;
|
|
590
|
+
if (!parse_cpu_mask(mask, params.draft_cpuparams_batch.cpumask)) {
|
|
591
|
+
throw std::invalid_argument("invalid cpumask");
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
|
|
595
|
+
add_opt(llama_arg(
|
|
596
|
+
{"-Crbd", "--cpu-range-batch-draft"}, "lo-hi",
|
|
597
|
+
"Ranges of CPUs for affinity. Complements --cpu-mask-draft-batch)",
|
|
598
|
+
[](gpt_params & params, const std::string & range) {
|
|
599
|
+
params.draft_cpuparams_batch.mask_valid = true;
|
|
600
|
+
if (!parse_cpu_range(range, params.draft_cpuparams_batch.cpumask)) {
|
|
601
|
+
throw std::invalid_argument("invalid cpumask");
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
|
|
605
|
+
add_opt(llama_arg(
|
|
606
|
+
{"--cpu-strict-batch-draft"}, "<0|1>",
|
|
607
|
+
"Use strict CPU placement for draft model (default: --cpu-strict-draft)",
|
|
608
|
+
[](gpt_params & params, int value) {
|
|
609
|
+
params.draft_cpuparams_batch.strict_cpu = value;
|
|
610
|
+
}
|
|
611
|
+
).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
|
|
612
|
+
add_opt(llama_arg(
|
|
613
|
+
{"--prio-batch-draft"}, "N",
|
|
614
|
+
format("set draft process/thread priority : 0-normal, 1-medium, 2-high, 3-realtime (default: %d)\n", params.draft_cpuparams_batch.priority),
|
|
615
|
+
[](gpt_params & params, int prio) {
|
|
616
|
+
if (prio < 0 || prio > 3) {
|
|
617
|
+
throw std::invalid_argument("invalid value");
|
|
618
|
+
}
|
|
619
|
+
params.draft_cpuparams_batch.priority = (enum ggml_sched_priority) prio;
|
|
620
|
+
}
|
|
621
|
+
).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
|
|
622
|
+
add_opt(llama_arg(
|
|
623
|
+
{"--poll-batch-draft"}, "<0|1>",
|
|
624
|
+
"Use polling to wait for draft model work (default: --poll-draft)",
|
|
625
|
+
[](gpt_params & params, int value) {
|
|
626
|
+
params.draft_cpuparams_batch.poll = value;
|
|
627
|
+
}
|
|
628
|
+
).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
|
|
629
|
+
add_opt(llama_arg(
|
|
630
|
+
{"--draft"}, "N",
|
|
631
|
+
format("number of tokens to draft for speculative decoding (default: %d)", params.n_draft),
|
|
632
|
+
[](gpt_params & params, int value) {
|
|
633
|
+
params.n_draft = value;
|
|
634
|
+
}
|
|
635
|
+
).set_examples({LLAMA_EXAMPLE_SPECULATIVE, LLAMA_EXAMPLE_LOOKUP}));
|
|
636
|
+
add_opt(llama_arg(
|
|
637
|
+
{"-ps", "--p-split"}, "N",
|
|
638
|
+
format("speculative decoding split probability (default: %.1f)", (double)params.p_split),
|
|
639
|
+
[](gpt_params & params, const std::string & value) {
|
|
640
|
+
params.p_split = std::stof(value);
|
|
641
|
+
}
|
|
642
|
+
).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
|
|
643
|
+
add_opt(llama_arg(
|
|
644
|
+
{"-lcs", "--lookup-cache-static"}, "FNAME",
|
|
645
|
+
"path to static lookup cache to use for lookup decoding (not updated by generation)",
|
|
646
|
+
[](gpt_params & params, const std::string & value) {
|
|
647
|
+
params.lookup_cache_static = value;
|
|
648
|
+
}
|
|
649
|
+
).set_examples({LLAMA_EXAMPLE_LOOKUP}));
|
|
650
|
+
add_opt(llama_arg(
|
|
651
|
+
{"-lcd", "--lookup-cache-dynamic"}, "FNAME",
|
|
652
|
+
"path to dynamic lookup cache to use for lookup decoding (updated by generation)",
|
|
653
|
+
[](gpt_params & params, const std::string & value) {
|
|
654
|
+
params.lookup_cache_dynamic = value;
|
|
655
|
+
}
|
|
656
|
+
).set_examples({LLAMA_EXAMPLE_LOOKUP}));
|
|
657
|
+
add_opt(llama_arg(
|
|
658
|
+
{"-c", "--ctx-size"}, "N",
|
|
659
|
+
format("size of the prompt context (default: %d, 0 = loaded from model)", params.n_ctx),
|
|
660
|
+
[](gpt_params & params, int value) {
|
|
661
|
+
params.n_ctx = value;
|
|
662
|
+
}
|
|
663
|
+
).set_env("LLAMA_ARG_CTX_SIZE"));
|
|
664
|
+
add_opt(llama_arg(
|
|
665
|
+
{"-n", "--predict", "--n-predict"}, "N",
|
|
666
|
+
format("number of tokens to predict (default: %d, -1 = infinity, -2 = until context filled)", params.n_predict),
|
|
667
|
+
[](gpt_params & params, int value) {
|
|
668
|
+
params.n_predict = value;
|
|
669
|
+
}
|
|
670
|
+
).set_env("LLAMA_ARG_N_PREDICT"));
|
|
671
|
+
add_opt(llama_arg(
|
|
672
|
+
{"-b", "--batch-size"}, "N",
|
|
673
|
+
format("logical maximum batch size (default: %d)", params.n_batch),
|
|
674
|
+
[](gpt_params & params, int value) {
|
|
675
|
+
params.n_batch = value;
|
|
676
|
+
}
|
|
677
|
+
).set_env("LLAMA_ARG_BATCH"));
|
|
678
|
+
add_opt(llama_arg(
|
|
679
|
+
{"-ub", "--ubatch-size"}, "N",
|
|
680
|
+
format("physical maximum batch size (default: %d)", params.n_ubatch),
|
|
681
|
+
[](gpt_params & params, int value) {
|
|
682
|
+
params.n_ubatch = value;
|
|
683
|
+
}
|
|
684
|
+
).set_env("LLAMA_ARG_UBATCH"));
|
|
685
|
+
add_opt(llama_arg(
|
|
686
|
+
{"--keep"}, "N",
|
|
687
|
+
format("number of tokens to keep from the initial prompt (default: %d, -1 = all)", params.n_keep),
|
|
688
|
+
[](gpt_params & params, int value) {
|
|
689
|
+
params.n_keep = value;
|
|
690
|
+
}
|
|
691
|
+
));
|
|
692
|
+
add_opt(llama_arg(
|
|
693
|
+
{"--no-context-shift"},
|
|
694
|
+
format("disables context shift on inifinite text generation (default: %s)", params.ctx_shift ? "disabled" : "enabled"),
|
|
695
|
+
[](gpt_params & params) {
|
|
696
|
+
params.ctx_shift = false;
|
|
697
|
+
}
|
|
698
|
+
).set_examples({LLAMA_EXAMPLE_MAIN, LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_NO_CONTEXT_SHIFT"));
|
|
699
|
+
add_opt(llama_arg(
|
|
700
|
+
{"--chunks"}, "N",
|
|
701
|
+
format("max number of chunks to process (default: %d, -1 = all)", params.n_chunks),
|
|
702
|
+
[](gpt_params & params, int value) {
|
|
703
|
+
params.n_chunks = value;
|
|
704
|
+
}
|
|
705
|
+
).set_examples({LLAMA_EXAMPLE_IMATRIX, LLAMA_EXAMPLE_PERPLEXITY, LLAMA_EXAMPLE_RETRIEVAL}));
|
|
706
|
+
add_opt(llama_arg(
|
|
707
|
+
{"-fa", "--flash-attn"},
|
|
708
|
+
format("enable Flash Attention (default: %s)", params.flash_attn ? "enabled" : "disabled"),
|
|
709
|
+
[](gpt_params & params) {
|
|
710
|
+
params.flash_attn = true;
|
|
711
|
+
}
|
|
712
|
+
).set_env("LLAMA_ARG_FLASH_ATTN"));
|
|
713
|
+
add_opt(llama_arg(
|
|
714
|
+
{"-p", "--prompt"}, "PROMPT",
|
|
715
|
+
ex == LLAMA_EXAMPLE_MAIN
|
|
716
|
+
? "prompt to start generation with\nif -cnv is set, this will be used as system prompt"
|
|
717
|
+
: "prompt to start generation with",
|
|
718
|
+
[](gpt_params & params, const std::string & value) {
|
|
719
|
+
params.prompt = value;
|
|
720
|
+
}
|
|
721
|
+
));
|
|
722
|
+
add_opt(llama_arg(
|
|
723
|
+
{"--no-perf"},
|
|
724
|
+
format("disable internal libllama performance timings (default: %s)", params.no_perf ? "true" : "false"),
|
|
725
|
+
[](gpt_params & params) {
|
|
726
|
+
params.no_perf = true;
|
|
727
|
+
params.sparams.no_perf = true;
|
|
728
|
+
}
|
|
729
|
+
).set_env("LLAMA_ARG_NO_PERF"));
|
|
730
|
+
add_opt(llama_arg(
|
|
731
|
+
{"-f", "--file"}, "FNAME",
|
|
732
|
+
"a file containing the prompt (default: none)",
|
|
733
|
+
[](gpt_params & params, const std::string & value) {
|
|
734
|
+
std::ifstream file(value);
|
|
735
|
+
if (!file) {
|
|
736
|
+
throw std::runtime_error(format("error: failed to open file '%s'\n", value.c_str()));
|
|
737
|
+
}
|
|
738
|
+
// store the external file name in params
|
|
739
|
+
params.prompt_file = value;
|
|
740
|
+
std::copy(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>(), back_inserter(params.prompt));
|
|
741
|
+
if (!params.prompt.empty() && params.prompt.back() == '\n') {
|
|
742
|
+
params.prompt.pop_back();
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
));
|
|
746
|
+
add_opt(llama_arg(
|
|
747
|
+
{"--in-file"}, "FNAME",
|
|
748
|
+
"an input file (repeat to specify multiple files)",
|
|
749
|
+
[](gpt_params & params, const std::string & value) {
|
|
750
|
+
std::ifstream file(value);
|
|
751
|
+
if (!file) {
|
|
752
|
+
throw std::runtime_error(format("error: failed to open file '%s'\n", value.c_str()));
|
|
753
|
+
}
|
|
754
|
+
params.in_files.push_back(value);
|
|
755
|
+
}
|
|
756
|
+
).set_examples({LLAMA_EXAMPLE_IMATRIX}));
|
|
757
|
+
add_opt(llama_arg(
|
|
758
|
+
{"-bf", "--binary-file"}, "FNAME",
|
|
759
|
+
"binary file containing the prompt (default: none)",
|
|
760
|
+
[](gpt_params & params, const std::string & value) {
|
|
761
|
+
std::ifstream file(value, std::ios::binary);
|
|
762
|
+
if (!file) {
|
|
763
|
+
throw std::runtime_error(format("error: failed to open file '%s'\n", value.c_str()));
|
|
764
|
+
}
|
|
765
|
+
// store the external file name in params
|
|
766
|
+
params.prompt_file = value;
|
|
767
|
+
std::ostringstream ss;
|
|
768
|
+
ss << file.rdbuf();
|
|
769
|
+
params.prompt = ss.str();
|
|
770
|
+
fprintf(stderr, "Read %zu bytes from binary file %s\n", params.prompt.size(), value.c_str());
|
|
771
|
+
}
|
|
772
|
+
));
|
|
773
|
+
add_opt(llama_arg(
|
|
774
|
+
{"-e", "--escape"},
|
|
775
|
+
format("process escapes sequences (\\n, \\r, \\t, \\', \\\", \\\\) (default: %s)", params.escape ? "true" : "false"),
|
|
776
|
+
[](gpt_params & params) {
|
|
777
|
+
params.escape = true;
|
|
778
|
+
}
|
|
779
|
+
));
|
|
780
|
+
add_opt(llama_arg(
|
|
781
|
+
{"--no-escape"},
|
|
782
|
+
"do not process escape sequences",
|
|
783
|
+
[](gpt_params & params) {
|
|
784
|
+
params.escape = false;
|
|
785
|
+
}
|
|
786
|
+
));
|
|
787
|
+
add_opt(llama_arg(
|
|
788
|
+
{"-ptc", "--print-token-count"}, "N",
|
|
789
|
+
format("print token count every N tokens (default: %d)", params.n_print),
|
|
790
|
+
[](gpt_params & params, int value) {
|
|
791
|
+
params.n_print = value;
|
|
792
|
+
}
|
|
793
|
+
).set_examples({LLAMA_EXAMPLE_MAIN}));
|
|
794
|
+
add_opt(llama_arg(
|
|
795
|
+
{"--prompt-cache"}, "FNAME",
|
|
796
|
+
"file to cache prompt state for faster startup (default: none)",
|
|
797
|
+
[](gpt_params & params, const std::string & value) {
|
|
798
|
+
params.path_prompt_cache = value;
|
|
799
|
+
}
|
|
800
|
+
).set_examples({LLAMA_EXAMPLE_MAIN}));
|
|
801
|
+
add_opt(llama_arg(
|
|
802
|
+
{"--prompt-cache-all"},
|
|
803
|
+
"if specified, saves user input and generations to cache as well\n",
|
|
804
|
+
[](gpt_params & params) {
|
|
805
|
+
params.prompt_cache_all = true;
|
|
806
|
+
}
|
|
807
|
+
).set_examples({LLAMA_EXAMPLE_MAIN}));
|
|
808
|
+
add_opt(llama_arg(
|
|
809
|
+
{"--prompt-cache-ro"},
|
|
810
|
+
"if specified, uses the prompt cache but does not update it",
|
|
811
|
+
[](gpt_params & params) {
|
|
812
|
+
params.prompt_cache_ro = true;
|
|
813
|
+
}
|
|
814
|
+
).set_examples({LLAMA_EXAMPLE_MAIN}));
|
|
815
|
+
add_opt(llama_arg(
|
|
816
|
+
{"-r", "--reverse-prompt"}, "PROMPT",
|
|
817
|
+
"halt generation at PROMPT, return control in interactive mode\n",
|
|
818
|
+
[](gpt_params & params, const std::string & value) {
|
|
819
|
+
params.antiprompt.emplace_back(value);
|
|
820
|
+
}
|
|
821
|
+
).set_examples({LLAMA_EXAMPLE_MAIN}));
|
|
822
|
+
add_opt(llama_arg(
|
|
823
|
+
{"-sp", "--special"},
|
|
824
|
+
format("special tokens output enabled (default: %s)", params.special ? "true" : "false"),
|
|
825
|
+
[](gpt_params & params) {
|
|
826
|
+
params.special = true;
|
|
827
|
+
}
|
|
828
|
+
).set_examples({LLAMA_EXAMPLE_MAIN, LLAMA_EXAMPLE_SERVER}));
|
|
829
|
+
add_opt(llama_arg(
|
|
830
|
+
{"-cnv", "--conversation"},
|
|
831
|
+
format(
|
|
832
|
+
"run in conversation mode:\n"
|
|
833
|
+
"- does not print special tokens and suffix/prefix\n"
|
|
834
|
+
"- interactive mode is also enabled\n"
|
|
835
|
+
"(default: %s)",
|
|
836
|
+
params.conversation ? "true" : "false"
|
|
837
|
+
),
|
|
838
|
+
[](gpt_params & params) {
|
|
839
|
+
params.conversation = true;
|
|
840
|
+
}
|
|
841
|
+
).set_examples({LLAMA_EXAMPLE_MAIN}));
|
|
842
|
+
add_opt(llama_arg(
|
|
843
|
+
{"-i", "--interactive"},
|
|
844
|
+
format("run in interactive mode (default: %s)", params.interactive ? "true" : "false"),
|
|
845
|
+
[](gpt_params & params) {
|
|
846
|
+
params.interactive = true;
|
|
847
|
+
}
|
|
848
|
+
).set_examples({LLAMA_EXAMPLE_MAIN}));
|
|
849
|
+
add_opt(llama_arg(
|
|
850
|
+
{"-if", "--interactive-first"},
|
|
851
|
+
format("run in interactive mode and wait for input right away (default: %s)", params.interactive_first ? "true" : "false"),
|
|
852
|
+
[](gpt_params & params) {
|
|
853
|
+
params.interactive_first = true;
|
|
854
|
+
}
|
|
855
|
+
).set_examples({LLAMA_EXAMPLE_MAIN}));
|
|
856
|
+
add_opt(llama_arg(
|
|
857
|
+
{"-mli", "--multiline-input"},
|
|
858
|
+
"allows you to write or paste multiple lines without ending each in '\\'",
|
|
859
|
+
[](gpt_params & params) {
|
|
860
|
+
params.multiline_input = true;
|
|
861
|
+
}
|
|
862
|
+
).set_examples({LLAMA_EXAMPLE_MAIN}));
|
|
863
|
+
add_opt(llama_arg(
|
|
864
|
+
{"--in-prefix-bos"},
|
|
865
|
+
"prefix BOS to user inputs, preceding the `--in-prefix` string",
|
|
866
|
+
[](gpt_params & params) {
|
|
867
|
+
params.input_prefix_bos = true;
|
|
868
|
+
params.enable_chat_template = false;
|
|
869
|
+
}
|
|
870
|
+
).set_examples({LLAMA_EXAMPLE_MAIN}));
|
|
871
|
+
add_opt(llama_arg(
|
|
872
|
+
{"--in-prefix"}, "STRING",
|
|
873
|
+
"string to prefix user inputs with (default: empty)",
|
|
874
|
+
[](gpt_params & params, const std::string & value) {
|
|
875
|
+
params.input_prefix = value;
|
|
876
|
+
params.enable_chat_template = false;
|
|
877
|
+
}
|
|
878
|
+
).set_examples({LLAMA_EXAMPLE_MAIN, LLAMA_EXAMPLE_INFILL}));
|
|
879
|
+
add_opt(llama_arg(
|
|
880
|
+
{"--in-suffix"}, "STRING",
|
|
881
|
+
"string to suffix after user inputs with (default: empty)",
|
|
882
|
+
[](gpt_params & params, const std::string & value) {
|
|
883
|
+
params.input_suffix = value;
|
|
884
|
+
params.enable_chat_template = false;
|
|
885
|
+
}
|
|
886
|
+
).set_examples({LLAMA_EXAMPLE_MAIN, LLAMA_EXAMPLE_INFILL}));
|
|
887
|
+
add_opt(llama_arg(
|
|
888
|
+
{"--no-warmup"},
|
|
889
|
+
"skip warming up the model with an empty run",
|
|
890
|
+
[](gpt_params & params) {
|
|
891
|
+
params.warmup = false;
|
|
892
|
+
}
|
|
893
|
+
).set_examples({LLAMA_EXAMPLE_MAIN}));
|
|
894
|
+
add_opt(llama_arg(
|
|
895
|
+
{"--spm-infill"},
|
|
896
|
+
format(
|
|
897
|
+
"use Suffix/Prefix/Middle pattern for infill (instead of Prefix/Suffix/Middle) as some models prefer this. (default: %s)",
|
|
898
|
+
params.spm_infill ? "enabled" : "disabled"
|
|
899
|
+
),
|
|
900
|
+
[](gpt_params & params) {
|
|
901
|
+
params.spm_infill = true;
|
|
902
|
+
}
|
|
903
|
+
).set_examples({LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_INFILL}));
|
|
904
|
+
add_opt(llama_arg(
|
|
905
|
+
{"--samplers"}, "SAMPLERS",
|
|
906
|
+
format("samplers that will be used for generation in the order, separated by \';\'\n(default: %s)", sampler_type_names.c_str()),
|
|
907
|
+
[](gpt_params & params, const std::string & value) {
|
|
908
|
+
const auto sampler_names = string_split(value, ';');
|
|
909
|
+
params.sparams.samplers = gpt_sampler_types_from_names(sampler_names, true);
|
|
910
|
+
}
|
|
911
|
+
).set_sparam());
|
|
912
|
+
add_opt(llama_arg(
|
|
913
|
+
{"-s", "--seed"}, "SEED",
|
|
914
|
+
format("RNG seed (default: %d, use random seed for %d)", params.sparams.seed, LLAMA_DEFAULT_SEED),
|
|
915
|
+
[](gpt_params & params, const std::string & value) {
|
|
916
|
+
params.sparams.seed = std::stoul(value);
|
|
917
|
+
}
|
|
918
|
+
).set_sparam());
|
|
919
|
+
add_opt(llama_arg(
|
|
920
|
+
{"--sampling-seq"}, "SEQUENCE",
|
|
921
|
+
format("simplified sequence for samplers that will be used (default: %s)", sampler_type_chars.c_str()),
|
|
922
|
+
[](gpt_params & params, const std::string & value) {
|
|
923
|
+
params.sparams.samplers = gpt_sampler_types_from_chars(value);
|
|
924
|
+
}
|
|
925
|
+
).set_sparam());
|
|
926
|
+
add_opt(llama_arg(
|
|
927
|
+
{"--ignore-eos"},
|
|
928
|
+
"ignore end of stream token and continue generating (implies --logit-bias EOS-inf)",
|
|
929
|
+
[](gpt_params & params) {
|
|
930
|
+
params.sparams.ignore_eos = true;
|
|
931
|
+
}
|
|
932
|
+
).set_sparam());
|
|
933
|
+
add_opt(llama_arg(
|
|
934
|
+
{"--penalize-nl"},
|
|
935
|
+
format("penalize newline tokens (default: %s)", params.sparams.penalize_nl ? "true" : "false"),
|
|
936
|
+
[](gpt_params & params) {
|
|
937
|
+
params.sparams.penalize_nl = true;
|
|
938
|
+
}
|
|
939
|
+
).set_sparam());
|
|
940
|
+
add_opt(llama_arg(
|
|
941
|
+
{"--temp"}, "N",
|
|
942
|
+
format("temperature (default: %.1f)", (double)params.sparams.temp),
|
|
943
|
+
[](gpt_params & params, const std::string & value) {
|
|
944
|
+
params.sparams.temp = std::stof(value);
|
|
945
|
+
params.sparams.temp = std::max(params.sparams.temp, 0.0f);
|
|
946
|
+
}
|
|
947
|
+
).set_sparam());
|
|
948
|
+
add_opt(llama_arg(
|
|
949
|
+
{"--top-k"}, "N",
|
|
950
|
+
format("top-k sampling (default: %d, 0 = disabled)", params.sparams.top_k),
|
|
951
|
+
[](gpt_params & params, int value) {
|
|
952
|
+
params.sparams.top_k = value;
|
|
953
|
+
}
|
|
954
|
+
).set_sparam());
|
|
955
|
+
add_opt(llama_arg(
|
|
956
|
+
{"--top-p"}, "N",
|
|
957
|
+
format("top-p sampling (default: %.1f, 1.0 = disabled)", (double)params.sparams.top_p),
|
|
958
|
+
[](gpt_params & params, const std::string & value) {
|
|
959
|
+
params.sparams.top_p = std::stof(value);
|
|
960
|
+
}
|
|
961
|
+
).set_sparam());
|
|
962
|
+
add_opt(llama_arg(
|
|
963
|
+
{"--min-p"}, "N",
|
|
964
|
+
format("min-p sampling (default: %.1f, 0.0 = disabled)", (double)params.sparams.min_p),
|
|
965
|
+
[](gpt_params & params, const std::string & value) {
|
|
966
|
+
params.sparams.min_p = std::stof(value);
|
|
967
|
+
}
|
|
968
|
+
).set_sparam());
|
|
969
|
+
add_opt(llama_arg(
|
|
970
|
+
{"--tfs"}, "N",
|
|
971
|
+
format("tail free sampling, parameter z (default: %.1f, 1.0 = disabled)", (double)params.sparams.tfs_z),
|
|
972
|
+
[](gpt_params & params, const std::string & value) {
|
|
973
|
+
params.sparams.tfs_z = std::stof(value);
|
|
974
|
+
}
|
|
975
|
+
).set_sparam());
|
|
976
|
+
add_opt(llama_arg(
|
|
977
|
+
{"--typical"}, "N",
|
|
978
|
+
format("locally typical sampling, parameter p (default: %.1f, 1.0 = disabled)", (double)params.sparams.typ_p),
|
|
979
|
+
[](gpt_params & params, const std::string & value) {
|
|
980
|
+
params.sparams.typ_p = std::stof(value);
|
|
981
|
+
}
|
|
982
|
+
).set_sparam());
|
|
983
|
+
add_opt(llama_arg(
|
|
984
|
+
{"--repeat-last-n"}, "N",
|
|
985
|
+
format("last n tokens to consider for penalize (default: %d, 0 = disabled, -1 = ctx_size)", params.sparams.penalty_last_n),
|
|
986
|
+
[](gpt_params & params, int value) {
|
|
987
|
+
params.sparams.penalty_last_n = value;
|
|
988
|
+
params.sparams.n_prev = std::max(params.sparams.n_prev, params.sparams.penalty_last_n);
|
|
989
|
+
}
|
|
990
|
+
).set_sparam());
|
|
991
|
+
add_opt(llama_arg(
|
|
992
|
+
{"--repeat-penalty"}, "N",
|
|
993
|
+
format("penalize repeat sequence of tokens (default: %.1f, 1.0 = disabled)", (double)params.sparams.penalty_repeat),
|
|
994
|
+
[](gpt_params & params, const std::string & value) {
|
|
995
|
+
params.sparams.penalty_repeat = std::stof(value);
|
|
996
|
+
}
|
|
997
|
+
).set_sparam());
|
|
998
|
+
add_opt(llama_arg(
|
|
999
|
+
{"--presence-penalty"}, "N",
|
|
1000
|
+
format("repeat alpha presence penalty (default: %.1f, 0.0 = disabled)", (double)params.sparams.penalty_present),
|
|
1001
|
+
[](gpt_params & params, const std::string & value) {
|
|
1002
|
+
params.sparams.penalty_present = std::stof(value);
|
|
1003
|
+
}
|
|
1004
|
+
).set_sparam());
|
|
1005
|
+
add_opt(llama_arg(
|
|
1006
|
+
{"--frequency-penalty"}, "N",
|
|
1007
|
+
format("repeat alpha frequency penalty (default: %.1f, 0.0 = disabled)", (double)params.sparams.penalty_freq),
|
|
1008
|
+
[](gpt_params & params, const std::string & value) {
|
|
1009
|
+
params.sparams.penalty_freq = std::stof(value);
|
|
1010
|
+
}
|
|
1011
|
+
).set_sparam());
|
|
1012
|
+
add_opt(llama_arg(
|
|
1013
|
+
{"--dynatemp-range"}, "N",
|
|
1014
|
+
format("dynamic temperature range (default: %.1f, 0.0 = disabled)", (double)params.sparams.dynatemp_range),
|
|
1015
|
+
[](gpt_params & params, const std::string & value) {
|
|
1016
|
+
params.sparams.dynatemp_range = std::stof(value);
|
|
1017
|
+
}
|
|
1018
|
+
).set_sparam());
|
|
1019
|
+
add_opt(llama_arg(
|
|
1020
|
+
{"--dynatemp-exp"}, "N",
|
|
1021
|
+
format("dynamic temperature exponent (default: %.1f)", (double)params.sparams.dynatemp_exponent),
|
|
1022
|
+
[](gpt_params & params, const std::string & value) {
|
|
1023
|
+
params.sparams.dynatemp_exponent = std::stof(value);
|
|
1024
|
+
}
|
|
1025
|
+
).set_sparam());
|
|
1026
|
+
add_opt(llama_arg(
|
|
1027
|
+
{"--mirostat"}, "N",
|
|
1028
|
+
format("use Mirostat sampling.\nTop K, Nucleus, Tail Free and Locally Typical samplers are ignored if used.\n"
|
|
1029
|
+
"(default: %d, 0 = disabled, 1 = Mirostat, 2 = Mirostat 2.0)", params.sparams.mirostat),
|
|
1030
|
+
[](gpt_params & params, int value) {
|
|
1031
|
+
params.sparams.mirostat = value;
|
|
1032
|
+
}
|
|
1033
|
+
).set_sparam());
|
|
1034
|
+
add_opt(llama_arg(
|
|
1035
|
+
{"--mirostat-lr"}, "N",
|
|
1036
|
+
format("Mirostat learning rate, parameter eta (default: %.1f)", (double)params.sparams.mirostat_eta),
|
|
1037
|
+
[](gpt_params & params, const std::string & value) {
|
|
1038
|
+
params.sparams.mirostat_eta = std::stof(value);
|
|
1039
|
+
}
|
|
1040
|
+
).set_sparam());
|
|
1041
|
+
add_opt(llama_arg(
|
|
1042
|
+
{"--mirostat-ent"}, "N",
|
|
1043
|
+
format("Mirostat target entropy, parameter tau (default: %.1f)", (double)params.sparams.mirostat_tau),
|
|
1044
|
+
[](gpt_params & params, const std::string & value) {
|
|
1045
|
+
params.sparams.mirostat_tau = std::stof(value);
|
|
1046
|
+
}
|
|
1047
|
+
).set_sparam());
|
|
1048
|
+
add_opt(llama_arg(
|
|
1049
|
+
{"-l", "--logit-bias"}, "TOKEN_ID(+/-)BIAS",
|
|
1050
|
+
"modifies the likelihood of token appearing in the completion,\n"
|
|
1051
|
+
"i.e. `--logit-bias 15043+1` to increase likelihood of token ' Hello',\n"
|
|
1052
|
+
"or `--logit-bias 15043-1` to decrease likelihood of token ' Hello'",
|
|
1053
|
+
[](gpt_params & params, const std::string & value) {
|
|
1054
|
+
std::stringstream ss(value);
|
|
1055
|
+
llama_token key;
|
|
1056
|
+
char sign;
|
|
1057
|
+
std::string value_str;
|
|
1058
|
+
try {
|
|
1059
|
+
if (ss >> key && ss >> sign && std::getline(ss, value_str) && (sign == '+' || sign == '-')) {
|
|
1060
|
+
const float bias = std::stof(value_str) * ((sign == '-') ? -1.0f : 1.0f);
|
|
1061
|
+
params.sparams.logit_bias.push_back({key, bias});
|
|
1062
|
+
} else {
|
|
1063
|
+
throw std::invalid_argument("invalid input format");
|
|
1064
|
+
}
|
|
1065
|
+
} catch (const std::exception&) {
|
|
1066
|
+
throw std::invalid_argument("invalid input format");
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
).set_sparam());
|
|
1070
|
+
add_opt(llama_arg(
|
|
1071
|
+
{"--grammar"}, "GRAMMAR",
|
|
1072
|
+
format("BNF-like grammar to constrain generations (see samples in grammars/ dir) (default: '%s')", params.sparams.grammar.c_str()),
|
|
1073
|
+
[](gpt_params & params, const std::string & value) {
|
|
1074
|
+
params.sparams.grammar = value;
|
|
1075
|
+
}
|
|
1076
|
+
).set_sparam());
|
|
1077
|
+
add_opt(llama_arg(
|
|
1078
|
+
{"--grammar-file"}, "FNAME",
|
|
1079
|
+
"file to read grammar from",
|
|
1080
|
+
[](gpt_params & params, const std::string & value) {
|
|
1081
|
+
std::ifstream file(value);
|
|
1082
|
+
if (!file) {
|
|
1083
|
+
throw std::runtime_error(format("error: failed to open file '%s'\n", value.c_str()));
|
|
1084
|
+
}
|
|
1085
|
+
std::copy(
|
|
1086
|
+
std::istreambuf_iterator<char>(file),
|
|
1087
|
+
std::istreambuf_iterator<char>(),
|
|
1088
|
+
std::back_inserter(params.sparams.grammar)
|
|
1089
|
+
);
|
|
1090
|
+
}
|
|
1091
|
+
).set_sparam());
|
|
1092
|
+
add_opt(llama_arg(
|
|
1093
|
+
{"-j", "--json-schema"}, "SCHEMA",
|
|
1094
|
+
"JSON schema to constrain generations (https://json-schema.org/), e.g. `{}` for any JSON object\nFor schemas w/ external $refs, use --grammar + example/json_schema_to_grammar.py instead",
|
|
1095
|
+
[](gpt_params & params, const std::string & value) {
|
|
1096
|
+
params.sparams.grammar = json_schema_to_grammar(json::parse(value));
|
|
1097
|
+
}
|
|
1098
|
+
).set_sparam());
|
|
1099
|
+
add_opt(llama_arg(
|
|
1100
|
+
{"--pooling"}, "{none,mean,cls,last,rank}",
|
|
1101
|
+
"pooling type for embeddings, use model default if unspecified",
|
|
1102
|
+
[](gpt_params & params, const std::string & value) {
|
|
1103
|
+
/**/ if (value == "none") { params.pooling_type = LLAMA_POOLING_TYPE_NONE; }
|
|
1104
|
+
else if (value == "mean") { params.pooling_type = LLAMA_POOLING_TYPE_MEAN; }
|
|
1105
|
+
else if (value == "cls") { params.pooling_type = LLAMA_POOLING_TYPE_CLS; }
|
|
1106
|
+
else if (value == "last") { params.pooling_type = LLAMA_POOLING_TYPE_LAST; }
|
|
1107
|
+
else if (value == "rank") { params.pooling_type = LLAMA_POOLING_TYPE_RANK; }
|
|
1108
|
+
else { throw std::invalid_argument("invalid value"); }
|
|
1109
|
+
}
|
|
1110
|
+
).set_examples({LLAMA_EXAMPLE_EMBEDDING, LLAMA_EXAMPLE_RETRIEVAL, LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_POOLING"));
|
|
1111
|
+
add_opt(llama_arg(
|
|
1112
|
+
{"--attention"}, "{causal,non,causal}",
|
|
1113
|
+
"attention type for embeddings, use model default if unspecified",
|
|
1114
|
+
[](gpt_params & params, const std::string & value) {
|
|
1115
|
+
/**/ if (value == "causal") { params.attention_type = LLAMA_ATTENTION_TYPE_CAUSAL; }
|
|
1116
|
+
else if (value == "non-causal") { params.attention_type = LLAMA_ATTENTION_TYPE_NON_CAUSAL; }
|
|
1117
|
+
else { throw std::invalid_argument("invalid value"); }
|
|
1118
|
+
}
|
|
1119
|
+
).set_examples({LLAMA_EXAMPLE_EMBEDDING}));
|
|
1120
|
+
add_opt(llama_arg(
|
|
1121
|
+
{"--rope-scaling"}, "{none,linear,yarn}",
|
|
1122
|
+
"RoPE frequency scaling method, defaults to linear unless specified by the model",
|
|
1123
|
+
[](gpt_params & params, const std::string & value) {
|
|
1124
|
+
/**/ if (value == "none") { params.rope_scaling_type = LLAMA_ROPE_SCALING_TYPE_NONE; }
|
|
1125
|
+
else if (value == "linear") { params.rope_scaling_type = LLAMA_ROPE_SCALING_TYPE_LINEAR; }
|
|
1126
|
+
else if (value == "yarn") { params.rope_scaling_type = LLAMA_ROPE_SCALING_TYPE_YARN; }
|
|
1127
|
+
else { throw std::invalid_argument("invalid value"); }
|
|
1128
|
+
}
|
|
1129
|
+
).set_env("LLAMA_ARG_ROPE_SCALING_TYPE"));
|
|
1130
|
+
add_opt(llama_arg(
|
|
1131
|
+
{"--rope-scale"}, "N",
|
|
1132
|
+
"RoPE context scaling factor, expands context by a factor of N",
|
|
1133
|
+
[](gpt_params & params, const std::string & value) {
|
|
1134
|
+
params.rope_freq_scale = 1.0f / std::stof(value);
|
|
1135
|
+
}
|
|
1136
|
+
).set_env("LLAMA_ARG_ROPE_SCALE"));
|
|
1137
|
+
add_opt(llama_arg(
|
|
1138
|
+
{"--rope-freq-base"}, "N",
|
|
1139
|
+
"RoPE base frequency, used by NTK-aware scaling (default: loaded from model)",
|
|
1140
|
+
[](gpt_params & params, const std::string & value) {
|
|
1141
|
+
params.rope_freq_base = std::stof(value);
|
|
1142
|
+
}
|
|
1143
|
+
).set_env("LLAMA_ARG_ROPE_FREQ_BASE"));
|
|
1144
|
+
add_opt(llama_arg(
|
|
1145
|
+
{"--rope-freq-scale"}, "N",
|
|
1146
|
+
"RoPE frequency scaling factor, expands context by a factor of 1/N",
|
|
1147
|
+
[](gpt_params & params, const std::string & value) {
|
|
1148
|
+
params.rope_freq_scale = std::stof(value);
|
|
1149
|
+
}
|
|
1150
|
+
).set_env("LLAMA_ARG_ROPE_FREQ_SCALE"));
|
|
1151
|
+
add_opt(llama_arg(
|
|
1152
|
+
{"--yarn-orig-ctx"}, "N",
|
|
1153
|
+
format("YaRN: original context size of model (default: %d = model training context size)", params.yarn_orig_ctx),
|
|
1154
|
+
[](gpt_params & params, int value) {
|
|
1155
|
+
params.yarn_orig_ctx = value;
|
|
1156
|
+
}
|
|
1157
|
+
).set_env("LLAMA_ARG_YARN_ORIG_CTX"));
|
|
1158
|
+
add_opt(llama_arg(
|
|
1159
|
+
{"--yarn-ext-factor"}, "N",
|
|
1160
|
+
format("YaRN: extrapolation mix factor (default: %.1f, 0.0 = full interpolation)", (double)params.yarn_ext_factor),
|
|
1161
|
+
[](gpt_params & params, const std::string & value) {
|
|
1162
|
+
params.yarn_ext_factor = std::stof(value);
|
|
1163
|
+
}
|
|
1164
|
+
).set_env("LLAMA_ARG_YARN_EXT_FACTOR"));
|
|
1165
|
+
add_opt(llama_arg(
|
|
1166
|
+
{"--yarn-attn-factor"}, "N",
|
|
1167
|
+
format("YaRN: scale sqrt(t) or attention magnitude (default: %.1f)", (double)params.yarn_attn_factor),
|
|
1168
|
+
[](gpt_params & params, const std::string & value) {
|
|
1169
|
+
params.yarn_attn_factor = std::stof(value);
|
|
1170
|
+
}
|
|
1171
|
+
).set_env("LLAMA_ARG_YARN_ATTN_FACTOR"));
|
|
1172
|
+
add_opt(llama_arg(
|
|
1173
|
+
{"--yarn-beta-slow"}, "N",
|
|
1174
|
+
format("YaRN: high correction dim or alpha (default: %.1f)", (double)params.yarn_beta_slow),
|
|
1175
|
+
[](gpt_params & params, const std::string & value) {
|
|
1176
|
+
params.yarn_beta_slow = std::stof(value);
|
|
1177
|
+
}
|
|
1178
|
+
).set_env("LLAMA_ARG_YARN_BETA_SLOW"));
|
|
1179
|
+
add_opt(llama_arg(
|
|
1180
|
+
{"--yarn-beta-fast"}, "N",
|
|
1181
|
+
format("YaRN: low correction dim or beta (default: %.1f)", (double)params.yarn_beta_fast),
|
|
1182
|
+
[](gpt_params & params, const std::string & value) {
|
|
1183
|
+
params.yarn_beta_fast = std::stof(value);
|
|
1184
|
+
}
|
|
1185
|
+
).set_env("LLAMA_ARG_YARN_BETA_FAST"));
|
|
1186
|
+
add_opt(llama_arg(
|
|
1187
|
+
{"-gan", "--grp-attn-n"}, "N",
|
|
1188
|
+
format("group-attention factor (default: %d)", params.grp_attn_n),
|
|
1189
|
+
[](gpt_params & params, int value) {
|
|
1190
|
+
params.grp_attn_n = value;
|
|
1191
|
+
}
|
|
1192
|
+
).set_env("LLAMA_ARG_GRP_ATTN_N"));
|
|
1193
|
+
add_opt(llama_arg(
|
|
1194
|
+
{"-gaw", "--grp-attn-w"}, "N",
|
|
1195
|
+
format("group-attention width (default: %.1f)", (double)params.grp_attn_w),
|
|
1196
|
+
[](gpt_params & params, int value) {
|
|
1197
|
+
params.grp_attn_w = value;
|
|
1198
|
+
}
|
|
1199
|
+
).set_env("LLAMA_ARG_GRP_ATTN_W"));
|
|
1200
|
+
add_opt(llama_arg(
|
|
1201
|
+
{"-dkvc", "--dump-kv-cache"},
|
|
1202
|
+
"verbose print of the KV cache",
|
|
1203
|
+
[](gpt_params & params) {
|
|
1204
|
+
params.dump_kv_cache = true;
|
|
1205
|
+
}
|
|
1206
|
+
));
|
|
1207
|
+
add_opt(llama_arg(
|
|
1208
|
+
{"-nkvo", "--no-kv-offload"},
|
|
1209
|
+
"disable KV offload",
|
|
1210
|
+
[](gpt_params & params) {
|
|
1211
|
+
params.no_kv_offload = true;
|
|
1212
|
+
}
|
|
1213
|
+
).set_env("LLAMA_ARG_NO_KV_OFFLOAD"));
|
|
1214
|
+
add_opt(llama_arg(
|
|
1215
|
+
{"-ctk", "--cache-type-k"}, "TYPE",
|
|
1216
|
+
format("KV cache data type for K (default: %s)", params.cache_type_k.c_str()),
|
|
1217
|
+
[](gpt_params & params, const std::string & value) {
|
|
1218
|
+
// TODO: get the type right here
|
|
1219
|
+
params.cache_type_k = value;
|
|
1220
|
+
}
|
|
1221
|
+
).set_env("LLAMA_ARG_CACHE_TYPE_K"));
|
|
1222
|
+
add_opt(llama_arg(
|
|
1223
|
+
{"-ctv", "--cache-type-v"}, "TYPE",
|
|
1224
|
+
format("KV cache data type for V (default: %s)", params.cache_type_v.c_str()),
|
|
1225
|
+
[](gpt_params & params, const std::string & value) {
|
|
1226
|
+
// TODO: get the type right here
|
|
1227
|
+
params.cache_type_v = value;
|
|
1228
|
+
}
|
|
1229
|
+
).set_env("LLAMA_ARG_CACHE_TYPE_V"));
|
|
1230
|
+
add_opt(llama_arg(
|
|
1231
|
+
{"--perplexity", "--all-logits"},
|
|
1232
|
+
format("return logits for all tokens in the batch (default: %s)", params.logits_all ? "true" : "false"),
|
|
1233
|
+
[](gpt_params & params) {
|
|
1234
|
+
params.logits_all = true;
|
|
1235
|
+
}
|
|
1236
|
+
).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
|
|
1237
|
+
add_opt(llama_arg(
|
|
1238
|
+
{"--hellaswag"},
|
|
1239
|
+
"compute HellaSwag score over random tasks from datafile supplied with -f",
|
|
1240
|
+
[](gpt_params & params) {
|
|
1241
|
+
params.hellaswag = true;
|
|
1242
|
+
}
|
|
1243
|
+
).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
|
|
1244
|
+
add_opt(llama_arg(
|
|
1245
|
+
{"--hellaswag-tasks"}, "N",
|
|
1246
|
+
format("number of tasks to use when computing the HellaSwag score (default: %zu)", params.hellaswag_tasks),
|
|
1247
|
+
[](gpt_params & params, int value) {
|
|
1248
|
+
params.hellaswag_tasks = value;
|
|
1249
|
+
}
|
|
1250
|
+
).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
|
|
1251
|
+
add_opt(llama_arg(
|
|
1252
|
+
{"--winogrande"},
|
|
1253
|
+
"compute Winogrande score over random tasks from datafile supplied with -f",
|
|
1254
|
+
[](gpt_params & params) {
|
|
1255
|
+
params.winogrande = true;
|
|
1256
|
+
}
|
|
1257
|
+
).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
|
|
1258
|
+
add_opt(llama_arg(
|
|
1259
|
+
{"--winogrande-tasks"}, "N",
|
|
1260
|
+
format("number of tasks to use when computing the Winogrande score (default: %zu)", params.winogrande_tasks),
|
|
1261
|
+
[](gpt_params & params, int value) {
|
|
1262
|
+
params.winogrande_tasks = value;
|
|
1263
|
+
}
|
|
1264
|
+
).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
|
|
1265
|
+
add_opt(llama_arg(
|
|
1266
|
+
{"--multiple-choice"},
|
|
1267
|
+
"compute multiple choice score over random tasks from datafile supplied with -f",
|
|
1268
|
+
[](gpt_params & params) {
|
|
1269
|
+
params.multiple_choice = true;
|
|
1270
|
+
}
|
|
1271
|
+
).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
|
|
1272
|
+
add_opt(llama_arg(
|
|
1273
|
+
{"--multiple-choice-tasks"}, "N",
|
|
1274
|
+
format("number of tasks to use when computing the multiple choice score (default: %zu)", params.multiple_choice_tasks),
|
|
1275
|
+
[](gpt_params & params, int value) {
|
|
1276
|
+
params.multiple_choice_tasks = value;
|
|
1277
|
+
}
|
|
1278
|
+
).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
|
|
1279
|
+
add_opt(llama_arg(
|
|
1280
|
+
{"--kl-divergence"},
|
|
1281
|
+
"computes KL-divergence to logits provided via --kl-divergence-base",
|
|
1282
|
+
[](gpt_params & params) {
|
|
1283
|
+
params.kl_divergence = true;
|
|
1284
|
+
}
|
|
1285
|
+
).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
|
|
1286
|
+
add_opt(llama_arg(
|
|
1287
|
+
{"--save-all-logits", "--kl-divergence-base"}, "FNAME",
|
|
1288
|
+
"set logits file",
|
|
1289
|
+
[](gpt_params & params, const std::string & value) {
|
|
1290
|
+
params.logits_file = value;
|
|
1291
|
+
}
|
|
1292
|
+
).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
|
|
1293
|
+
add_opt(llama_arg(
|
|
1294
|
+
{"--ppl-stride"}, "N",
|
|
1295
|
+
format("stride for perplexity calculation (default: %d)", params.ppl_stride),
|
|
1296
|
+
[](gpt_params & params, int value) {
|
|
1297
|
+
params.ppl_stride = value;
|
|
1298
|
+
}
|
|
1299
|
+
).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
|
|
1300
|
+
add_opt(llama_arg(
|
|
1301
|
+
{"--ppl-output-type"}, "<0|1>",
|
|
1302
|
+
format("output type for perplexity calculation (default: %d)", params.ppl_output_type),
|
|
1303
|
+
[](gpt_params & params, int value) {
|
|
1304
|
+
params.ppl_output_type = value;
|
|
1305
|
+
}
|
|
1306
|
+
).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
|
|
1307
|
+
add_opt(llama_arg(
|
|
1308
|
+
{"-dt", "--defrag-thold"}, "N",
|
|
1309
|
+
format("KV cache defragmentation threshold (default: %.1f, < 0 - disabled)", (double)params.defrag_thold),
|
|
1310
|
+
[](gpt_params & params, const std::string & value) {
|
|
1311
|
+
params.defrag_thold = std::stof(value);
|
|
1312
|
+
}
|
|
1313
|
+
).set_env("LLAMA_ARG_DEFRAG_THOLD"));
|
|
1314
|
+
add_opt(llama_arg(
|
|
1315
|
+
{"-np", "--parallel"}, "N",
|
|
1316
|
+
format("number of parallel sequences to decode (default: %d)", params.n_parallel),
|
|
1317
|
+
[](gpt_params & params, int value) {
|
|
1318
|
+
params.n_parallel = value;
|
|
1319
|
+
}
|
|
1320
|
+
).set_env("LLAMA_ARG_N_PARALLEL"));
|
|
1321
|
+
add_opt(llama_arg(
|
|
1322
|
+
{"-ns", "--sequences"}, "N",
|
|
1323
|
+
format("number of sequences to decode (default: %d)", params.n_sequences),
|
|
1324
|
+
[](gpt_params & params, int value) {
|
|
1325
|
+
params.n_sequences = value;
|
|
1326
|
+
}
|
|
1327
|
+
).set_examples({LLAMA_EXAMPLE_PARALLEL}));
|
|
1328
|
+
add_opt(llama_arg(
|
|
1329
|
+
{"-cb", "--cont-batching"},
|
|
1330
|
+
format("enable continuous batching (a.k.a dynamic batching) (default: %s)", params.cont_batching ? "enabled" : "disabled"),
|
|
1331
|
+
[](gpt_params & params) {
|
|
1332
|
+
params.cont_batching = true;
|
|
1333
|
+
}
|
|
1334
|
+
).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_CONT_BATCHING"));
|
|
1335
|
+
add_opt(llama_arg(
|
|
1336
|
+
{"-nocb", "--no-cont-batching"},
|
|
1337
|
+
"disable continuous batching",
|
|
1338
|
+
[](gpt_params & params) {
|
|
1339
|
+
params.cont_batching = false;
|
|
1340
|
+
}
|
|
1341
|
+
).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_NO_CONT_BATCHING"));
|
|
1342
|
+
add_opt(llama_arg(
|
|
1343
|
+
{"--mmproj"}, "FILE",
|
|
1344
|
+
"path to a multimodal projector file for LLaVA. see examples/llava/README.md",
|
|
1345
|
+
[](gpt_params & params, const std::string & value) {
|
|
1346
|
+
params.mmproj = value;
|
|
1347
|
+
}
|
|
1348
|
+
).set_examples({LLAMA_EXAMPLE_LLAVA}));
|
|
1349
|
+
add_opt(llama_arg(
|
|
1350
|
+
{"--image"}, "FILE",
|
|
1351
|
+
"path to an image file. use with multimodal models. Specify multiple times for batching",
|
|
1352
|
+
[](gpt_params & params, const std::string & value) {
|
|
1353
|
+
params.image.emplace_back(value);
|
|
1354
|
+
}
|
|
1355
|
+
).set_examples({LLAMA_EXAMPLE_LLAVA}));
|
|
1356
|
+
#ifdef GGML_USE_RPC
|
|
1357
|
+
add_opt(llama_arg(
|
|
1358
|
+
{"--rpc"}, "SERVERS",
|
|
1359
|
+
"comma separated list of RPC servers",
|
|
1360
|
+
[](gpt_params & params, const std::string & value) {
|
|
1361
|
+
params.rpc_servers = value;
|
|
1362
|
+
}
|
|
1363
|
+
).set_env("LLAMA_ARG_RPC"));
|
|
1364
|
+
#endif
|
|
1365
|
+
add_opt(llama_arg(
|
|
1366
|
+
{"--mlock"},
|
|
1367
|
+
"force system to keep model in RAM rather than swapping or compressing",
|
|
1368
|
+
[](gpt_params & params) {
|
|
1369
|
+
params.use_mlock = true;
|
|
1370
|
+
}
|
|
1371
|
+
).set_env("LLAMA_ARG_MLOCK"));
|
|
1372
|
+
add_opt(llama_arg(
|
|
1373
|
+
{"--no-mmap"},
|
|
1374
|
+
"do not memory-map model (slower load but may reduce pageouts if not using mlock)",
|
|
1375
|
+
[](gpt_params & params) {
|
|
1376
|
+
params.use_mmap = false;
|
|
1377
|
+
}
|
|
1378
|
+
).set_env("LLAMA_ARG_NO_MMAP"));
|
|
1379
|
+
add_opt(llama_arg(
|
|
1380
|
+
{"--numa"}, "TYPE",
|
|
1381
|
+
"attempt optimizations that help on some NUMA systems\n"
|
|
1382
|
+
"- distribute: spread execution evenly over all nodes\n"
|
|
1383
|
+
"- isolate: only spawn threads on CPUs on the node that execution started on\n"
|
|
1384
|
+
"- numactl: use the CPU map provided by numactl\n"
|
|
1385
|
+
"if run without this previously, it is recommended to drop the system page cache before using this\n"
|
|
1386
|
+
"see https://github.com/ggerganov/llama.cpp/issues/1437",
|
|
1387
|
+
[](gpt_params & params, const std::string & value) {
|
|
1388
|
+
/**/ if (value == "distribute" || value == "") { params.numa = GGML_NUMA_STRATEGY_DISTRIBUTE; }
|
|
1389
|
+
else if (value == "isolate") { params.numa = GGML_NUMA_STRATEGY_ISOLATE; }
|
|
1390
|
+
else if (value == "numactl") { params.numa = GGML_NUMA_STRATEGY_NUMACTL; }
|
|
1391
|
+
else { throw std::invalid_argument("invalid value"); }
|
|
1392
|
+
}
|
|
1393
|
+
).set_env("LLAMA_ARG_NUMA"));
|
|
1394
|
+
add_opt(llama_arg(
|
|
1395
|
+
{"-ngl", "--gpu-layers", "--n-gpu-layers"}, "N",
|
|
1396
|
+
"number of layers to store in VRAM",
|
|
1397
|
+
[](gpt_params & params, int value) {
|
|
1398
|
+
params.n_gpu_layers = value;
|
|
1399
|
+
if (!llama_supports_gpu_offload()) {
|
|
1400
|
+
fprintf(stderr, "warning: not compiled with GPU offload support, --gpu-layers option will be ignored\n");
|
|
1401
|
+
fprintf(stderr, "warning: see main README.md for information on enabling GPU BLAS support\n");
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
).set_env("LLAMA_ARG_N_GPU_LAYERS"));
|
|
1405
|
+
add_opt(llama_arg(
|
|
1406
|
+
{"-ngld", "--gpu-layers-draft", "--n-gpu-layers-draft"}, "N",
|
|
1407
|
+
"number of layers to store in VRAM for the draft model",
|
|
1408
|
+
[](gpt_params & params, int value) {
|
|
1409
|
+
params.n_gpu_layers_draft = value;
|
|
1410
|
+
if (!llama_supports_gpu_offload()) {
|
|
1411
|
+
fprintf(stderr, "warning: not compiled with GPU offload support, --gpu-layers-draft option will be ignored\n");
|
|
1412
|
+
fprintf(stderr, "warning: see main README.md for information on enabling GPU BLAS support\n");
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
|
|
1416
|
+
add_opt(llama_arg(
|
|
1417
|
+
{"-sm", "--split-mode"}, "{none,layer,row}",
|
|
1418
|
+
"how to split the model across multiple GPUs, one of:\n"
|
|
1419
|
+
"- none: use one GPU only\n"
|
|
1420
|
+
"- layer (default): split layers and KV across GPUs\n"
|
|
1421
|
+
"- row: split rows across GPUs",
|
|
1422
|
+
[](gpt_params & params, const std::string & value) {
|
|
1423
|
+
std::string arg_next = value;
|
|
1424
|
+
if (arg_next == "none") {
|
|
1425
|
+
params.split_mode = LLAMA_SPLIT_MODE_NONE;
|
|
1426
|
+
} else if (arg_next == "layer") {
|
|
1427
|
+
params.split_mode = LLAMA_SPLIT_MODE_LAYER;
|
|
1428
|
+
} else if (arg_next == "row") {
|
|
1429
|
+
#ifdef GGML_USE_SYCL
|
|
1430
|
+
fprintf(stderr, "warning: The split mode value:[row] is not supported by llama.cpp with SYCL. It's developing.\nExit!\n");
|
|
1431
|
+
exit(1);
|
|
1432
|
+
#endif // GGML_USE_SYCL
|
|
1433
|
+
params.split_mode = LLAMA_SPLIT_MODE_ROW;
|
|
1434
|
+
} else {
|
|
1435
|
+
throw std::invalid_argument("invalid value");
|
|
1436
|
+
}
|
|
1437
|
+
if (!llama_supports_gpu_offload()) {
|
|
1438
|
+
fprintf(stderr, "warning: llama.cpp was compiled without support for GPU offload. Setting the split mode has no effect.\n");
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
).set_env("LLAMA_ARG_SPLIT_MODE"));
|
|
1442
|
+
add_opt(llama_arg(
|
|
1443
|
+
{"-ts", "--tensor-split"}, "N0,N1,N2,...",
|
|
1444
|
+
"fraction of the model to offload to each GPU, comma-separated list of proportions, e.g. 3,1",
|
|
1445
|
+
[](gpt_params & params, const std::string & value) {
|
|
1446
|
+
std::string arg_next = value;
|
|
1447
|
+
|
|
1448
|
+
// split string by , and /
|
|
1449
|
+
const std::regex regex{ R"([,/]+)" };
|
|
1450
|
+
std::sregex_token_iterator it{ arg_next.begin(), arg_next.end(), regex, -1 };
|
|
1451
|
+
std::vector<std::string> split_arg{ it, {} };
|
|
1452
|
+
if (split_arg.size() >= llama_max_devices()) {
|
|
1453
|
+
throw std::invalid_argument(
|
|
1454
|
+
format("got %d input configs, but system only has %d devices", (int)split_arg.size(), (int)llama_max_devices())
|
|
1455
|
+
);
|
|
1456
|
+
}
|
|
1457
|
+
for (size_t i = 0; i < llama_max_devices(); ++i) {
|
|
1458
|
+
if (i < split_arg.size()) {
|
|
1459
|
+
params.tensor_split[i] = std::stof(split_arg[i]);
|
|
1460
|
+
} else {
|
|
1461
|
+
params.tensor_split[i] = 0.0f;
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
if (!llama_supports_gpu_offload()) {
|
|
1465
|
+
fprintf(stderr, "warning: llama.cpp was compiled without support for GPU offload. Setting a tensor split has no effect.\n");
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
).set_env("LLAMA_ARG_TENSOR_SPLIT"));
|
|
1469
|
+
add_opt(llama_arg(
|
|
1470
|
+
{"-mg", "--main-gpu"}, "INDEX",
|
|
1471
|
+
format("the GPU to use for the model (with split-mode = none), or for intermediate results and KV (with split-mode = row) (default: %d)", params.main_gpu),
|
|
1472
|
+
[](gpt_params & params, int value) {
|
|
1473
|
+
params.main_gpu = value;
|
|
1474
|
+
if (!llama_supports_gpu_offload()) {
|
|
1475
|
+
fprintf(stderr, "warning: llama.cpp was compiled without support for GPU offload. Setting the main GPU has no effect.\n");
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
).set_env("LLAMA_ARG_MAIN_GPU"));
|
|
1479
|
+
add_opt(llama_arg(
|
|
1480
|
+
{"--check-tensors"},
|
|
1481
|
+
format("check model tensor data for invalid values (default: %s)", params.check_tensors ? "true" : "false"),
|
|
1482
|
+
[](gpt_params & params) {
|
|
1483
|
+
params.check_tensors = true;
|
|
1484
|
+
}
|
|
1485
|
+
));
|
|
1486
|
+
add_opt(llama_arg(
|
|
1487
|
+
{"--override-kv"}, "KEY=TYPE:VALUE",
|
|
1488
|
+
"advanced option to override model metadata by key. may be specified multiple times.\n"
|
|
1489
|
+
"types: int, float, bool, str. example: --override-kv tokenizer.ggml.add_bos_token=bool:false",
|
|
1490
|
+
[](gpt_params & params, const std::string & value) {
|
|
1491
|
+
if (!string_parse_kv_override(value.c_str(), params.kv_overrides)) {
|
|
1492
|
+
throw std::runtime_error(format("error: Invalid type for KV override: %s\n", value.c_str()));
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
));
|
|
1496
|
+
add_opt(llama_arg(
|
|
1497
|
+
{"--lora"}, "FNAME",
|
|
1498
|
+
"path to LoRA adapter (can be repeated to use multiple adapters)",
|
|
1499
|
+
[](gpt_params & params, const std::string & value) {
|
|
1500
|
+
params.lora_adapters.push_back({ std::string(value), 1.0 });
|
|
1501
|
+
}
|
|
1502
|
+
// we define this arg on both COMMON and EXPORT_LORA, so when showing help message of export-lora, it will be categorized as "example-specific" arg
|
|
1503
|
+
).set_examples({LLAMA_EXAMPLE_COMMON, LLAMA_EXAMPLE_EXPORT_LORA}));
|
|
1504
|
+
add_opt(llama_arg(
|
|
1505
|
+
{"--lora-scaled"}, "FNAME", "SCALE",
|
|
1506
|
+
"path to LoRA adapter with user defined scaling (can be repeated to use multiple adapters)",
|
|
1507
|
+
[](gpt_params & params, const std::string & fname, const std::string & scale) {
|
|
1508
|
+
params.lora_adapters.push_back({ fname, std::stof(scale) });
|
|
1509
|
+
}
|
|
1510
|
+
// we define this arg on both COMMON and EXPORT_LORA, so when showing help message of export-lora, it will be categorized as "example-specific" arg
|
|
1511
|
+
).set_examples({LLAMA_EXAMPLE_COMMON, LLAMA_EXAMPLE_EXPORT_LORA}));
|
|
1512
|
+
add_opt(llama_arg(
|
|
1513
|
+
{"--control-vector"}, "FNAME",
|
|
1514
|
+
"add a control vector\nnote: this argument can be repeated to add multiple control vectors",
|
|
1515
|
+
[](gpt_params & params, const std::string & value) {
|
|
1516
|
+
params.control_vectors.push_back({ 1.0f, value, });
|
|
1517
|
+
}
|
|
1518
|
+
));
|
|
1519
|
+
add_opt(llama_arg(
|
|
1520
|
+
{"--control-vector-scaled"}, "FNAME", "SCALE",
|
|
1521
|
+
"add a control vector with user defined scaling SCALE\n"
|
|
1522
|
+
"note: this argument can be repeated to add multiple scaled control vectors",
|
|
1523
|
+
[](gpt_params & params, const std::string & fname, const std::string & scale) {
|
|
1524
|
+
params.control_vectors.push_back({ std::stof(scale), fname });
|
|
1525
|
+
}
|
|
1526
|
+
));
|
|
1527
|
+
add_opt(llama_arg(
|
|
1528
|
+
{"--control-vector-layer-range"}, "START", "END",
|
|
1529
|
+
"layer range to apply the control vector(s) to, start and end inclusive",
|
|
1530
|
+
[](gpt_params & params, const std::string & start, const std::string & end) {
|
|
1531
|
+
params.control_vector_layer_start = std::stoi(start);
|
|
1532
|
+
params.control_vector_layer_end = std::stoi(end);
|
|
1533
|
+
}
|
|
1534
|
+
));
|
|
1535
|
+
add_opt(llama_arg(
|
|
1536
|
+
{"-a", "--alias"}, "STRING",
|
|
1537
|
+
"set alias for model name (to be used by REST API)",
|
|
1538
|
+
[](gpt_params & params, const std::string & value) {
|
|
1539
|
+
params.model_alias = value;
|
|
1540
|
+
}
|
|
1541
|
+
).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_ALIAS"));
|
|
1542
|
+
add_opt(llama_arg(
|
|
1543
|
+
{"-m", "--model"}, "FNAME",
|
|
1544
|
+
ex == LLAMA_EXAMPLE_EXPORT_LORA
|
|
1545
|
+
? std::string("model path from which to load base model")
|
|
1546
|
+
: format(
|
|
1547
|
+
"model path (default: `models/$filename` with filename from `--hf-file` "
|
|
1548
|
+
"or `--model-url` if set, otherwise %s)", DEFAULT_MODEL_PATH
|
|
1549
|
+
),
|
|
1550
|
+
[](gpt_params & params, const std::string & value) {
|
|
1551
|
+
params.model = value;
|
|
1552
|
+
}
|
|
1553
|
+
).set_examples({LLAMA_EXAMPLE_COMMON, LLAMA_EXAMPLE_EXPORT_LORA}).set_env("LLAMA_ARG_MODEL"));
|
|
1554
|
+
add_opt(llama_arg(
|
|
1555
|
+
{"-md", "--model-draft"}, "FNAME",
|
|
1556
|
+
"draft model for speculative decoding (default: unused)",
|
|
1557
|
+
[](gpt_params & params, const std::string & value) {
|
|
1558
|
+
params.model_draft = value;
|
|
1559
|
+
}
|
|
1560
|
+
).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
|
|
1561
|
+
add_opt(llama_arg(
|
|
1562
|
+
{"-mu", "--model-url"}, "MODEL_URL",
|
|
1563
|
+
"model download url (default: unused)",
|
|
1564
|
+
[](gpt_params & params, const std::string & value) {
|
|
1565
|
+
params.model_url = value;
|
|
1566
|
+
}
|
|
1567
|
+
).set_env("LLAMA_ARG_MODEL_URL"));
|
|
1568
|
+
add_opt(llama_arg(
|
|
1569
|
+
{"-hfr", "--hf-repo"}, "REPO",
|
|
1570
|
+
"Hugging Face model repository (default: unused)",
|
|
1571
|
+
[](gpt_params & params, const std::string & value) {
|
|
1572
|
+
params.hf_repo = value;
|
|
1573
|
+
}
|
|
1574
|
+
).set_env("LLAMA_ARG_HF_REPO"));
|
|
1575
|
+
add_opt(llama_arg(
|
|
1576
|
+
{"-hff", "--hf-file"}, "FILE",
|
|
1577
|
+
"Hugging Face model file (default: unused)",
|
|
1578
|
+
[](gpt_params & params, const std::string & value) {
|
|
1579
|
+
params.hf_file = value;
|
|
1580
|
+
}
|
|
1581
|
+
).set_env("LLAMA_ARG_HF_FILE"));
|
|
1582
|
+
add_opt(llama_arg(
|
|
1583
|
+
{"-hft", "--hf-token"}, "TOKEN",
|
|
1584
|
+
"Hugging Face access token (default: value from HF_TOKEN environment variable)",
|
|
1585
|
+
[](gpt_params & params, const std::string & value) {
|
|
1586
|
+
params.hf_token = value;
|
|
1587
|
+
}
|
|
1588
|
+
).set_env("HF_TOKEN"));
|
|
1589
|
+
add_opt(llama_arg(
|
|
1590
|
+
{"--context-file"}, "FNAME",
|
|
1591
|
+
"file to load context from (repeat to specify multiple files)",
|
|
1592
|
+
[](gpt_params & params, const std::string & value) {
|
|
1593
|
+
std::ifstream file(value, std::ios::binary);
|
|
1594
|
+
if (!file) {
|
|
1595
|
+
throw std::runtime_error(format("error: failed to open file '%s'\n", value.c_str()));
|
|
1596
|
+
}
|
|
1597
|
+
params.context_files.push_back(value);
|
|
1598
|
+
}
|
|
1599
|
+
).set_examples({LLAMA_EXAMPLE_RETRIEVAL}));
|
|
1600
|
+
add_opt(llama_arg(
|
|
1601
|
+
{"--chunk-size"}, "N",
|
|
1602
|
+
format("minimum length of embedded text chunks (default: %d)", params.chunk_size),
|
|
1603
|
+
[](gpt_params & params, int value) {
|
|
1604
|
+
params.chunk_size = value;
|
|
1605
|
+
}
|
|
1606
|
+
).set_examples({LLAMA_EXAMPLE_RETRIEVAL}));
|
|
1607
|
+
add_opt(llama_arg(
|
|
1608
|
+
{"--chunk-separator"}, "STRING",
|
|
1609
|
+
format("separator between chunks (default: '%s')", params.chunk_separator.c_str()),
|
|
1610
|
+
[](gpt_params & params, const std::string & value) {
|
|
1611
|
+
params.chunk_separator = value;
|
|
1612
|
+
}
|
|
1613
|
+
).set_examples({LLAMA_EXAMPLE_RETRIEVAL}));
|
|
1614
|
+
add_opt(llama_arg(
|
|
1615
|
+
{"--junk"}, "N",
|
|
1616
|
+
format("number of times to repeat the junk text (default: %d)", params.n_junk),
|
|
1617
|
+
[](gpt_params & params, int value) {
|
|
1618
|
+
params.n_junk = value;
|
|
1619
|
+
}
|
|
1620
|
+
).set_examples({LLAMA_EXAMPLE_PASSKEY}));
|
|
1621
|
+
add_opt(llama_arg(
|
|
1622
|
+
{"--pos"}, "N",
|
|
1623
|
+
format("position of the passkey in the junk text (default: %d)", params.i_pos),
|
|
1624
|
+
[](gpt_params & params, int value) {
|
|
1625
|
+
params.i_pos = value;
|
|
1626
|
+
}
|
|
1627
|
+
).set_examples({LLAMA_EXAMPLE_PASSKEY}));
|
|
1628
|
+
add_opt(llama_arg(
|
|
1629
|
+
{"-o", "--output", "--output-file"}, "FNAME",
|
|
1630
|
+
format("output file (default: '%s')",
|
|
1631
|
+
ex == LLAMA_EXAMPLE_EXPORT_LORA
|
|
1632
|
+
? params.lora_outfile.c_str()
|
|
1633
|
+
: ex == LLAMA_EXAMPLE_CVECTOR_GENERATOR
|
|
1634
|
+
? params.cvector_outfile.c_str()
|
|
1635
|
+
: params.out_file.c_str()),
|
|
1636
|
+
[](gpt_params & params, const std::string & value) {
|
|
1637
|
+
params.out_file = value;
|
|
1638
|
+
params.cvector_outfile = value;
|
|
1639
|
+
params.lora_outfile = value;
|
|
1640
|
+
}
|
|
1641
|
+
).set_examples({LLAMA_EXAMPLE_IMATRIX, LLAMA_EXAMPLE_CVECTOR_GENERATOR, LLAMA_EXAMPLE_EXPORT_LORA}));
|
|
1642
|
+
add_opt(llama_arg(
|
|
1643
|
+
{"-ofreq", "--output-frequency"}, "N",
|
|
1644
|
+
format("output the imatrix every N iterations (default: %d)", params.n_out_freq),
|
|
1645
|
+
[](gpt_params & params, int value) {
|
|
1646
|
+
params.n_out_freq = value;
|
|
1647
|
+
}
|
|
1648
|
+
).set_examples({LLAMA_EXAMPLE_IMATRIX}));
|
|
1649
|
+
add_opt(llama_arg(
|
|
1650
|
+
{"--save-frequency"}, "N",
|
|
1651
|
+
format("save an imatrix copy every N iterations (default: %d)", params.n_save_freq),
|
|
1652
|
+
[](gpt_params & params, int value) {
|
|
1653
|
+
params.n_save_freq = value;
|
|
1654
|
+
}
|
|
1655
|
+
).set_examples({LLAMA_EXAMPLE_IMATRIX}));
|
|
1656
|
+
add_opt(llama_arg(
|
|
1657
|
+
{"--process-output"},
|
|
1658
|
+
format("collect data for the output tensor (default: %s)", params.process_output ? "true" : "false"),
|
|
1659
|
+
[](gpt_params & params) {
|
|
1660
|
+
params.process_output = true;
|
|
1661
|
+
}
|
|
1662
|
+
).set_examples({LLAMA_EXAMPLE_IMATRIX}));
|
|
1663
|
+
add_opt(llama_arg(
|
|
1664
|
+
{"--no-ppl"},
|
|
1665
|
+
format("do not compute perplexity (default: %s)", params.compute_ppl ? "true" : "false"),
|
|
1666
|
+
[](gpt_params & params) {
|
|
1667
|
+
params.compute_ppl = false;
|
|
1668
|
+
}
|
|
1669
|
+
).set_examples({LLAMA_EXAMPLE_IMATRIX}));
|
|
1670
|
+
add_opt(llama_arg(
|
|
1671
|
+
{"--chunk", "--from-chunk"}, "N",
|
|
1672
|
+
format("start processing the input from chunk N (default: %d)", params.i_chunk),
|
|
1673
|
+
[](gpt_params & params, int value) {
|
|
1674
|
+
params.i_chunk = value;
|
|
1675
|
+
}
|
|
1676
|
+
).set_examples({LLAMA_EXAMPLE_IMATRIX}));
|
|
1677
|
+
add_opt(llama_arg(
|
|
1678
|
+
{"-pps"},
|
|
1679
|
+
format("is the prompt shared across parallel sequences (default: %s)", params.is_pp_shared ? "true" : "false"),
|
|
1680
|
+
[](gpt_params & params) {
|
|
1681
|
+
params.is_pp_shared = true;
|
|
1682
|
+
}
|
|
1683
|
+
).set_examples({LLAMA_EXAMPLE_BENCH}));
|
|
1684
|
+
add_opt(llama_arg(
|
|
1685
|
+
{"-npp"}, "n0,n1,...",
|
|
1686
|
+
"number of prompt tokens",
|
|
1687
|
+
[](gpt_params & params, const std::string & value) {
|
|
1688
|
+
auto p = string_split<int>(value, ',');
|
|
1689
|
+
params.n_pp.insert(params.n_pp.end(), p.begin(), p.end());
|
|
1690
|
+
}
|
|
1691
|
+
).set_examples({LLAMA_EXAMPLE_BENCH}));
|
|
1692
|
+
add_opt(llama_arg(
|
|
1693
|
+
{"-ntg"}, "n0,n1,...",
|
|
1694
|
+
"number of text generation tokens",
|
|
1695
|
+
[](gpt_params & params, const std::string & value) {
|
|
1696
|
+
auto p = string_split<int>(value, ',');
|
|
1697
|
+
params.n_tg.insert(params.n_tg.end(), p.begin(), p.end());
|
|
1698
|
+
}
|
|
1699
|
+
).set_examples({LLAMA_EXAMPLE_BENCH}));
|
|
1700
|
+
add_opt(llama_arg(
|
|
1701
|
+
{"-npl"}, "n0,n1,...",
|
|
1702
|
+
"number of parallel prompts",
|
|
1703
|
+
[](gpt_params & params, const std::string & value) {
|
|
1704
|
+
auto p = string_split<int>(value, ',');
|
|
1705
|
+
params.n_pl.insert(params.n_pl.end(), p.begin(), p.end());
|
|
1706
|
+
}
|
|
1707
|
+
).set_examples({LLAMA_EXAMPLE_BENCH}));
|
|
1708
|
+
add_opt(llama_arg(
|
|
1709
|
+
{"--embd-normalize"}, "N",
|
|
1710
|
+
format("normalisation for embendings (default: %d) (-1=none, 0=max absolute int16, 1=taxicab, 2=euclidean, >2=p-norm)", params.embd_normalize),
|
|
1711
|
+
[](gpt_params & params, int value) {
|
|
1712
|
+
params.embd_normalize = value;
|
|
1713
|
+
}
|
|
1714
|
+
).set_examples({LLAMA_EXAMPLE_EMBEDDING}));
|
|
1715
|
+
add_opt(llama_arg(
|
|
1716
|
+
{"--embd-output-format"}, "FORMAT",
|
|
1717
|
+
"empty = default, \"array\" = [[],[]...], \"json\" = openai style, \"json+\" = same \"json\" + cosine similarity matrix",
|
|
1718
|
+
[](gpt_params & params, const std::string & value) {
|
|
1719
|
+
params.embd_out = value;
|
|
1720
|
+
}
|
|
1721
|
+
).set_examples({LLAMA_EXAMPLE_EMBEDDING}));
|
|
1722
|
+
add_opt(llama_arg(
|
|
1723
|
+
{"--embd-separator"}, "STRING",
|
|
1724
|
+
"separator of embendings (default \\n) for example \"<#sep#>\"",
|
|
1725
|
+
[](gpt_params & params, const std::string & value) {
|
|
1726
|
+
params.embd_sep = value;
|
|
1727
|
+
}
|
|
1728
|
+
).set_examples({LLAMA_EXAMPLE_EMBEDDING}));
|
|
1729
|
+
add_opt(llama_arg(
|
|
1730
|
+
{"--host"}, "HOST",
|
|
1731
|
+
format("ip address to listen (default: %s)", params.hostname.c_str()),
|
|
1732
|
+
[](gpt_params & params, const std::string & value) {
|
|
1733
|
+
params.hostname = value;
|
|
1734
|
+
}
|
|
1735
|
+
).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_HOST"));
|
|
1736
|
+
add_opt(llama_arg(
|
|
1737
|
+
{"--port"}, "PORT",
|
|
1738
|
+
format("port to listen (default: %d)", params.port),
|
|
1739
|
+
[](gpt_params & params, int value) {
|
|
1740
|
+
params.port = value;
|
|
1741
|
+
}
|
|
1742
|
+
).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_PORT"));
|
|
1743
|
+
add_opt(llama_arg(
|
|
1744
|
+
{"--path"}, "PATH",
|
|
1745
|
+
format("path to serve static files from (default: %s)", params.public_path.c_str()),
|
|
1746
|
+
[](gpt_params & params, const std::string & value) {
|
|
1747
|
+
params.public_path = value;
|
|
1748
|
+
}
|
|
1749
|
+
).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_STATIC_PATH"));
|
|
1750
|
+
add_opt(llama_arg(
|
|
1751
|
+
{"--embedding", "--embeddings"},
|
|
1752
|
+
format("restrict to only support embedding use case; use only with dedicated embedding models (default: %s)", params.embedding ? "enabled" : "disabled"),
|
|
1753
|
+
[](gpt_params & params) {
|
|
1754
|
+
params.embedding = true;
|
|
1755
|
+
}
|
|
1756
|
+
).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_EMBEDDINGS"));
|
|
1757
|
+
add_opt(llama_arg(
|
|
1758
|
+
{"--reranking", "--rerank"},
|
|
1759
|
+
format("enable reranking endpoint on server (default: %s)", params.reranking ? "enabled" : "disabled"),
|
|
1760
|
+
[](gpt_params & params) {
|
|
1761
|
+
params.reranking = true;
|
|
1762
|
+
}
|
|
1763
|
+
).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_RERANKING"));
|
|
1764
|
+
add_opt(llama_arg(
|
|
1765
|
+
{"--api-key"}, "KEY",
|
|
1766
|
+
"API key to use for authentication (default: none)",
|
|
1767
|
+
[](gpt_params & params, const std::string & value) {
|
|
1768
|
+
params.api_keys.push_back(value);
|
|
1769
|
+
}
|
|
1770
|
+
).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_API_KEY"));
|
|
1771
|
+
add_opt(llama_arg(
|
|
1772
|
+
{"--api-key-file"}, "FNAME",
|
|
1773
|
+
"path to file containing API keys (default: none)",
|
|
1774
|
+
[](gpt_params & params, const std::string & value) {
|
|
1775
|
+
std::ifstream key_file(value);
|
|
1776
|
+
if (!key_file) {
|
|
1777
|
+
throw std::runtime_error(format("error: failed to open file '%s'\n", value.c_str()));
|
|
1778
|
+
}
|
|
1779
|
+
std::string key;
|
|
1780
|
+
while (std::getline(key_file, key)) {
|
|
1781
|
+
if (!key.empty()) {
|
|
1782
|
+
params.api_keys.push_back(key);
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
key_file.close();
|
|
1786
|
+
}
|
|
1787
|
+
).set_examples({LLAMA_EXAMPLE_SERVER}));
|
|
1788
|
+
add_opt(llama_arg(
|
|
1789
|
+
{"--ssl-key-file"}, "FNAME",
|
|
1790
|
+
"path to file a PEM-encoded SSL private key",
|
|
1791
|
+
[](gpt_params & params, const std::string & value) {
|
|
1792
|
+
params.ssl_file_key = value;
|
|
1793
|
+
}
|
|
1794
|
+
).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_SSL_KEY_FILE"));
|
|
1795
|
+
add_opt(llama_arg(
|
|
1796
|
+
{"--ssl-cert-file"}, "FNAME",
|
|
1797
|
+
"path to file a PEM-encoded SSL certificate",
|
|
1798
|
+
[](gpt_params & params, const std::string & value) {
|
|
1799
|
+
params.ssl_file_cert = value;
|
|
1800
|
+
}
|
|
1801
|
+
).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_SSL_CERT_FILE"));
|
|
1802
|
+
add_opt(llama_arg(
|
|
1803
|
+
{"-to", "--timeout"}, "N",
|
|
1804
|
+
format("server read/write timeout in seconds (default: %d)", params.timeout_read),
|
|
1805
|
+
[](gpt_params & params, int value) {
|
|
1806
|
+
params.timeout_read = value;
|
|
1807
|
+
params.timeout_write = value;
|
|
1808
|
+
}
|
|
1809
|
+
).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_TIMEOUT"));
|
|
1810
|
+
add_opt(llama_arg(
|
|
1811
|
+
{"--threads-http"}, "N",
|
|
1812
|
+
format("number of threads used to process HTTP requests (default: %d)", params.n_threads_http),
|
|
1813
|
+
[](gpt_params & params, int value) {
|
|
1814
|
+
params.n_threads_http = value;
|
|
1815
|
+
}
|
|
1816
|
+
).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_THREADS_HTTP"));
|
|
1817
|
+
add_opt(llama_arg(
|
|
1818
|
+
{"-spf", "--system-prompt-file"}, "FNAME",
|
|
1819
|
+
"set a file to load a system prompt (initial prompt of all slots), this is useful for chat applications",
|
|
1820
|
+
[](gpt_params & params, const std::string & value) {
|
|
1821
|
+
std::ifstream file(value);
|
|
1822
|
+
if (!file) {
|
|
1823
|
+
throw std::runtime_error(format("error: failed to open file '%s'\n", value.c_str()));
|
|
1824
|
+
}
|
|
1825
|
+
std::string system_prompt;
|
|
1826
|
+
std::copy(
|
|
1827
|
+
std::istreambuf_iterator<char>(file),
|
|
1828
|
+
std::istreambuf_iterator<char>(),
|
|
1829
|
+
std::back_inserter(system_prompt)
|
|
1830
|
+
);
|
|
1831
|
+
params.system_prompt = system_prompt;
|
|
1832
|
+
}
|
|
1833
|
+
).set_examples({LLAMA_EXAMPLE_SERVER}));
|
|
1834
|
+
add_opt(llama_arg(
|
|
1835
|
+
{"--metrics"},
|
|
1836
|
+
format("enable prometheus compatible metrics endpoint (default: %s)", params.endpoint_metrics ? "enabled" : "disabled"),
|
|
1837
|
+
[](gpt_params & params) {
|
|
1838
|
+
params.endpoint_metrics = true;
|
|
1839
|
+
}
|
|
1840
|
+
).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_ENDPOINT_METRICS"));
|
|
1841
|
+
add_opt(llama_arg(
|
|
1842
|
+
{"--no-slots"},
|
|
1843
|
+
format("disables slots monitoring endpoint (default: %s)", params.endpoint_slots ? "enabled" : "disabled"),
|
|
1844
|
+
[](gpt_params & params) {
|
|
1845
|
+
params.endpoint_slots = false;
|
|
1846
|
+
}
|
|
1847
|
+
).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_NO_ENDPOINT_SLOTS"));
|
|
1848
|
+
add_opt(llama_arg(
|
|
1849
|
+
{"--slot-save-path"}, "PATH",
|
|
1850
|
+
"path to save slot kv cache (default: disabled)",
|
|
1851
|
+
[](gpt_params & params, const std::string & value) {
|
|
1852
|
+
params.slot_save_path = value;
|
|
1853
|
+
// if doesn't end with DIRECTORY_SEPARATOR, add it
|
|
1854
|
+
if (!params.slot_save_path.empty() && params.slot_save_path[params.slot_save_path.size() - 1] != DIRECTORY_SEPARATOR) {
|
|
1855
|
+
params.slot_save_path += DIRECTORY_SEPARATOR;
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
).set_examples({LLAMA_EXAMPLE_SERVER}));
|
|
1859
|
+
add_opt(llama_arg(
|
|
1860
|
+
{"--chat-template"}, "JINJA_TEMPLATE",
|
|
1861
|
+
"set custom jinja chat template (default: template taken from model's metadata)\n"
|
|
1862
|
+
"if suffix/prefix are specified, template will be disabled\n"
|
|
1863
|
+
"only commonly used templates are accepted:\nhttps://github.com/ggerganov/llama.cpp/wiki/Templates-supported-by-llama_chat_apply_template",
|
|
1864
|
+
[](gpt_params & params, const std::string & value) {
|
|
1865
|
+
if (!llama_chat_verify_template(value)) {
|
|
1866
|
+
throw std::runtime_error(format(
|
|
1867
|
+
"error: the supplied chat template is not supported: %s\n"
|
|
1868
|
+
"note: llama.cpp does not use jinja parser, we only support commonly used templates\n",
|
|
1869
|
+
value.c_str()
|
|
1870
|
+
));
|
|
1871
|
+
}
|
|
1872
|
+
params.chat_template = value;
|
|
1873
|
+
}
|
|
1874
|
+
).set_examples({LLAMA_EXAMPLE_MAIN, LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_CHAT_TEMPLATE"));
|
|
1875
|
+
add_opt(llama_arg(
|
|
1876
|
+
{"-sps", "--slot-prompt-similarity"}, "SIMILARITY",
|
|
1877
|
+
format("how much the prompt of a request must match the prompt of a slot in order to use that slot (default: %.2f, 0.0 = disabled)\n", params.slot_prompt_similarity),
|
|
1878
|
+
[](gpt_params & params, const std::string & value) {
|
|
1879
|
+
params.slot_prompt_similarity = std::stof(value);
|
|
1880
|
+
}
|
|
1881
|
+
).set_examples({LLAMA_EXAMPLE_SERVER}));
|
|
1882
|
+
add_opt(llama_arg(
|
|
1883
|
+
{"--lora-init-without-apply"},
|
|
1884
|
+
format("load LoRA adapters without applying them (apply later via POST /lora-adapters) (default: %s)", params.lora_init_without_apply ? "enabled" : "disabled"),
|
|
1885
|
+
[](gpt_params & params) {
|
|
1886
|
+
params.lora_init_without_apply = true;
|
|
1887
|
+
}
|
|
1888
|
+
).set_examples({LLAMA_EXAMPLE_SERVER}));
|
|
1889
|
+
add_opt(llama_arg(
|
|
1890
|
+
{"--simple-io"},
|
|
1891
|
+
"use basic IO for better compatibility in subprocesses and limited consoles",
|
|
1892
|
+
[](gpt_params & params) {
|
|
1893
|
+
params.simple_io = true;
|
|
1894
|
+
}
|
|
1895
|
+
).set_examples({LLAMA_EXAMPLE_MAIN, LLAMA_EXAMPLE_INFILL}));
|
|
1896
|
+
add_opt(llama_arg(
|
|
1897
|
+
{"-ld", "--logdir"}, "LOGDIR",
|
|
1898
|
+
"path under which to save YAML logs (no logging if unset)",
|
|
1899
|
+
[](gpt_params & params, const std::string & value) {
|
|
1900
|
+
params.logdir = value;
|
|
1901
|
+
|
|
1902
|
+
if (params.logdir.back() != DIRECTORY_SEPARATOR) {
|
|
1903
|
+
params.logdir += DIRECTORY_SEPARATOR;
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
));
|
|
1907
|
+
add_opt(llama_arg(
|
|
1908
|
+
{"--positive-file"}, "FNAME",
|
|
1909
|
+
format("positive prompts file, one prompt per line (default: '%s')", params.cvector_positive_file.c_str()),
|
|
1910
|
+
[](gpt_params & params, const std::string & value) {
|
|
1911
|
+
params.cvector_positive_file = value;
|
|
1912
|
+
}
|
|
1913
|
+
).set_examples({LLAMA_EXAMPLE_CVECTOR_GENERATOR}));
|
|
1914
|
+
add_opt(llama_arg(
|
|
1915
|
+
{"--negative-file"}, "FNAME",
|
|
1916
|
+
format("negative prompts file, one prompt per line (default: '%s')", params.cvector_negative_file.c_str()),
|
|
1917
|
+
[](gpt_params & params, const std::string & value) {
|
|
1918
|
+
params.cvector_negative_file = value;
|
|
1919
|
+
}
|
|
1920
|
+
).set_examples({LLAMA_EXAMPLE_CVECTOR_GENERATOR}));
|
|
1921
|
+
add_opt(llama_arg(
|
|
1922
|
+
{"--pca-batch"}, "N",
|
|
1923
|
+
format("batch size used for PCA. Larger batch runs faster, but uses more memory (default: %d)", params.n_pca_batch),
|
|
1924
|
+
[](gpt_params & params, int value) {
|
|
1925
|
+
params.n_pca_batch = value;
|
|
1926
|
+
}
|
|
1927
|
+
).set_examples({LLAMA_EXAMPLE_CVECTOR_GENERATOR}));
|
|
1928
|
+
add_opt(llama_arg(
|
|
1929
|
+
{"--pca-iter"}, "N",
|
|
1930
|
+
format("number of iterations used for PCA (default: %d)", params.n_pca_iterations),
|
|
1931
|
+
[](gpt_params & params, int value) {
|
|
1932
|
+
params.n_pca_iterations = value;
|
|
1933
|
+
}
|
|
1934
|
+
).set_examples({LLAMA_EXAMPLE_CVECTOR_GENERATOR}));
|
|
1935
|
+
add_opt(llama_arg(
|
|
1936
|
+
{"--method"}, "{pca, mean}",
|
|
1937
|
+
"dimensionality reduction method to be used (default: pca)",
|
|
1938
|
+
[](gpt_params & params, const std::string & value) {
|
|
1939
|
+
/**/ if (value == "pca") { params.cvector_dimre_method = DIMRE_METHOD_PCA; }
|
|
1940
|
+
else if (value == "mean") { params.cvector_dimre_method = DIMRE_METHOD_MEAN; }
|
|
1941
|
+
else { throw std::invalid_argument("invalid value"); }
|
|
1942
|
+
}
|
|
1943
|
+
).set_examples({LLAMA_EXAMPLE_CVECTOR_GENERATOR}));
|
|
1944
|
+
add_opt(llama_arg(
|
|
1945
|
+
{"--output-format"}, "{md,jsonl}",
|
|
1946
|
+
"output format for batched-bench results (default: md)",
|
|
1947
|
+
[](gpt_params & params, const std::string & value) {
|
|
1948
|
+
/**/ if (value == "jsonl") { params.batched_bench_output_jsonl = true; }
|
|
1949
|
+
else if (value == "md") { params.batched_bench_output_jsonl = false; }
|
|
1950
|
+
else { std::invalid_argument("invalid value"); }
|
|
1951
|
+
}
|
|
1952
|
+
).set_examples({LLAMA_EXAMPLE_BENCH}));
|
|
1953
|
+
add_opt(llama_arg(
|
|
1954
|
+
{"--log-disable"},
|
|
1955
|
+
"Log disable",
|
|
1956
|
+
[](gpt_params &) {
|
|
1957
|
+
gpt_log_pause(gpt_log_main());
|
|
1958
|
+
}
|
|
1959
|
+
));
|
|
1960
|
+
add_opt(llama_arg(
|
|
1961
|
+
{"--log-file"}, "FNAME",
|
|
1962
|
+
"Log to file",
|
|
1963
|
+
[](gpt_params &, const std::string & value) {
|
|
1964
|
+
gpt_log_set_file(gpt_log_main(), value.c_str());
|
|
1965
|
+
}
|
|
1966
|
+
));
|
|
1967
|
+
add_opt(llama_arg(
|
|
1968
|
+
{"--log-colors"},
|
|
1969
|
+
"Enable colored logging",
|
|
1970
|
+
[](gpt_params &) {
|
|
1971
|
+
gpt_log_set_colors(gpt_log_main(), true);
|
|
1972
|
+
}
|
|
1973
|
+
).set_env("LLAMA_LOG_COLORS"));
|
|
1974
|
+
add_opt(llama_arg(
|
|
1975
|
+
{"-v", "--verbose", "--log-verbose"},
|
|
1976
|
+
"Set verbosity level to infinity (i.e. log all messages, useful for debugging)",
|
|
1977
|
+
[](gpt_params & params) {
|
|
1978
|
+
params.verbosity = INT_MAX;
|
|
1979
|
+
gpt_log_set_verbosity_thold(INT_MAX);
|
|
1980
|
+
}
|
|
1981
|
+
));
|
|
1982
|
+
add_opt(llama_arg(
|
|
1983
|
+
{"-lv", "--verbosity", "--log-verbosity"}, "N",
|
|
1984
|
+
"Set the verbosity threshold. Messages with a higher verbosity will be ignored.",
|
|
1985
|
+
[](gpt_params & params, int value) {
|
|
1986
|
+
params.verbosity = value;
|
|
1987
|
+
gpt_log_set_verbosity_thold(value);
|
|
1988
|
+
}
|
|
1989
|
+
).set_env("LLAMA_LOG_VERBOSITY"));
|
|
1990
|
+
add_opt(llama_arg(
|
|
1991
|
+
{"--log-prefix"},
|
|
1992
|
+
"Enable prefx in log messages",
|
|
1993
|
+
[](gpt_params &) {
|
|
1994
|
+
gpt_log_set_prefix(gpt_log_main(), true);
|
|
1995
|
+
}
|
|
1996
|
+
).set_env("LLAMA_LOG_PREFIX"));
|
|
1997
|
+
add_opt(llama_arg(
|
|
1998
|
+
{"--log-timestamps"},
|
|
1999
|
+
"Enable timestamps in log messages",
|
|
2000
|
+
[](gpt_params &) {
|
|
2001
|
+
gpt_log_set_timestamps(gpt_log_main(), true);
|
|
2002
|
+
}
|
|
2003
|
+
).set_env("LLAMA_LOG_TIMESTAMPS"));
|
|
2004
|
+
|
|
2005
|
+
return ctx_arg;
|
|
2006
|
+
}
|