Skip to content

Commit d8514b3

Browse files
authored
A minor optimization of the code. (#733)
1 parent 1d8bbd6 commit d8514b3

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

LLama/LLamaExecutorBase.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,13 @@ protected virtual void HandleRunOutOfContext(int tokensToKeep)
195195
// if we run out of context:
196196
// - take the tokensToKeep first tokens from the original prompt (via n_past)
197197
// - take half of the last (n_ctx - tokensToKeep) tokens and recompute the logits in batches
198-
var n_left = _pastTokensCount - tokensToKeep;
199-
var n_discard = n_left / 2;
198+
int n_left = _pastTokensCount - tokensToKeep;
199+
int n_discard = n_left / 2;
200200

201-
NativeApi.llama_kv_cache_seq_rm(Context.NativeHandle, (LLamaSeqId)0, tokensToKeep, tokensToKeep + n_discard);
202-
NativeApi.llama_kv_cache_seq_add(Context.NativeHandle, (LLamaSeqId)0, tokensToKeep + n_discard, _pastTokensCount, -n_discard);
201+
NativeApi.llama_kv_cache_seq_rm(Context.NativeHandle, LLamaSeqId.Zero, tokensToKeep, tokensToKeep + n_discard);
202+
NativeApi.llama_kv_cache_seq_add(Context.NativeHandle, LLamaSeqId.Zero, tokensToKeep + n_discard, _pastTokensCount, -n_discard);
203203

204204
_pastTokensCount -= n_discard;
205-
206205
// stop saving session if we run out of context
207206
_pathSession = string.Empty;
208207
}

0 commit comments

Comments
 (0)