Prompt caching
Before a language model writes anything, it processes the whole prompt. The intermediate results of that processing are kept in a key–value (KV) cache, so that each new token does not have to recompute them. If many calls begin with the same text, such as instructions and fixed examples, that shared beginning can be processed once and its cache reused. The llama.cpp server does this automatically for a shared prefix.
The saving applies only to a prefix, an identical beginning. A prompt is therefore ordered with the fixed material first and anything that varies afterwards. Retrieved examples and the new input come last.
In Quell
See also
- In-context learning — why prompts contain examples.
- Quantization and llama.cpp — llama.cpp, which provides the cache.
What links here: In-context learning