Made algorithm safer and more readable

This commit is contained in:
MaggotHATE 2024-10-11 15:36:25 +05:00
parent 3968369071
commit acada1a5e7

View file

@ -1107,15 +1107,18 @@ static void llama_sample_xtc_apply(struct llama_sampler * smpl, llama_token_data
} }
} }
size_t to_remove = pos_last - (1 + pos_first); int to_remove = pos_last - (1 + pos_first);
if (cur_p->size - to_remove < ctx->min_keep || to_remove < 1) return; if (cur_p->size - to_remove >= ctx->min_keep && to_remove > 0) {
for (size_t i = pos_first + 1; i < cur_p->size - to_remove + 1; ++i) { size_t last_idx = cur_p->size - to_remove;
for (size_t i = pos_first + 1; i <= last_idx; ++i) {
cur_p->data[i] = cur_p->data[i + to_remove]; cur_p->data[i] = cur_p->data[i + to_remove];
} }
cur_p->size = cur_p->size - to_remove; cur_p->size = cur_p->size - to_remove;
}
} }
static struct llama_sampler * llama_sampler_xtc_clone(const struct llama_sampler * smpl) { static struct llama_sampler * llama_sampler_xtc_clone(const struct llama_sampler * smpl) {