1# cvector-generator
2
3This example demonstrates how to generate a control vector using gguf models.
4
5Related PRs:
6- [Add support for control vectors](https://github.com/ggml-org/llama.cpp/pull/5970)
7- (Issue) [Generate control vector using llama.cpp](https://github.com/ggml-org/llama.cpp/issues/6880)
8- [Add cvector-generator example](https://github.com/ggml-org/llama.cpp/pull/7514)
9
10## Examples
11
12```sh
13# CPU only
14./cvector-generator -m ./llama-3.Q4_K_M.gguf
15
16# With GPU
17./cvector-generator -m ./llama-3.Q4_K_M.gguf -ngl 99
18
19# With advanced options
20./cvector-generator -m ./llama-3.Q4_K_M.gguf -ngl 99 --pca-iter 2000 --pca-batch 100
21
22# Using mean value instead of PCA
23./cvector-generator -m ./llama-3.Q4_K_M.gguf --method mean
24
25# To see help message
26./cvector-generator -h
27# Then, have a look at "cvector" section
28```
29
30## Tips and tricks
31
32If you have multiple lines per prompt, you can escape the newline character (change it to `\n`). For example:
33
34```
35<|im_start|>system\nAct like a person who is extremely happy.<|im_end|>
36<|im_start|>system\nYou are in a very good mood today<|im_end|>
37```
38
39Example to use output file with `llama-cli`:
40
41(Tips: The control vector works better when apply to layers higher than 10)
42
43```sh
44./llama-cli -m ./llama-3.Q4_K_M.gguf -p "<|start_header_id|>system<|end_header_id|>\n\nYou are a helpful assistant<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nSing a song<|im_end|><|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n" --special --control-vector-scaled ./control_vector.gguf 0.8 --control-vector-layer-range 10 31
45```