| @@ -1,9 +1,5 @@ | |||||
| using LLama.Common; | using LLama.Common; | ||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | using System.Text; | ||||
| using System.Threading.Tasks; | |||||
| namespace LLama.Examples.NewVersion | namespace LLama.Examples.NewVersion | ||||
| { | { | ||||
| @@ -12,15 +8,22 @@ namespace LLama.Examples.NewVersion | |||||
| public static void Run() | public static void Run() | ||||
| { | { | ||||
| Console.Write("Please input your model path: "); | Console.Write("Please input your model path: "); | ||||
| string modelPath = Console.ReadLine(); | |||||
| var modelPath = Console.ReadLine(); | |||||
| var prompt = File.ReadAllText("Assets/chat-with-bob.txt").Trim(); | var prompt = File.ReadAllText("Assets/chat-with-bob.txt").Trim(); | ||||
| InteractiveExecutor ex = new(new LLamaContext(new ModelParams(modelPath, contextSize: 1024, seed: 1337, gpuLayerCount: 5))); | |||||
| ChatSession session = new ChatSession(ex).WithOutputTransform(new LLamaTransforms.KeywordTextOutputStreamTransform(new string[] { "User:", "Bob:" }, redundancyLength: 8)); | |||||
| var parameters = new ModelParams(modelPath, contextSize: 1024, seed: 1337, gpuLayerCount: 5); | |||||
| using var model = LLamaWeights.LoadFromFile(parameters); | |||||
| using var context = model.CreateContext(parameters, Encoding.UTF8); | |||||
| var executor = new InteractiveExecutor(context); | |||||
| var session = new ChatSession(executor).WithOutputTransform(new LLamaTransforms.KeywordTextOutputStreamTransform(new string[] { "User:", "Bob:" }, redundancyLength: 8)); | |||||
| Console.ForegroundColor = ConsoleColor.Yellow; | Console.ForegroundColor = ConsoleColor.Yellow; | ||||
| Console.WriteLine("The chat session has started. The role names won't be printed."); | Console.WriteLine("The chat session has started. The role names won't be printed."); | ||||
| Console.ForegroundColor = ConsoleColor.White; | Console.ForegroundColor = ConsoleColor.White; | ||||
| // show the prompt | |||||
| Console.Write(prompt); | |||||
| while (true) | while (true) | ||||
| { | { | ||||
| foreach (var text in session.Chat(prompt, new InferenceParams() { Temperature = 0.6f, AntiPrompts = new List<string> { "User:" } })) | foreach (var text in session.Chat(prompt, new InferenceParams() { Temperature = 0.6f, AntiPrompts = new List<string> { "User:" } })) | ||||
| @@ -1,9 +1,5 @@ | |||||
| using LLama.Common; | using LLama.Common; | ||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | using System.Text; | ||||
| using System.Threading.Tasks; | |||||
| namespace LLama.Examples.NewVersion | namespace LLama.Examples.NewVersion | ||||
| { | { | ||||
| @@ -12,10 +8,15 @@ namespace LLama.Examples.NewVersion | |||||
| public static void Run() | public static void Run() | ||||
| { | { | ||||
| Console.Write("Please input your model path: "); | Console.Write("Please input your model path: "); | ||||
| string modelPath = Console.ReadLine(); | |||||
| var modelPath = Console.ReadLine(); | |||||
| var prompt = File.ReadAllText("Assets/chat-with-bob.txt").Trim(); | var prompt = File.ReadAllText("Assets/chat-with-bob.txt").Trim(); | ||||
| InteractiveExecutor ex = new(new LLamaContext(new ModelParams(modelPath, contextSize: 1024, seed: 1337, gpuLayerCount: 5))); | |||||
| ChatSession session = new ChatSession(ex); // The only change is to remove the transform for the output text stream. | |||||
| var parameters = new ModelParams(modelPath, contextSize: 1024, seed: 1337, gpuLayerCount: 5); | |||||
| using var model = LLamaWeights.LoadFromFile(parameters); | |||||
| using var context = model.CreateContext(parameters, Encoding.UTF8); | |||||
| var executor = new InteractiveExecutor(context); | |||||
| var session = new ChatSession(executor); | |||||
| Console.ForegroundColor = ConsoleColor.Yellow; | Console.ForegroundColor = ConsoleColor.Yellow; | ||||
| Console.WriteLine("The chat session has started. In this example, the prompt is printed for better visual result."); | Console.WriteLine("The chat session has started. In this example, the prompt is printed for better visual result."); | ||||
| @@ -1,9 +1,4 @@ | |||||
| using LLama.Common; | using LLama.Common; | ||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| namespace LLama.Examples.NewVersion | namespace LLama.Examples.NewVersion | ||||
| { | { | ||||
| @@ -12,7 +7,7 @@ namespace LLama.Examples.NewVersion | |||||
| public static void Run() | public static void Run() | ||||
| { | { | ||||
| Console.Write("Please input your model path: "); | Console.Write("Please input your model path: "); | ||||
| string modelPath = Console.ReadLine(); | |||||
| var modelPath = Console.ReadLine(); | |||||
| var embedder = new LLamaEmbedder(new ModelParams(modelPath)); | var embedder = new LLamaEmbedder(new ModelParams(modelPath)); | ||||
| while (true) | while (true) | ||||
| @@ -1,9 +1,5 @@ | |||||
| using LLama.Common; | using LLama.Common; | ||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | using System.Text; | ||||
| using System.Threading.Tasks; | |||||
| namespace LLama.Examples.NewVersion | namespace LLama.Examples.NewVersion | ||||
| { | { | ||||
| @@ -12,10 +8,13 @@ namespace LLama.Examples.NewVersion | |||||
| public static void Run() | public static void Run() | ||||
| { | { | ||||
| Console.Write("Please input your model path: "); | Console.Write("Please input your model path: "); | ||||
| string modelPath = Console.ReadLine(); | |||||
| var modelPath = Console.ReadLine(); | |||||
| var prompt = File.ReadAllText("Assets/dan.txt").Trim(); | var prompt = File.ReadAllText("Assets/dan.txt").Trim(); | ||||
| InstructExecutor ex = new(new LLamaContext(new ModelParams(modelPath, contextSize: 1024))); | |||||
| var parameters = new ModelParams(modelPath, contextSize: 1024, seed: 1337, gpuLayerCount: 5); | |||||
| using var model = LLamaWeights.LoadFromFile(parameters); | |||||
| using var context = model.CreateContext(parameters, Encoding.UTF8); | |||||
| var executor = new InstructExecutor(context); | |||||
| Console.ForegroundColor = ConsoleColor.Yellow; | Console.ForegroundColor = ConsoleColor.Yellow; | ||||
| Console.WriteLine("The executor has been enabled. In this example, the LLM will follow your instructions. For example, you can input \"Write a story about a fox who want to " + | Console.WriteLine("The executor has been enabled. In this example, the LLM will follow your instructions. For example, you can input \"Write a story about a fox who want to " + | ||||
| @@ -26,7 +25,7 @@ namespace LLama.Examples.NewVersion | |||||
| while (true) | while (true) | ||||
| { | { | ||||
| foreach (var text in ex.Infer(prompt, inferenceParams)) | |||||
| foreach (var text in executor.Infer(prompt, inferenceParams)) | |||||
| { | { | ||||
| Console.Write(text); | Console.Write(text); | ||||
| } | } | ||||
| @@ -1,21 +1,20 @@ | |||||
| using LLama.Common; | using LLama.Common; | ||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | using System.Text; | ||||
| using System.Threading.Tasks; | |||||
| namespace LLama.Examples.NewVersion | namespace LLama.Examples.NewVersion | ||||
| { | { | ||||
| public class InteractiveModeExecute | public class InteractiveModeExecute | ||||
| { | { | ||||
| public async static Task Run() | |||||
| public static async Task Run() | |||||
| { | { | ||||
| Console.Write("Please input your model path: "); | Console.Write("Please input your model path: "); | ||||
| string modelPath = Console.ReadLine(); | |||||
| var prompt = File.ReadAllText("Assets/chat-with-bob.txt").Trim(); | |||||
| var modelPath = Console.ReadLine(); | |||||
| var prompt = (await File.ReadAllTextAsync("Assets/chat-with-bob.txt")).Trim(); | |||||
| InteractiveExecutor ex = new(new LLamaContext(new ModelParams(modelPath, contextSize: 256))); | |||||
| var parameters = new ModelParams(modelPath, contextSize: 1024, seed: 1337, gpuLayerCount: 5); | |||||
| using var model = LLamaWeights.LoadFromFile(parameters); | |||||
| using var context = model.CreateContext(parameters, Encoding.UTF8); | |||||
| var ex = new InteractiveExecutor(context); | |||||
| Console.ForegroundColor = ConsoleColor.Yellow; | Console.ForegroundColor = ConsoleColor.Yellow; | ||||
| Console.WriteLine("The executor has been enabled. In this example, the prompt is printed, the maximum tokens is set to 128 and the context size is 256. (an example for small scale usage)"); | Console.WriteLine("The executor has been enabled. In this example, the prompt is printed, the maximum tokens is set to 128 and the context size is 256. (an example for small scale usage)"); | ||||
| @@ -1,10 +1,5 @@ | |||||
| using LLama.Common; | using LLama.Common; | ||||
| using LLama.OldVersion; | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | using System.Text; | ||||
| using System.Threading.Tasks; | |||||
| namespace LLama.Examples.NewVersion | namespace LLama.Examples.NewVersion | ||||
| { | { | ||||
| @@ -13,10 +8,15 @@ namespace LLama.Examples.NewVersion | |||||
| public static void Run() | public static void Run() | ||||
| { | { | ||||
| Console.Write("Please input your model path: "); | Console.Write("Please input your model path: "); | ||||
| string modelPath = Console.ReadLine(); | |||||
| var modelPath = Console.ReadLine(); | |||||
| var prompt = File.ReadAllText("Assets/chat-with-bob.txt").Trim(); | var prompt = File.ReadAllText("Assets/chat-with-bob.txt").Trim(); | ||||
| InteractiveExecutor ex = new(new LLamaContext(new ModelParams(modelPath, contextSize: 1024, seed: 1337, gpuLayerCount: 5))); | |||||
| ChatSession session = new ChatSession(ex); // The only change is to remove the transform for the output text stream. | |||||
| var parameters = new ModelParams(modelPath, contextSize: 1024, seed: 1337, gpuLayerCount: 5); | |||||
| using var model = LLamaWeights.LoadFromFile(parameters); | |||||
| using var context = model.CreateContext(parameters, Encoding.UTF8); | |||||
| var ex = new InteractiveExecutor(context); | |||||
| var session = new ChatSession(ex); | |||||
| Console.ForegroundColor = ConsoleColor.Yellow; | Console.ForegroundColor = ConsoleColor.Yellow; | ||||
| Console.WriteLine("The chat session has started. In this example, the prompt is printed for better visual result. Input \"save\" to save and reload the session."); | Console.WriteLine("The chat session has started. In this example, the prompt is printed for better visual result. Input \"save\" to save and reload the session."); | ||||
| @@ -1,9 +1,5 @@ | |||||
| using LLama.Common; | using LLama.Common; | ||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | using System.Text; | ||||
| using System.Threading.Tasks; | |||||
| namespace LLama.Examples.NewVersion | namespace LLama.Examples.NewVersion | ||||
| { | { | ||||
| @@ -12,10 +8,13 @@ namespace LLama.Examples.NewVersion | |||||
| public static void Run() | public static void Run() | ||||
| { | { | ||||
| Console.Write("Please input your model path: "); | Console.Write("Please input your model path: "); | ||||
| string modelPath = Console.ReadLine(); | |||||
| var modelPath = Console.ReadLine(); | |||||
| var prompt = File.ReadAllText("Assets/chat-with-bob.txt").Trim(); | var prompt = File.ReadAllText("Assets/chat-with-bob.txt").Trim(); | ||||
| InteractiveExecutor ex = new(new LLamaContext(new ModelParams(modelPath, contextSize: 256))); | |||||
| var parameters = new ModelParams(modelPath, contextSize: 1024, seed: 1337, gpuLayerCount: 5); | |||||
| using var model = LLamaWeights.LoadFromFile(parameters); | |||||
| using var context = model.CreateContext(parameters, Encoding.UTF8); | |||||
| var ex = new InteractiveExecutor(context); | |||||
| Console.ForegroundColor = ConsoleColor.Yellow; | Console.ForegroundColor = ConsoleColor.Yellow; | ||||
| Console.WriteLine("The executor has been enabled. In this example, the prompt is printed, the maximum tokens is set to 64 and the context size is 256. (an example for small scale usage)"); | Console.WriteLine("The executor has been enabled. In this example, the prompt is printed, the maximum tokens is set to 64 and the context size is 256. (an example for small scale usage)"); | ||||
| @@ -47,9 +46,9 @@ namespace LLama.Examples.NewVersion | |||||
| Console.WriteLine("All states saved!"); | Console.WriteLine("All states saved!"); | ||||
| Console.ForegroundColor = ConsoleColor.White; | Console.ForegroundColor = ConsoleColor.White; | ||||
| var model = ex.Context; | |||||
| model.LoadState(modelStatePath); | |||||
| ex = new InteractiveExecutor(model); | |||||
| var ctx = ex.Context; | |||||
| ctx.LoadState(modelStatePath); | |||||
| ex = new InteractiveExecutor(ctx); | |||||
| ex.LoadState(executorStatePath); | ex.LoadState(executorStatePath); | ||||
| Console.ForegroundColor = ConsoleColor.Yellow; | Console.ForegroundColor = ConsoleColor.Yellow; | ||||
| Console.WriteLine("Loaded state!"); | Console.WriteLine("Loaded state!"); | ||||
| @@ -1,11 +1,4 @@ | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading; | |||||
| using System.Threading.Tasks; | |||||
| namespace LLama.Examples.NewVersion | |||||
| namespace LLama.Examples.NewVersion | |||||
| { | { | ||||
| public class QuantizeModel | public class QuantizeModel | ||||
| { | { | ||||
| @@ -13,13 +6,16 @@ namespace LLama.Examples.NewVersion | |||||
| { | { | ||||
| Console.Write("Please input your original model path: "); | Console.Write("Please input your original model path: "); | ||||
| var inputPath = Console.ReadLine(); | var inputPath = Console.ReadLine(); | ||||
| Console.Write("Please input your output model path: "); | Console.Write("Please input your output model path: "); | ||||
| var outputPath = Console.ReadLine(); | var outputPath = Console.ReadLine(); | ||||
| Console.Write("Please input the quantize type (one of q4_0, q4_1, q5_0, q5_1, q8_0): "); | Console.Write("Please input the quantize type (one of q4_0, q4_1, q5_0, q5_1, q8_0): "); | ||||
| var quantizeType = Console.ReadLine(); | var quantizeType = Console.ReadLine(); | ||||
| if (LLamaQuantizer.Quantize(inputPath, outputPath, quantizeType)) | if (LLamaQuantizer.Quantize(inputPath, outputPath, quantizeType)) | ||||
| { | { | ||||
| Console.WriteLine("Quantization succeed!"); | |||||
| Console.WriteLine("Quantization succeeded!"); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| @@ -1,9 +1,5 @@ | |||||
| using LLama.Common; | using LLama.Common; | ||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | using System.Text; | ||||
| using System.Threading.Tasks; | |||||
| namespace LLama.Examples.NewVersion | namespace LLama.Examples.NewVersion | ||||
| { | { | ||||
| @@ -12,9 +8,12 @@ namespace LLama.Examples.NewVersion | |||||
| public static void Run() | public static void Run() | ||||
| { | { | ||||
| Console.Write("Please input your model path: "); | Console.Write("Please input your model path: "); | ||||
| string modelPath = Console.ReadLine(); | |||||
| var modelPath = Console.ReadLine(); | |||||
| StatelessExecutor ex = new(new LLamaContext(new ModelParams(modelPath, contextSize: 256))); | |||||
| var parameters = new ModelParams(modelPath, contextSize: 1024, seed: 1337, gpuLayerCount: 5); | |||||
| using var model = LLamaWeights.LoadFromFile(parameters); | |||||
| using var context = model.CreateContext(parameters, Encoding.UTF8); | |||||
| var ex = new StatelessExecutor(context); | |||||
| Console.ForegroundColor = ConsoleColor.Yellow; | Console.ForegroundColor = ConsoleColor.Yellow; | ||||
| Console.WriteLine("The executor has been enabled. In this example, the inference is an one-time job. That says, the previous input and response has " + | Console.WriteLine("The executor has been enabled. In this example, the inference is an one-time job. That says, the previous input and response has " + | ||||
| @@ -1,10 +1,4 @@ | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| namespace LLama.Examples.NewVersion | |||||
| namespace LLama.Examples.NewVersion | |||||
| { | { | ||||
| public class NewVersionTestRunner | public class NewVersionTestRunner | ||||
| { | { | ||||