From e89ca5cc17bf9cccdaf24e5b4ac78c0b7183e7a2 Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Thu, 19 Oct 2023 00:43:50 +0100 Subject: [PATCH] Fixed a few minor warnings --- LLama.Examples/NewVersion/GetEmbeddings.cs | 5 +++- LLama.Examples/NewVersion/LoadAndSaveState.cs | 6 ++--- LLama.Unittest/LLamaEmbedderTests.cs | 9 ++++++- LLama.Unittest/ModelsParamsTests.cs | 27 +------------------ LLama/Native/NativeApi.cs | 1 + LLama/Native/SafeLLamaContextHandle.cs | 1 + 6 files changed, 18 insertions(+), 31 deletions(-) diff --git a/LLama.Examples/NewVersion/GetEmbeddings.cs b/LLama.Examples/NewVersion/GetEmbeddings.cs index 516d2da7..fe9e3ea8 100644 --- a/LLama.Examples/NewVersion/GetEmbeddings.cs +++ b/LLama.Examples/NewVersion/GetEmbeddings.cs @@ -8,7 +8,10 @@ namespace LLama.Examples.NewVersion { Console.Write("Please input your model path: "); var modelPath = Console.ReadLine(); - var embedder = new LLamaEmbedder(new ModelParams(modelPath)); + + var @params = new ModelParams(modelPath); + using var weights = LLamaWeights.LoadFromFile(@params); + var embedder = new LLamaEmbedder(weights, @params); while (true) { diff --git a/LLama.Examples/NewVersion/LoadAndSaveState.cs b/LLama.Examples/NewVersion/LoadAndSaveState.cs index 28ee30d6..2546a496 100644 --- a/LLama.Examples/NewVersion/LoadAndSaveState.cs +++ b/LLama.Examples/NewVersion/LoadAndSaveState.cs @@ -8,7 +8,7 @@ namespace LLama.Examples.NewVersion { Console.Write("Please input your model path: "); var modelPath = Console.ReadLine(); - var prompt = File.ReadAllText("Assets/chat-with-bob.txt").Trim(); + var prompt = (await File.ReadAllTextAsync("Assets/chat-with-bob.txt")).Trim(); var parameters = new ModelParams(modelPath) { @@ -44,7 +44,7 @@ namespace LLama.Examples.NewVersion Console.Write("Your path to save executor state: "); var executorStatePath = Console.ReadLine(); - ex.SaveState(executorStatePath); + await ex.SaveState(executorStatePath); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("All states saved!"); @@ -53,7 +53,7 @@ namespace LLama.Examples.NewVersion var ctx = ex.Context; ctx.LoadState(modelStatePath); ex = new InteractiveExecutor(ctx); - ex.LoadState(executorStatePath); + await ex.LoadState(executorStatePath); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Loaded state!"); Console.ForegroundColor = ConsoleColor.White; diff --git a/LLama.Unittest/LLamaEmbedderTests.cs b/LLama.Unittest/LLamaEmbedderTests.cs index f94c90ba..a4bd5867 100644 --- a/LLama.Unittest/LLamaEmbedderTests.cs +++ b/LLama.Unittest/LLamaEmbedderTests.cs @@ -5,7 +5,14 @@ namespace LLama.Unittest; public class LLamaEmbedderTests : IDisposable { - private readonly LLamaEmbedder _embedder = new(new ModelParams(Constants.ModelPath)); + private readonly LLamaEmbedder _embedder; + + public LLamaEmbedderTests() + { + var @params = new ModelParams(Constants.ModelPath); + using var weights = LLamaWeights.LoadFromFile(@params); + _embedder = new(weights, @params); + } public void Dispose() { diff --git a/LLama.Unittest/ModelsParamsTests.cs b/LLama.Unittest/ModelsParamsTests.cs index 000f5853..d07698a6 100644 --- a/LLama.Unittest/ModelsParamsTests.cs +++ b/LLama.Unittest/ModelsParamsTests.cs @@ -1,6 +1,4 @@ -using System.Text; -using LLama.Common; -using Newtonsoft.Json; +using LLama.Common; namespace LLama.Unittest { @@ -40,34 +38,11 @@ namespace LLama.Unittest }; var settings = new Newtonsoft.Json.JsonSerializerSettings(); - settings.Converters.Add(new NewtsonsoftEncodingConverter()); var json = Newtonsoft.Json.JsonConvert.SerializeObject(expected, settings); var actual = Newtonsoft.Json.JsonConvert.DeserializeObject(json, settings); Assert.Equal(expected, actual); } - - - - public class NewtsonsoftEncodingConverter : JsonConverter - { - public override bool CanConvert(Type objectType) - { - return typeof(Encoding).IsAssignableFrom(objectType); - } - - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - writer.WriteValue(((Encoding)value).WebName); - } - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - return Encoding.GetEncoding((string)reader.Value); - } - } - - } } diff --git a/LLama/Native/NativeApi.cs b/LLama/Native/NativeApi.cs index 15380a37..b806f9c0 100644 --- a/LLama/Native/NativeApi.cs +++ b/LLama/Native/NativeApi.cs @@ -273,6 +273,7 @@ namespace LLama.Native /// /// Returns 0 on success [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)] + [Obsolete("use llama_decode() instead")] public static extern int llama_eval(SafeLLamaContextHandle ctx, llama_token* tokens, int n_tokens, int n_past); /// diff --git a/LLama/Native/SafeLLamaContextHandle.cs b/LLama/Native/SafeLLamaContextHandle.cs index 6d5e87ce..c411385c 100644 --- a/LLama/Native/SafeLLamaContextHandle.cs +++ b/LLama/Native/SafeLLamaContextHandle.cs @@ -204,6 +204,7 @@ namespace LLama.Native { fixed (int* pinned = tokens) { + // the entire `eval` system needs replacing with the new batch system! var ret = NativeApi.llama_eval(this, pinned, tokens.Length, n_past); return ret == 0; }