From 1db7292b05e9172eca52fe167c42512eac47e26c Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Thu, 17 Aug 2023 19:35:07 +0100 Subject: [PATCH] Fixed conflicts caused by merging of multi context PR --- LLama.Unittest/BasicTest.cs | 18 +++++++++++++++++- LLama.Unittest/GrammarTest.cs | 15 ++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/LLama.Unittest/BasicTest.cs b/LLama.Unittest/BasicTest.cs index 2a88f25d..f3fed804 100644 --- a/LLama.Unittest/BasicTest.cs +++ b/LLama.Unittest/BasicTest.cs @@ -1,13 +1,29 @@ +using System.Text; using LLama.Common; namespace LLama.Unittest { public class BasicTest + : IDisposable { + private readonly ModelParams _params; + private readonly LLamaWeights _model; + + public BasicTest() + { + _params = new ModelParams("Models/llama-2-7b-chat.ggmlv3.q3_K_S.bin", contextSize: 2048); + _model = LLamaWeights.LoadFromFile(_params); + } + + public void Dispose() + { + _model.Dispose(); + } + [Fact] public void LoadModel() { - var model = new LLamaContext(new ModelParams("Models/llama-2-7b-chat.ggmlv3.q3_K_S.bin", contextSize: 256)); + var model = _model.CreateContext(_params, Encoding.UTF8); model.Dispose(); } } diff --git a/LLama.Unittest/GrammarTest.cs b/LLama.Unittest/GrammarTest.cs index c813a573..c2b60a1a 100644 --- a/LLama.Unittest/GrammarTest.cs +++ b/LLama.Unittest/GrammarTest.cs @@ -1,4 +1,5 @@ -using LLama.Common; +using System.Text; +using LLama.Common; using LLama.Native; namespace LLama.Unittest @@ -6,7 +7,14 @@ namespace LLama.Unittest public sealed class GrammarTest : IDisposable { - private readonly LLamaModel _model = new(new ModelParams("Models/llama-2-7b-chat.ggmlv3.q3_K_S.bin", contextSize: 2048)); + private readonly ModelParams _params; + private readonly LLamaWeights _model; + + public GrammarTest() + { + _params = new ModelParams("Models/llama-2-7b-chat.ggmlv3.q3_K_S.bin", contextSize: 2048); + _model = LLamaWeights.LoadFromFile(_params); + } public void Dispose() { @@ -46,7 +54,8 @@ namespace LLama.Unittest using var grammar = SafeLLamaGrammarHandle.Create(rules, 0); - var executor = new StatelessExecutor(_model); + using var ctx = _model.CreateContext(_params, Encoding.UTF8); + var executor = new StatelessExecutor(ctx); var inferenceParams = new InferenceParams { MaxTokens = 3,