mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2026-09-29 09:27:33 -05:00
Add FP8 KV-cache support
This commit is contained in:
@@ -1524,6 +1524,16 @@ bool llama_model_base::load_tensors(llama_model_loader & ml) {
|
||||
for (int i = 0; i < n_layer_all; ++i) {
|
||||
auto & layer = layers[i];
|
||||
|
||||
if (hparams.has_kv(i)) {
|
||||
layer.k_cache_scale = create_tensor(tn(LLM_TENSOR_ATTN_K, "k_scale", i), {1}, TENSOR_NOT_REQUIRED);
|
||||
layer.v_cache_scale = create_tensor(tn(LLM_TENSOR_ATTN_V, "v_scale", i), {1}, TENSOR_NOT_REQUIRED);
|
||||
|
||||
if ((layer.k_cache_scale && layer.k_cache_scale->type != GGML_TYPE_F32) ||
|
||||
(layer.v_cache_scale && layer.v_cache_scale->type != GGML_TYPE_F32)) {
|
||||
throw std::runtime_error(format("KV cache scales for layer %d must be F32", i));
|
||||
}
|
||||
}
|
||||
|
||||
// attention weight scales (per-tensor, shape {1})
|
||||
if (!layer.wq_s && layer.wq) {
|
||||
layer.wq_s = create_tensor(tn(LLM_TENSOR_ATTN_Q, "scale", i), {1}, TENSOR_NOT_REQUIRED);
|
||||
|
||||
Reference in New Issue
Block a user