From bd989c21d4d691eaf384b2dd5fcbceccfbb41189 Mon Sep 17 00:00:00 2001 From: ngxson Date: Sun, 23 Jun 2024 00:33:59 +0200 Subject: [PATCH] fix inverted vector --- common/common.h | 2 +- examples/cvector-generator/README.md | 2 +- examples/cvector-generator/pca.hpp | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/common/common.h b/common/common.h index be05308fa..93848463b 100644 --- a/common/common.h +++ b/common/common.h @@ -233,7 +233,7 @@ struct gpt_params { bool compute_ppl = true; // whether to compute perplexity // cvector-generator params - int n_pca_batch = 20; + int n_pca_batch = 100; int n_pca_iterations = 1000; std::string cvector_outfile = "control_vector.gguf"; std::string cvector_positive_file = "examples/cvector-generator/positive.txt"; diff --git a/examples/cvector-generator/README.md b/examples/cvector-generator/README.md index 87ee6b76d..7d814154c 100644 --- a/examples/cvector-generator/README.md +++ b/examples/cvector-generator/README.md @@ -17,7 +17,7 @@ Related PRs: ./cvector-generator -m ./llama-3.Q4_K_M.gguf -ngl 99 # With advanced options -./cvector-generator -m ./llama-3.Q4_K_M.gguf -ngl 99 --completions 128 --pca-iter 2000 --pca-batch 100 +./cvector-generator -m ./llama-3.Q4_K_M.gguf -ngl 99 --pca-iter 2000 --pca-batch 100 # To see help message ./cvector-generator -h diff --git a/examples/cvector-generator/pca.hpp b/examples/cvector-generator/pca.hpp index 20f15d4c2..e2af5989a 100644 --- a/examples/cvector-generator/pca.hpp +++ b/examples/cvector-generator/pca.hpp @@ -298,6 +298,11 @@ static void power_iteration( ggml_backend_tensor_get(last_eigenvector, output->data, 0, ggml_nbytes(last_eigenvector)); //print_debug_tensor(output); ggml_gallocr_free(allocr); + + // TODO @ngxson : The output vector is inverted. Don't know why, but here is quick fix + for (int i = 0; i < output->ne[0]; i++) { + ggml_set_f32_1d(output, i, -ggml_get_f32_1d(output, i)); + } } static void run_pca(