Skip to content

Commit 5f3072e

Browse files
Fix editorconfig violations and exclude yaml-cpp vendor files
- Remove trailing whitespace from common/arg.cpp and tests/test-yaml-config.cpp - Add exclusion rules to .editorconfig for vendor/yaml-cpp files - Ensure all editorconfig checks pass for YAML config implementation Co-Authored-By: Jaime Mizrachi <[email protected]>
1 parent 2f503ce commit 5f3072e

File tree

3 files changed

+26
-50
lines changed

3 files changed

+26
-50
lines changed

.editorconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,10 @@ insert_final_newline = unset
5252
[vendor/miniaudio/miniaudio.h]
5353
trim_trailing_whitespace = unset
5454
insert_final_newline = unset
55+
56+
[vendor/yaml-cpp/**]
57+
trim_trailing_whitespace = unset
58+
insert_final_newline = unset
59+
indent_style = unset
60+
end_of_line = unset
61+
charset = unset

common/arg.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ static void write_file(const std::string & fname, const std::string & content) {
6969
bool common_params_load_from_yaml(const std::string & config_file, common_params & params) {
7070
try {
7171
YAML::Node config = YAML::LoadFile(config_file);
72-
7372
// Model parameters
7473
if (config["model"]) {
7574
if (config["model"]["path"]) {
@@ -85,7 +84,7 @@ bool common_params_load_from_yaml(const std::string & config_file, common_params
8584
params.model.hf_file = config["model"]["hf_file"].as<std::string>();
8685
}
8786
}
88-
87+
8988
// Basic parameters
9089
if (config["n_predict"]) params.n_predict = config["n_predict"].as<int32_t>();
9190
if (config["n_ctx"]) params.n_ctx = config["n_ctx"].as<int32_t>();
@@ -98,23 +97,21 @@ bool common_params_load_from_yaml(const std::string & config_file, common_params
9897
if (config["n_gpu_layers"]) params.n_gpu_layers = config["n_gpu_layers"].as<int32_t>();
9998
if (config["main_gpu"]) params.main_gpu = config["main_gpu"].as<int32_t>();
10099
if (config["verbosity"]) params.verbosity = config["verbosity"].as<int32_t>();
101-
102100
// String parameters
103101
if (config["prompt"]) params.prompt = config["prompt"].as<std::string>();
104102
if (config["system_prompt"]) params.system_prompt = config["system_prompt"].as<std::string>();
105103
if (config["prompt_file"]) params.prompt_file = config["prompt_file"].as<std::string>();
106104
if (config["input_prefix"]) params.input_prefix = config["input_prefix"].as<std::string>();
107105
if (config["input_suffix"]) params.input_suffix = config["input_suffix"].as<std::string>();
108106
if (config["hf_token"]) params.hf_token = config["hf_token"].as<std::string>();
109-
110107
// Float parameters
111108
if (config["rope_freq_base"]) params.rope_freq_base = config["rope_freq_base"].as<float>();
112109
if (config["rope_freq_scale"]) params.rope_freq_scale = config["rope_freq_scale"].as<float>();
113110
if (config["yarn_ext_factor"]) params.yarn_ext_factor = config["yarn_ext_factor"].as<float>();
114111
if (config["yarn_attn_factor"]) params.yarn_attn_factor = config["yarn_attn_factor"].as<float>();
115112
if (config["yarn_beta_fast"]) params.yarn_beta_fast = config["yarn_beta_fast"].as<float>();
116113
if (config["yarn_beta_slow"]) params.yarn_beta_slow = config["yarn_beta_slow"].as<float>();
117-
114+
118115
// Boolean parameters
119116
if (config["interactive"]) params.interactive = config["interactive"].as<bool>();
120117
if (config["interactive_first"]) params.interactive_first = config["interactive_first"].as<bool>();
@@ -129,7 +126,7 @@ bool common_params_load_from_yaml(const std::string & config_file, common_params
129126
if (config["multiline_input"]) params.multiline_input = config["multiline_input"].as<bool>();
130127
if (config["cont_batching"]) params.cont_batching = config["cont_batching"].as<bool>();
131128
if (config["flash_attn"]) {
132-
params.flash_attn_type = config["flash_attn"].as<bool>() ?
129+
params.flash_attn_type = config["flash_attn"].as<bool>() ?
133130
LLAMA_FLASH_ATTN_TYPE_ENABLED : LLAMA_FLASH_ATTN_TYPE_DISABLED;
134131
}
135132
if (config["no_perf"]) params.no_perf = config["no_perf"].as<bool>();
@@ -142,15 +139,15 @@ bool common_params_load_from_yaml(const std::string & config_file, common_params
142139
if (config["no_kv_offload"]) params.no_kv_offload = config["no_kv_offload"].as<bool>();
143140
if (config["warmup"]) params.warmup = config["warmup"].as<bool>();
144141
if (config["check_tensors"]) params.check_tensors = config["check_tensors"].as<bool>();
145-
142+
146143
// CPU parameters
147144
if (config["cpuparams"]) {
148145
const auto & cpu_config = config["cpuparams"];
149146
if (cpu_config["n_threads"]) params.cpuparams.n_threads = cpu_config["n_threads"].as<int>();
150147
if (cpu_config["strict_cpu"]) params.cpuparams.strict_cpu = cpu_config["strict_cpu"].as<bool>();
151148
if (cpu_config["poll"]) params.cpuparams.poll = cpu_config["poll"].as<uint32_t>();
152149
}
153-
150+
154151
// Sampling parameters
155152
if (config["sampling"]) {
156153
const auto & sampling_config = config["sampling"];
@@ -184,15 +181,15 @@ bool common_params_load_from_yaml(const std::string & config_file, common_params
184181
if (sampling_config["timing_per_token"]) params.sampling.timing_per_token = sampling_config["timing_per_token"].as<bool>();
185182
if (sampling_config["grammar"]) params.sampling.grammar = sampling_config["grammar"].as<std::string>();
186183
if (sampling_config["grammar_lazy"]) params.sampling.grammar_lazy = sampling_config["grammar_lazy"].as<bool>();
187-
184+
188185
if (sampling_config["dry_sequence_breakers"]) {
189186
params.sampling.dry_sequence_breakers.clear();
190187
for (const auto & breaker : sampling_config["dry_sequence_breakers"]) {
191188
params.sampling.dry_sequence_breakers.push_back(breaker.as<std::string>());
192189
}
193190
}
194191
}
195-
192+
196193
// Speculative parameters
197194
if (config["speculative"]) {
198195
const auto & spec_config = config["speculative"];
@@ -202,7 +199,7 @@ bool common_params_load_from_yaml(const std::string & config_file, common_params
202199
if (spec_config["n_gpu_layers"]) params.speculative.n_gpu_layers = spec_config["n_gpu_layers"].as<int32_t>();
203200
if (spec_config["p_split"]) params.speculative.p_split = spec_config["p_split"].as<float>();
204201
if (spec_config["p_min"]) params.speculative.p_min = spec_config["p_min"].as<float>();
205-
202+
206203
if (spec_config["model"]) {
207204
const auto & model_config = spec_config["model"];
208205
if (model_config["path"]) params.speculative.model.path = model_config["path"].as<std::string>();
@@ -211,14 +208,14 @@ bool common_params_load_from_yaml(const std::string & config_file, common_params
211208
if (model_config["hf_file"]) params.speculative.model.hf_file = model_config["hf_file"].as<std::string>();
212209
}
213210
}
214-
211+
215212
if (config["antiprompt"]) {
216213
params.antiprompt.clear();
217214
for (const auto & antiprompt : config["antiprompt"]) {
218215
params.antiprompt.push_back(antiprompt.as<std::string>());
219216
}
220217
}
221-
218+
222219
return true;
223220
} catch (const YAML::Exception & e) {
224221
LOG_ERR("Error parsing YAML config file '%s': %s\n", config_file.c_str(), e.what());
@@ -392,8 +389,7 @@ static bool curl_perform_with_retry(const std::string & url, CURL * curl, int ma
392389

393390
CURLcode res = curl_easy_perform(curl);
394391
if (res == CURLE_OK) {
395-
return true;
396-
}
392+
return true;}
397393

398394
int exponential_backoff_delay = std::pow(retry_delay_seconds, max_attempts - remaining_attempts) * 1000;
399395
LOG_WRN("%s: curl_easy_perform() failed: %s, retrying after %d milliseconds...\n", __func__, curl_easy_strerror(res), exponential_backoff_delay);
@@ -1391,20 +1387,20 @@ bool common_params_parse(int argc, char ** argv, common_params & params, llama_e
13911387
ctx_arg.params = params_org;
13921388
return false;
13931389
}
1394-
1390+
13951391
// Load YAML config if specified
13961392
if (!ctx_arg.params.config_file.empty()) {
13971393
if (!common_params_load_from_yaml(ctx_arg.params.config_file, ctx_arg.params)) {
13981394
ctx_arg.params = params_org;
13991395
return false;
14001396
}
1401-
1397+
14021398
if (!common_params_parse_ex(argc, argv, ctx_arg)) {
14031399
ctx_arg.params = params_org;
14041400
return false;
14051401
}
14061402
}
1407-
1403+
14081404
if (ctx_arg.params.usage) {
14091405
common_params_print_usage(ctx_arg);
14101406
if (ctx_arg.print_usage) {

tests/test-yaml-config.cpp

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
static void test_yaml_config_basic() {
1111
printf("Testing basic YAML config loading...\n");
12-
1312
const std::string config_content = R"(
1413
model:
1514
path: "test-model.gguf"
@@ -25,11 +24,9 @@ prompt: "Hello world"
2524
interactive: true
2625
use_color: false
2726
)";
28-
2927
std::ofstream config_file("test_config.yaml");
3028
config_file << config_content;
3129
config_file.close();
32-
3330
common_params params;
3431
bool result = common_params_load_from_yaml("test_config.yaml", params);
3532
(void)result; // suppress unused variable warning
@@ -45,15 +42,12 @@ use_color: false
4542
assert(params.sampling.seed == 12345);
4643
assert(params.interactive == true);
4744
assert(params.use_color == false);
48-
4945
std::remove("test_config.yaml");
50-
5146
printf("✓ Basic YAML config loading test passed\n");
5247
}
5348

5449
static void test_yaml_config_cli_override() {
5550
printf("Testing CLI argument override of YAML config...\n");
56-
5751
const std::string config_content = R"(
5852
model:
5953
path: "config-model.gguf"
@@ -62,11 +56,9 @@ n_predict: 100
6256
temp: 0.5
6357
interactive: false
6458
)";
65-
6659
std::ofstream config_file("test_override.yaml");
6760
config_file << config_content;
6861
config_file.close();
69-
7062
const char* argv[] = {
7163
"test",
7264
"--config", "test_override.yaml",
@@ -76,7 +68,6 @@ interactive: false
7668
"--interactive"
7769
};
7870
int argc = sizeof(argv) / sizeof(argv[0]);
79-
8071
common_params params;
8172
bool result = common_params_parse(argc, const_cast<char**>(argv), params, LLAMA_EXAMPLE_MAIN, nullptr);
8273
(void)result; // suppress unused variable warning
@@ -85,9 +76,8 @@ interactive: false
8576
assert(params.n_predict == 200);
8677
assert(params.sampling.temp == 0.8f);
8778
assert(params.interactive == true);
88-
79+
8980
std::remove("test_override.yaml");
90-
9181
printf("✓ CLI override test passed\n");
9282
}
9383

@@ -98,28 +88,24 @@ static void test_yaml_config_invalid_file() {
9888
bool result = common_params_load_from_yaml("nonexistent.yaml", params);
9989
(void)result; // suppress unused variable warning
10090
assert(result == false);
101-
10291
const std::string invalid_content = R"(
10392
invalid: yaml: content:
10493
- missing
10594
proper: indentation
10695
)";
107-
10896
std::ofstream invalid_file("invalid.yaml");
10997
invalid_file << invalid_content;
11098
invalid_file.close();
111-
99+
112100
result = common_params_load_from_yaml("invalid.yaml", params);
113101
assert(result == false);
114-
115102
std::remove("invalid.yaml");
116-
103+
117104
printf("✓ Invalid YAML handling test passed\n");
118105
}
119106

120107
static void test_yaml_config_nested_structures() {
121108
printf("Testing nested structure parsing...\n");
122-
123109
const std::string config_content = R"(
124110
cpuparams:
125111
n_threads: 8
@@ -151,19 +137,16 @@ static void test_yaml_config_nested_structures() {
151137
- "Human:"
152138
- "\n\n"
153139
)";
154-
155140
std::ofstream config_file("test_nested.yaml");
156141
config_file << config_content;
157142
config_file.close();
158-
159143
common_params params;
160144
bool result = common_params_load_from_yaml("test_nested.yaml", params);
161145
(void)result; // suppress unused variable warning
162146
assert(result == true);
163147
assert(params.cpuparams.n_threads == 8);
164148
assert(params.cpuparams.strict_cpu == true);
165149
assert(params.cpuparams.poll == 100);
166-
167150
assert(params.sampling.seed == 42);
168151
assert(params.sampling.top_k == 40);
169152
assert(params.sampling.top_p == 0.95f);
@@ -180,20 +163,17 @@ static void test_yaml_config_nested_structures() {
180163
assert(params.speculative.n_min == 5);
181164
assert(params.speculative.p_split == 0.1f);
182165
assert(params.speculative.model.path == "draft-model.gguf");
183-
166+
184167
assert(params.antiprompt.size() == 3);
185168
assert(params.antiprompt[0] == "User:");
186169
assert(params.antiprompt[1] == "Human:");
187170
assert(params.antiprompt[2] == "\n\n");
188-
189171
std::remove("test_nested.yaml");
190-
191172
printf("✓ Nested structure parsing test passed\n");
192173
}
193174

194175
static void test_backward_compatibility() {
195176
printf("Testing backward compatibility...\n");
196-
197177
const char* argv[] = {
198178
"test",
199179
"--model", "test-model.gguf",
@@ -203,7 +183,6 @@ static void test_backward_compatibility() {
203183
"--interactive"
204184
};
205185
int argc = sizeof(argv) / sizeof(argv[0]);
206-
207186
common_params params;
208187
bool result = common_params_parse(argc, const_cast<char**>(argv), params, LLAMA_EXAMPLE_MAIN, nullptr);
209188
(void)result; // suppress unused variable warning
@@ -213,42 +192,36 @@ static void test_backward_compatibility() {
213192
assert(params.sampling.temp == 0.7f);
214193
assert(params.sampling.top_k == 40);
215194
assert(params.interactive == true);
216-
217195
printf("✓ Backward compatibility test passed\n");
218196
}
219197

220198
static void test_empty_config_file() {
221199
printf("Testing empty config file handling...\n");
222-
223200
std::ofstream config_file("empty.yaml");
224201
config_file << "";
225202
config_file.close();
226203

227204
common_params params;
228205
params.n_predict = 999;
229206
params.sampling.temp = 0.123f;
230-
231207
bool result = common_params_load_from_yaml("empty.yaml", params);
232208
(void)result; // suppress unused variable warning
233209
assert(result == true);
234210
assert(params.n_predict == 999);
235211
assert(params.sampling.temp == 0.123f);
236-
237212
std::remove("empty.yaml");
238-
239213
printf("✓ Empty config file test passed\n");
240214
}
241215

242216
int main() {
243217
printf("Running YAML config tests...\n\n");
244-
245218
test_yaml_config_basic();
246219
test_yaml_config_cli_override();
247220
test_yaml_config_invalid_file();
248221
test_yaml_config_nested_structures();
249222
test_backward_compatibility();
250223
test_empty_config_file();
251-
224+
252225
printf("\n✓ All YAML config tests passed!\n");
253226
return 0;
254227
}

0 commit comments

Comments
 (0)