cont : fixes, naming [no ci]
This commit is contained in:
parent
cf4dd10ea5
commit
1b07dc51c6
3 changed files with 39 additions and 33 deletions
|
@ -665,7 +665,9 @@ static struct llama_constraint_i llama_constraint_top_k_i = {
|
||||||
*ctx_dst = *ctx_src;
|
*ctx_dst = *ctx_src;
|
||||||
},
|
},
|
||||||
/* .free = */ [](struct llama_constraint * cnstr) {
|
/* .free = */ [](struct llama_constraint * cnstr) {
|
||||||
delete (llama_constraint_context_top_k *) cnstr->ctx;
|
if (cnstr->ctx) {
|
||||||
|
delete (llama_constraint_context_top_k *) cnstr->ctx;
|
||||||
|
}
|
||||||
delete cnstr;
|
delete cnstr;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -700,7 +702,9 @@ static struct llama_constraint_i llama_constraint_top_p_i = {
|
||||||
*ctx_dst = *ctx_src;
|
*ctx_dst = *ctx_src;
|
||||||
},
|
},
|
||||||
/* .free = */ [](struct llama_constraint * cnstr) {
|
/* .free = */ [](struct llama_constraint * cnstr) {
|
||||||
delete (llama_constraint_context_top_p *) cnstr->ctx;
|
if (cnstr->ctx) {
|
||||||
|
delete (llama_constraint_context_top_p *) cnstr->ctx;
|
||||||
|
}
|
||||||
delete cnstr;
|
delete cnstr;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -714,26 +718,26 @@ struct llama_constraint * llama_constraint_init_top_p_impl(float p, size_t min_k
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void llama_constraint_free_impl(struct llama_constraint * constraint) {
|
void llama_constraint_free_impl(struct llama_constraint * cnstr) {
|
||||||
if (constraint->iface->free) {
|
if (cnstr->iface->free && cnstr) {
|
||||||
constraint->iface->free(constraint);
|
cnstr->iface->free(cnstr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void llama_constraint_accept_impl(struct llama_constraint * constraint, llama_token token) {
|
void llama_constraint_accept_impl(struct llama_constraint & cnstr, llama_token token) {
|
||||||
if (constraint->iface->accept) {
|
if (cnstr.iface->accept) {
|
||||||
constraint->iface->accept(constraint, token);
|
cnstr.iface->accept(&cnstr, token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void llama_constraint_apply_impl(struct llama_constraint * constraint, struct llama_token_data_array * candidates) {
|
void llama_constraint_apply_impl(struct llama_constraint & cnstr, struct llama_token_data_array * candidates) {
|
||||||
GGML_ASSERT(constraint->iface->apply);
|
GGML_ASSERT(cnstr.iface->apply);
|
||||||
constraint->iface->apply(constraint, candidates);
|
cnstr.iface->apply(&cnstr, candidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
void llama_constraint_reset_impl(struct llama_constraint * constraint) {
|
void llama_constraint_reset_impl(struct llama_constraint & cnstr) {
|
||||||
if (constraint->iface->reset) {
|
if (cnstr.iface->reset) {
|
||||||
constraint->iface->reset(constraint);
|
cnstr.iface->reset(&cnstr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -754,8 +758,8 @@ void llama_sampler_free_impl(struct llama_sampler * smpl) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto * constraint : smpl->constraints) {
|
for (auto * cnstr : smpl->constraints) {
|
||||||
llama_constraint_free_impl(constraint);
|
llama_constraint_free_impl(cnstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete smpl;
|
delete smpl;
|
||||||
|
@ -768,12 +772,14 @@ struct llama_sampler * llama_sampler_cp_impl(const struct llama_sampler & smpl)
|
||||||
|
|
||||||
// copy the constraints objects
|
// copy the constraints objects
|
||||||
result->constraints.clear();
|
result->constraints.clear();
|
||||||
for (const auto & constraint : smpl.constraints) {
|
for (const auto & cnstr : smpl.constraints) {
|
||||||
GGML_ASSERT(constraint->iface->copy);
|
|
||||||
|
|
||||||
result->constraints.push_back(new llama_constraint);
|
result->constraints.push_back(new llama_constraint);
|
||||||
result->constraints.back()->iface = constraint->iface;
|
result->constraints.back()->iface = cnstr->iface;
|
||||||
result->constraints.back()->iface->copy(result->constraints.back(), constraint);
|
|
||||||
|
if (cnstr->ctx) {
|
||||||
|
GGML_ASSERT(cnstr->iface->copy);
|
||||||
|
result->constraints.back()->iface->copy(result->constraints.back(), cnstr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -782,8 +788,8 @@ struct llama_sampler * llama_sampler_cp_impl(const struct llama_sampler & smpl)
|
||||||
void llama_sampler_reset_impl(struct llama_sampler & smpl) {
|
void llama_sampler_reset_impl(struct llama_sampler & smpl) {
|
||||||
smpl.prev.clear();
|
smpl.prev.clear();
|
||||||
|
|
||||||
for (auto * constraint : smpl.constraints) {
|
for (auto * cnstr : smpl.constraints) {
|
||||||
llama_constraint_reset_impl(constraint);
|
llama_constraint_reset_impl(*cnstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: should we reset the timings?
|
// TODO: should we reset the timings?
|
||||||
|
@ -796,7 +802,7 @@ void llama_sampler_add_constraint_impl(struct llama_sampler & smpl, struct llama
|
||||||
void llama_sampler_accept_impl(struct llama_sampler & smpl, llama_token token) {
|
void llama_sampler_accept_impl(struct llama_sampler & smpl, llama_token token) {
|
||||||
smpl.prev.push_back(token);
|
smpl.prev.push_back(token);
|
||||||
|
|
||||||
for (auto * constraint : smpl.constraints) {
|
for (auto * cnstr : smpl.constraints) {
|
||||||
llama_constraint_accept_impl(constraint, token);
|
llama_constraint_accept_impl(*cnstr, token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,11 +116,11 @@ int llama_sampling_n_prev_impl(const struct llama_sampling & smpl);
|
||||||
struct llama_constraint * llama_constraint_init_top_k_impl(int32_t k, size_t min_keep);
|
struct llama_constraint * llama_constraint_init_top_k_impl(int32_t k, size_t min_keep);
|
||||||
struct llama_constraint * llama_constraint_init_top_p_impl(float p, size_t min_keep);
|
struct llama_constraint * llama_constraint_init_top_p_impl(float p, size_t min_keep);
|
||||||
|
|
||||||
void llama_constraint_free_impl(struct llama_constraint * constraint);
|
void llama_constraint_free_impl(struct llama_constraint * cnstr);
|
||||||
|
|
||||||
void llama_constraint_accept_impl(struct llama_constraint * constraint, llama_token token);
|
void llama_constraint_accept_impl(struct llama_constraint & cnstr, llama_token token);
|
||||||
void llama_constraint_apply_impl (struct llama_constraint * constraint, struct llama_token_data_array * candidates);
|
void llama_constraint_apply_impl (struct llama_constraint & cnstr, struct llama_token_data_array * candidates);
|
||||||
void llama_constraint_reset_impl (struct llama_constraint * constraint);
|
void llama_constraint_reset_impl (struct llama_constraint & cnstr);
|
||||||
|
|
||||||
// samplers
|
// samplers
|
||||||
|
|
||||||
|
|
|
@ -20992,22 +20992,22 @@ void llama_constraint_free(struct llama_constraint * cnstr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void llama_constraint_accept(struct llama_constraint * cnstr, llama_token token) {
|
void llama_constraint_accept(struct llama_constraint * cnstr, llama_token token) {
|
||||||
llama_constraint_accept_impl(cnstr, token);
|
llama_constraint_accept_impl(*cnstr, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
void llama_constraint_apply(struct llama_constraint * cnstr, llama_token_data_array * candidates) {
|
void llama_constraint_apply(struct llama_constraint * cnstr, llama_token_data_array * candidates) {
|
||||||
llama_constraint_apply_impl(cnstr, candidates);
|
llama_constraint_apply_impl(*cnstr, candidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
void llama_constraint_reset(struct llama_constraint * cnstr) {
|
void llama_constraint_reset(struct llama_constraint * cnstr) {
|
||||||
llama_constraint_reset_impl(cnstr);
|
llama_constraint_reset_impl(*cnstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct llama_sampler * llama_sampler_init(struct llama_sampler_params params) {
|
struct llama_sampler * llama_sampler_init(struct llama_sampler_params params) {
|
||||||
return llama_sampler_init_impl(params);
|
return llama_sampler_init_impl(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
void llama_sampler_free(struct llama_sampler * smpl) {
|
void llama_sampler_free(struct llama_sampler * smpl) {
|
||||||
if (smpl == nullptr) {
|
if (smpl == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue