Replace size check with empty

This commit is contained in:
Michael Klimenko 2024-01-27 21:23:27 +01:00
parent c3fe181c44
commit e41d94972c
7 changed files with 19 additions and 19 deletions

View file

@ -850,7 +850,7 @@ size_t tokenize_file(
utf8_nunits.resize(buf.size()); utf8_nunits.resize(buf.size());
mark_utf8_units(buf.data(), utf8_units.data(), utf8_nunits.data(), 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 // tokenize all data at once
out_tokens.resize(buf.size() + n_max_tokens_overhead); 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(); const size_t search_start = sample_begin + sample_start.size();
sample_begin = data_str.find(sample_start, search_start); 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", printf("%s: warning: sample start pattern '%s' not found. inserting single sample at data begin\n",
__func__, sample_start.c_str()); __func__, sample_start.c_str());
out_samples_begin.push_back(0); out_samples_begin.push_back(0);

View file

@ -376,7 +376,7 @@ static void export_lora(struct export_lora_params * params) {
loras.push_back(lora); loras.push_back(lora);
} }
} }
if (loras.size() == 0) { if (loras.empty()) {
fprintf(stderr, "warning: no lora adapters will be applied.\n"); fprintf(stderr, "warning: no lora adapters will be applied.\n");
} }

View file

@ -1835,7 +1835,7 @@ int main(int argc, char ** argv) {
if (params.common.force_reshuffle) { if (params.common.force_reshuffle) {
printf("%s: forced reshuffling of data. restarting with newly shuffled epoch.\n", __func__); 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_rng_state_current = mt19937_seed_to_state(params.common.seed);
train->shuffle_sample_count = train_samples_size.size(); train->shuffle_sample_count = train_samples_size.size();
train->shuffle_next_sample = 0; train->shuffle_next_sample = 0;

View file

@ -6941,7 +6941,7 @@ inline ContentProviderWithoutLength ClientImpl::get_multipart_content_provider(
// state between successive calls // state between successive calls
return [&, cur_item, cur_start](size_t offset, return [&, cur_item, cur_start](size_t offset,
DataSink &sink) mutable -> bool { DataSink &sink) mutable -> bool {
if (!offset && items.size()) { if (!offset && !items.empty()) {
sink.os << detail::serialize_multipart_formdata(items, boundary, false); sink.os << detail::serialize_multipart_formdata(items, boundary, false);
return true; return true;
} else if (cur_item < provider_items.size()) { } else if (cur_item < provider_items.size()) {

View file

@ -649,7 +649,7 @@ struct llama_server_context
} }
// process prompt // 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 '}]} // 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<std::string>(); std::string prompt = slot->prompt.get<std::string>();
size_t pos = 0, begin_prefix = 0; size_t pos = 0, begin_prefix = 0;
@ -758,7 +758,7 @@ struct llama_server_context
name_user = sys_props.value("anti_prompt", ""); name_user = sys_props.value("anti_prompt", "");
name_assistant = sys_props.value("assistant_name", ""); name_assistant = sys_props.value("assistant_name", "");
if (slots.size() > 0) if (!slots.empty())
{ {
notify_system_prompt_changed(); notify_system_prompt_changed();
} }
@ -944,7 +944,7 @@ struct llama_server_context
img.request_encode_image = false; img.request_encode_image = false;
} }
return slot.images.size() > 0; return !slot.images.empty();
} }
void send_error(task_server& task, const std::string &error) 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; std::string key;
while (std::getline(key_file, key)) { while (std::getline(key_file, key)) {
if (key.size() > 0) { if (!key.empty()) {
sparams.api_keys.push_back(key); sparams.api_keys.push_back(key);
} }
} }

View file

@ -1200,7 +1200,7 @@ int main(int argc, char ** argv) {
if (params.common.force_reshuffle) { if (params.common.force_reshuffle) {
printf("%s: forced reshuffling of data. restarting with newly shuffled epoch.\n", __func__); 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_rng_state_current = mt19937_seed_to_state(params.common.seed);
train->shuffle_sample_count = train_samples_size.size(); train->shuffle_sample_count = train_samples_size.size();
train->shuffle_next_sample = 0; train->shuffle_next_sample = 0;

View file

@ -3015,7 +3015,7 @@ static void llm_load_vocab(
for (int i = 0; i < n_merges; i++) { for (int i = 0; i < n_merges; i++) {
const std::string word = gguf_get_arr_str(ctx, merges_keyidx, 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 first;
std::string second; std::string second;
@ -3050,7 +3050,7 @@ static void llm_load_vocab(
for (uint32_t i = 0; i < n_vocab; i++) { for (uint32_t i = 0; i < n_vocab; i++) {
std::string word = gguf_get_arr_str(ctx, token_idx, 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; vocab.token_to_id[word] = i;
@ -7190,7 +7190,7 @@ private:
split_condition = true; split_condition = true;
} }
if (split_condition) { if (split_condition) {
if (token.size()) { if (!token.empty()) {
bpe_words.emplace_back(token); // push previous content as token bpe_words.emplace_back(token); // push previous content as token
} }
token = utf_char + utf_char_next; token = utf_char + utf_char_next;
@ -7211,7 +7211,7 @@ private:
} }
if (split_condition) { if (split_condition) {
// current token + next token can be defined // current token + next token can be defined
if (token.size()) { if (!token.empty()) {
bpe_words.emplace_back(token); // push previous content as token bpe_words.emplace_back(token); // push previous content as token
} }
token = utf_char + utf_char_next + utf_char_next_next; token = utf_char + utf_char_next + utf_char_next_next;
@ -7223,17 +7223,17 @@ private:
} }
if (!split_condition && !collecting) { 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_letter = true;
collecting = 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_numeric = true;
collecting = true; collecting = true;
} }
else if ( else if (
((codepoint_type(utf_char) != CODEPOINT_TYPE_LETTER && codepoint_type(utf_char) != CODEPOINT_TYPE_DIGIT) && (codepoint_type(utf_char) != CODEPOINT_TYPE_WHITESPACE)) || ((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_special = true;
collecting = true; collecting = true;
@ -7261,13 +7261,13 @@ private:
} }
} }
if (utf_char_next == "") { if (utf_char_next.empty()) {
split_condition = true; // final split_condition = true; // final
token += utf_char; token += utf_char;
} }
if (split_condition) { if (split_condition) {
if (token.size()) { if (!token.empty()) {
bpe_words.emplace_back(token); bpe_words.emplace_back(token);
} }
token = utf_char; token = utf_char;