disable control vector when data == nullptr

use -1 for disabled range (also on init) in case we ever support controlling layer 0 (embeddings)
This commit is contained in:
Theia Vogel 2024-03-15 12:59:08 -07:00
parent fc6f042b30
commit 838c99c7d5

View file

@ -1876,8 +1876,8 @@ struct llama_control_vector {
std::vector<struct ggml_context *> ctxs; std::vector<struct ggml_context *> ctxs;
std::vector<ggml_backend_buffer_t> bufs; std::vector<ggml_backend_buffer_t> bufs;
int32_t layer_start = 0; int32_t layer_start = -1;
int32_t layer_end = 0; int32_t layer_end = -1;
ggml_tensor * tensor_for(int il) const { ggml_tensor * tensor_for(int il) const {
if (il < 0 || il < layer_start || il > layer_end || (size_t) il >= tensors.size()) { if (il < 0 || il < layer_start || il > layer_end || (size_t) il >= tensors.size()) {
@ -13343,6 +13343,13 @@ int32_t llama_control_vector_apply(struct llama_context * lctx, const float * da
const llama_model & model = lctx->model; const llama_model & model = lctx->model;
llama_control_vector & cvec = lctx->cvec; llama_control_vector & cvec = lctx->cvec;
if (data == nullptr) {
// disable the current control vector (but leave allocated for later)
cvec.layer_start = -1;
cvec.layer_end = -1;
return 0;
}
if (n_embd != (int) model.hparams.n_embd) { if (n_embd != (int) model.hparams.n_embd) {
LLAMA_LOG_ERROR("%s: control vector n_embd does not match model\n", __func__); LLAMA_LOG_ERROR("%s: control vector n_embd does not match model\n", __func__);
return 1; return 1;