File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -8819,12 +8819,14 @@ static int llama_decode_impl(
8819
8819
// llama_synchronize(&lctx);
8820
8820
8821
8821
// decide if we need to defrag the kv cache
8822
- if (cparams.causal_attn && cparams.defrag_thold >= 0 .0f ) {
8823
- const float fragmentation = kv_self.n >= 128 ? 1 .0f - float (kv_self.used )/float (kv_self.n ) : 0 .0f ;
8822
+ if (cparams.causal_attn && cparams.defrag_thold > 0 .0f ) {
8823
+ // - do not defrag small contexts (i.e. < 2048 tokens)
8824
+ // - count the padding towards the number of used tokens
8825
+ const float fragmentation = kv_self.n >= 2048 ? std::max (0 .0f , 1 .0f - float (kv_self.used + llama_kv_cache_get_padding (cparams))/float (kv_self.n )) : 0 .0f ;
8824
8826
8825
8827
// queue defragmentation for next llama_kv_cache_update
8826
8828
if (fragmentation > cparams.defrag_thold ) {
8827
- // LLAMA_LOG_INFO(" fragmentation: %.2f\n", fragmentation);
8829
+ LLAMA_LOG_DEBUG ( " %s: fragmentation: %.2f - requesting defrag \n " , __func__ , fragmentation);
8828
8830
8829
8831
llama_kv_cache_defrag (kv_self);
8830
8832
}
You can’t perform that action at this time.
0 commit comments