Skip to content

Commit 1b33d2c

Browse files
committed
fix: bugs
1 parent 1868c02 commit 1b33d2c

3 files changed

Lines changed: 7 additions & 8 deletions

File tree

src/evaluator/LlamaContext/LlamaContext.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,12 +1407,13 @@ export class LlamaContextSequence {
14071407
if (deletionSuccessful)
14081408
return;
14091409

1410-
const restoreCheckpointIndex = this._contextTokens.length - 1;
1411-
const existingCheckpoint = this._checkpoints.getLastCheckpoint(restoreCheckpointIndex);
1410+
let restoreCheckpointIndex = this._contextTokens.length - 1;
1411+
const existingCheckpoint = this._checkpoints.getLastCheckpoint(restoreCheckpointIndex, this.contextSize);
14121412
if (existingCheckpoint != null &&
14131413
restoreCheckpointIndex >= existingCheckpoint.minPos &&
1414-
restoreCheckpointIndex <= existingCheckpoint.maxPos
1414+
existingCheckpoint.maxPos <= this.contextSize
14151415
) {
1416+
restoreCheckpointIndex = Math.min(restoreCheckpointIndex, existingCheckpoint.maxPos);
14161417
const restoredSuccessfully = await this._context._ctx.restoreCheckpoint(existingCheckpoint, restoreCheckpointIndex);
14171418
if (restoredSuccessfully) {
14181419
const tokensToEvaluate = this._contextTokens.slice(restoreCheckpointIndex + 1);

src/evaluator/LlamaContext/LlamaContextSequenceCheckpoints.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ export class LlamaContextSequenceCheckpoints {
4141
return false;
4242
}
4343

44-
public getLastCheckpoint(restoreIndex: number) {
44+
public getLastCheckpoint(restoreIndex: number, contextSize: number) {
4545
if (restoreIndex <= 0)
4646
return null;
4747

4848
for (let i = this._checkpoints.length - 1; i >= 0; i--) {
4949
const [, checkpoint] = this._checkpoints[i]!;
50-
if (restoreIndex <= checkpoint.maxPos && restoreIndex >= checkpoint.minPos)
50+
if (restoreIndex >= checkpoint.minPos && checkpoint.maxPos <= contextSize)
5151
return checkpoint;
5252
else if (restoreIndex < checkpoint.minPos)
5353
return null;

vitest.config.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ export default defineConfig({
66
...configDefaults.exclude,
77
"./llama"
88
],
9-
pool: (process.platform === "darwin" && process.arch === "arm64")
10-
? "threads"
11-
: "forks",
9+
pool: "forks",
1210
maxWorkers: 1,
1311
maxConcurrency: 1,
1412
snapshotSerializers: [

0 commit comments

Comments
 (0)