diff --git a/common/train.cpp b/common/train.cpp index bab9bcc0b..b309808b5 100644 --- a/common/train.cpp +++ b/common/train.cpp @@ -850,7 +850,7 @@ size_t tokenize_file( utf8_nunits.resize(buf.size()); mark_utf8_units(buf.data(), utf8_units.data(), utf8_nunits.data(), buf.size()); - if (sample_start.size() == 0) { + if (sample_start.empty()) { // tokenize all data at once out_tokens.resize(buf.size() + n_max_tokens_overhead); @@ -898,7 +898,7 @@ size_t tokenize_file( const size_t search_start = sample_begin + sample_start.size(); sample_begin = data_str.find(sample_start, search_start); } - if (out_samples_begin.size() == 0) { + if (out_samples_begin.empty()) { printf("%s: warning: sample start pattern '%s' not found. inserting single sample at data begin\n", __func__, sample_start.c_str()); out_samples_begin.push_back(0); diff --git a/examples/export-lora/export-lora.cpp b/examples/export-lora/export-lora.cpp index 4cd5d99bb..14a4e97d8 100644 --- a/examples/export-lora/export-lora.cpp +++ b/examples/export-lora/export-lora.cpp @@ -376,7 +376,7 @@ static void export_lora(struct export_lora_params * params) { loras.push_back(lora); } } - if (loras.size() == 0) { + if (loras.empty()) { fprintf(stderr, "warning: no lora adapters will be applied.\n"); } diff --git a/examples/finetune/finetune.cpp b/examples/finetune/finetune.cpp index b7e19c5fe..2a326a2c4 100644 --- a/examples/finetune/finetune.cpp +++ b/examples/finetune/finetune.cpp @@ -1835,7 +1835,7 @@ int main(int argc, char ** argv) { if (params.common.force_reshuffle) { printf("%s: forced reshuffling of data. restarting with newly shuffled epoch.\n", __func__); } - if ((train->shuffle_rng_state_current == "") || changed_train_data || params.common.force_reshuffle) { + if ((train->shuffle_rng_state_current.empty()) || changed_train_data || params.common.force_reshuffle) { train->shuffle_rng_state_current = mt19937_seed_to_state(params.common.seed); train->shuffle_sample_count = train_samples_size.size(); train->shuffle_next_sample = 0; diff --git a/examples/server/httplib.h b/examples/server/httplib.h index 28746000c..e495d8299 100644 --- a/examples/server/httplib.h +++ b/examples/server/httplib.h @@ -6941,7 +6941,7 @@ inline ContentProviderWithoutLength ClientImpl::get_multipart_content_provider( // state between successive calls return [&, cur_item, cur_start](size_t offset, DataSink &sink) mutable -> bool { - if (!offset && items.size()) { + if (!offset && !items.empty()) { sink.os << detail::serialize_multipart_formdata(items, boundary, false); return true; } else if (cur_item < provider_items.size()) { diff --git a/examples/server/server.cpp b/examples/server/server.cpp index f97e5e415..7dcb5950d 100644 --- a/examples/server/server.cpp +++ b/examples/server/server.cpp @@ -649,7 +649,7 @@ struct llama_server_context } // process prompt // example: system prompt [img-102] user [img-103] describe [img-134] -> [{id: 102, prefix: 'system prompt '}, {id: 103, prefix: ' user '}, {id: 134, prefix: ' describe '}]} - if (slot->images.size() > 0 && !slot->prompt.is_array()) + if (!slot->images.empty() && !slot->prompt.is_array()) { std::string prompt = slot->prompt.get(); size_t pos = 0, begin_prefix = 0; @@ -758,7 +758,7 @@ struct llama_server_context name_user = sys_props.value("anti_prompt", ""); name_assistant = sys_props.value("assistant_name", ""); - if (slots.size() > 0) + if (!slots.empty()) { notify_system_prompt_changed(); } @@ -944,7 +944,7 @@ struct llama_server_context img.request_encode_image = false; } - return slot.images.size() > 0; + return !slot.images.empty(); } void send_error(task_server& task, const std::string &error) @@ -1794,7 +1794,7 @@ static void server_params_parse(int argc, char **argv, server_params &sparams, } std::string key; while (std::getline(key_file, key)) { - if (key.size() > 0) { + if (!key.empty()) { sparams.api_keys.push_back(key); } } diff --git a/examples/train-text-from-scratch/train-text-from-scratch.cpp b/examples/train-text-from-scratch/train-text-from-scratch.cpp index eee9d4de3..49eaf3e61 100644 --- a/examples/train-text-from-scratch/train-text-from-scratch.cpp +++ b/examples/train-text-from-scratch/train-text-from-scratch.cpp @@ -1200,7 +1200,7 @@ int main(int argc, char ** argv) { if (params.common.force_reshuffle) { printf("%s: forced reshuffling of data. restarting with newly shuffled epoch.\n", __func__); } - if ((train->shuffle_rng_state_current == "") || changed_train_data || params.common.force_reshuffle) { + if ((train->shuffle_rng_state_current.empty()) || changed_train_data || params.common.force_reshuffle) { train->shuffle_rng_state_current = mt19937_seed_to_state(params.common.seed); train->shuffle_sample_count = train_samples_size.size(); train->shuffle_next_sample = 0; diff --git a/llama.cpp b/llama.cpp index 31482069c..096eb4ac0 100644 --- a/llama.cpp +++ b/llama.cpp @@ -3015,7 +3015,7 @@ static void llm_load_vocab( for (int i = 0; i < n_merges; i++) { const std::string word = gguf_get_arr_str(ctx, merges_keyidx, i); - GGML_ASSERT(codepoints_from_utf8(word).size() > 0); + GGML_ASSERT(!codepoints_from_utf8(word).empty()); std::string first; std::string second; @@ -3050,7 +3050,7 @@ static void llm_load_vocab( for (uint32_t i = 0; i < n_vocab; i++) { std::string word = gguf_get_arr_str(ctx, token_idx, i); - GGML_ASSERT(codepoints_from_utf8(word).size() > 0); + GGML_ASSERT(!codepoints_from_utf8(word).empty()); vocab.token_to_id[word] = i; @@ -7190,7 +7190,7 @@ private: split_condition = true; } if (split_condition) { - if (token.size()) { + if (!token.empty()) { bpe_words.emplace_back(token); // push previous content as token } token = utf_char + utf_char_next; @@ -7211,7 +7211,7 @@ private: } if (split_condition) { // current token + next token can be defined - if (token.size()) { + if (!token.empty()) { bpe_words.emplace_back(token); // push previous content as token } token = utf_char + utf_char_next + utf_char_next_next; @@ -7223,17 +7223,17 @@ private: } if (!split_condition && !collecting) { - if (codepoint_type(utf_char) == CODEPOINT_TYPE_LETTER || (!token.size() && utf_char == " " && codepoint_type(utf_char_next) == CODEPOINT_TYPE_LETTER)) { + if (codepoint_type(utf_char) == CODEPOINT_TYPE_LETTER || (token.empty() && utf_char == " " && codepoint_type(utf_char_next) == CODEPOINT_TYPE_LETTER)) { collecting_letter = true; collecting = true; } - else if (codepoint_type(utf_char) == CODEPOINT_TYPE_DIGIT || (!token.size() && utf_char == " " && codepoint_type(utf_char_next) == CODEPOINT_TYPE_DIGIT)) { + else if (codepoint_type(utf_char) == CODEPOINT_TYPE_DIGIT || (token.empty() && utf_char == " " && codepoint_type(utf_char_next) == CODEPOINT_TYPE_DIGIT)) { collecting_numeric = true; collecting = true; } else if ( ((codepoint_type(utf_char) != CODEPOINT_TYPE_LETTER && codepoint_type(utf_char) != CODEPOINT_TYPE_DIGIT) && (codepoint_type(utf_char) != CODEPOINT_TYPE_WHITESPACE)) || - (!token.size() && utf_char == " " && codepoint_type(utf_char_next) != CODEPOINT_TYPE_LETTER && codepoint_type(utf_char_next) != CODEPOINT_TYPE_DIGIT && codepoint_type(utf_char_next) != CODEPOINT_TYPE_WHITESPACE) + (token.empty() && utf_char == " " && codepoint_type(utf_char_next) != CODEPOINT_TYPE_LETTER && codepoint_type(utf_char_next) != CODEPOINT_TYPE_DIGIT && codepoint_type(utf_char_next) != CODEPOINT_TYPE_WHITESPACE) ) { collecting_special = true; collecting = true; @@ -7261,13 +7261,13 @@ private: } } - if (utf_char_next == "") { + if (utf_char_next.empty()) { split_condition = true; // final token += utf_char; } if (split_condition) { - if (token.size()) { + if (!token.empty()) { bpe_words.emplace_back(token); } token = utf_char;