From 1cc463b9b748abc7e4922e614bace3b2da079c8c Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Mon, 12 Feb 2024 15:34:52 +0000 Subject: [PATCH] Added a finalizer to `BatchedExecutor` --- LLama/Batched/BatchedExecutor.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/LLama/Batched/BatchedExecutor.cs b/LLama/Batched/BatchedExecutor.cs index 2009a687..f432a89f 100644 --- a/LLama/Batched/BatchedExecutor.cs +++ b/LLama/Batched/BatchedExecutor.cs @@ -15,6 +15,11 @@ public sealed class BatchedExecutor private int _nextSequenceId; internal LLamaBatch Batch { get; } + + /// + /// Epoch is incremented every time Infer is called. Conversations can use this to keep track of + /// whether they're waiting for inference, or can be sampled. + /// internal ulong Epoch { get; private set; } /// @@ -50,6 +55,11 @@ public sealed class BatchedExecutor Epoch = 1; } + ~BatchedExecutor() + { + Dispose(); + } + /// /// Start a new with the given prompt /// @@ -97,6 +107,8 @@ public sealed class BatchedExecutor return; IsDisposed = true; + GC.SuppressFinalize(this); + Context.Dispose(); }