From 838c99c7d570379299b6205650630ad71bb96663 Mon Sep 17 00:00:00 2001 From: Theia Vogel Date: Fri, 15 Mar 2024 12:59:08 -0700 Subject: [PATCH] disable control vector when data == nullptr use -1 for disabled range (also on init) in case we ever support controlling layer 0 (embeddings) --- llama.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/llama.cpp b/llama.cpp index 09ff01b0b..ffac0e4ca 100644 --- a/llama.cpp +++ b/llama.cpp @@ -1876,8 +1876,8 @@ struct llama_control_vector { std::vector ctxs; std::vector bufs; - int32_t layer_start = 0; - int32_t layer_end = 0; + int32_t layer_start = -1; + int32_t layer_end = -1; ggml_tensor * tensor_for(int il) const { 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; 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) { LLAMA_LOG_ERROR("%s: control vector n_embd does not match model\n", __func__); return 1;