You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Program.cs 3.7 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using LLama;
  2. using LLama.Common;
  3. using LLama.Examples;
  4. Console.WriteLine("======================================================================================================");
  5. Console.WriteLine(" __ __ ____ __ \r\n/\\ \\ /\\ \\ /\\ _`\\ /\\ \\ \r\n\\ \\ \\ \\ \\ \\ __ ___ ___ __ \\ \\,\\L\\_\\\\ \\ \\___ __ _ __ _____ \r\n \\ \\ \\ __\\ \\ \\ __ /'__`\\ /' __` __`\\ /'__`\\ \\/_\\__ \\ \\ \\ _ `\\ /'__`\\ /\\`'__\\/\\ '__`\\ \r\n \\ \\ \\L\\ \\\\ \\ \\L\\ \\/\\ \\L\\.\\_ /\\ \\/\\ \\/\\ \\ /\\ \\L\\.\\_ /\\ \\L\\ \\\\ \\ \\ \\ \\ /\\ \\L\\.\\_\\ \\ \\/ \\ \\ \\L\\ \\\r\n \\ \\____/ \\ \\____/\\ \\__/.\\_\\\\ \\_\\ \\_\\ \\_\\\\ \\__/.\\_\\\\ `\\____\\\\ \\_\\ \\_\\\\ \\__/.\\_\\\\ \\_\\ \\ \\ ,__/\r\n \\/___/ \\/___/ \\/__/\\/_/ \\/_/\\/_/\\/_/ \\/__/\\/_/ \\/_____/ \\/_/\\/_/ \\/__/\\/_/ \\/_/ \\ \\ \\/ \r\n \\ \\_\\ \r\n \\/_/ ");
  6. Console.WriteLine("======================================================================================================");
  7. Console.WriteLine();
  8. Console.WriteLine("Please choose the version you want to test: ");
  9. Console.WriteLine("0. old version (for v0.3.0 or earlier version)");
  10. Console.WriteLine("1. new version (for versions after v0.4.0)");
  11. Console.Write("\nYour Choice: ");
  12. int version = int.Parse(Console.ReadLine());
  13. Console.WriteLine();
  14. if(version == 1)
  15. {
  16. Console.WriteLine("The examples for new versions are under working now. We'll soon update the examples." +
  17. " Thank you for your support!");
  18. string modelPath = "D:\\development\\llama\\weights\\wizard-vicuna-13B.ggmlv3.q4_1.bin";
  19. var prompt = File.ReadAllText("Assets/chat-with-bob.txt").Trim();
  20. //string prompt = " Qeustion: how to do binary search for an array in C#? Answer: ";
  21. InteractiveExecutor ex = new(new LLamaModel(new ModelParams(modelPath, contextSize: 1024, seed: 1337)));
  22. ChatSession session = new ChatSession(ex).WithOutputTransform(new LLamaTransforms.KeywordTextOutputStreamTransform(new string[] { "User:", "Bob:" }));
  23. while (prompt != "skip")
  24. {
  25. await foreach (var text in session.ChatAsync(prompt, new InferenceParams() { Temperature = 0.6f, AntiPrompts = new List<string> { "User:" } }, default(CancellationToken)))
  26. {
  27. Console.Write(text);
  28. }
  29. prompt = Console.ReadLine();
  30. }
  31. ex.Model.Dispose();
  32. //StatelessExecutor ex = new(new LLamaModel(new ModelParams(modelPath, contextSize: 256)));
  33. //while (true)
  34. //{
  35. // foreach (var text in ex.Infer(prompt, new InferenceParams() { Temperature = 0.6f, AntiPrompts = new List<string> { "user:" }, MaxTokens = 256 }))
  36. // {
  37. // Console.Write(text);
  38. // }
  39. // prompt = Console.ReadLine();
  40. //}
  41. //LLama.Examples.NewVersion.SaveAndLoadState runner = new(modelPath, prompt);
  42. //while (true)
  43. //{
  44. // var input = Console.ReadLine();
  45. // if(input == "save")
  46. // {
  47. // Console.Write("Your path to save state: ");
  48. // input = Console.ReadLine();
  49. // runner.SaveState("./ex_state.json", input);
  50. // runner.LoadState("./ex_state.json", input);
  51. // }
  52. // else
  53. // {
  54. // runner.Run(input);
  55. // }
  56. //}
  57. }
  58. else
  59. {
  60. LLama.Examples.Old.OldTestRunner.Run();
  61. }

C#/.NET上易用的LLM高性能推理框架,支持LLaMA和LLaVA系列模型。