From 4d0c044b9f537d80c7950bb0de738a34d709889b Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Fri, 18 Aug 2023 00:37:30 +0100 Subject: [PATCH] Added tests for the StatelessExecutor, one is currently failing --- LLama.Unittest/StatelessExecutorTest.cs | 59 +++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 LLama.Unittest/StatelessExecutorTest.cs diff --git a/LLama.Unittest/StatelessExecutorTest.cs b/LLama.Unittest/StatelessExecutorTest.cs new file mode 100644 index 00000000..fe3e6e03 --- /dev/null +++ b/LLama.Unittest/StatelessExecutorTest.cs @@ -0,0 +1,59 @@ +using LLama.Common; +using System.Text; + +namespace LLama.Unittest +{ + public class StatelessExecutorTest + : IDisposable + { + private readonly LLamaWeights _weights; + private readonly ModelParams _params; + + public StatelessExecutorTest() + { + _params = new ModelParams("Models/llama-2-7b-chat.ggmlv3.q3_K_S.bin") + { + ContextSize = 64, + Seed = 1754 + }; + _weights = LLamaWeights.LoadFromFile(_params); + } + + public void Dispose() + { + _weights.Dispose(); + } + + [Fact] + public void Stateless() + { + var executor = new StatelessExecutor(_weights.CreateContext(_params, Encoding.UTF8)); + + const string question = "Question. what is a cat?\nAnswer: "; + const string expected = " a domestic or wild animal that is typically small to medium-sized, has fur, four legs, and sharp retractable claws."; + var @params = new InferenceParams { MaxTokens = 32, AntiPrompts = new[] { "." } }; + + var result1 = string.Join("", executor.Infer(question, @params)); + Assert.Equal(expected, result1); + + var result2 = string.Join("", executor.Infer(question, @params)); + Assert.Equal(expected, result2); + + Assert.Equal(result1, result2); + } + + [Fact] + public void OutOfContext() + { + var executor = new StatelessExecutor(_weights.CreateContext(_params, Encoding.UTF8)); + + const string question = "Question. why is a cat the best pet?\nAnswer: "; + var @params = new InferenceParams() + { + MaxTokens = 128, + }; + + var result1 = string.Join("", executor.Infer(question, @params)); + } + } +} \ No newline at end of file