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.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using LLama;
  2. using LLama.Common;
  3. using LLama.Examples;
  4. using LLama.Examples.Old;
  5. Console.WriteLine("======================================================================================================");
  6. 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 \\/_/ ");
  7. Console.WriteLine("======================================================================================================");
  8. Console.WriteLine();
  9. Console.WriteLine("Please choose the version you want to test: ");
  10. Console.WriteLine("0. old version (for v0.3.0 or earlier version)");
  11. Console.WriteLine("1. new version (for versions after v0.4.0)");
  12. Console.Write("\nYour Choice: ");
  13. int version = int.Parse(Console.ReadLine());
  14. Console.WriteLine();
  15. if(version == 1)
  16. {
  17. Console.WriteLine("The examples for new versions are under working now. We'll soon update the examples." +
  18. " Thank you for your support!");
  19. string modelPath = "D:\\development\\llama\\weights\\wizard-vicuna-13B.ggmlv3.q4_1.bin";
  20. var prompt = File.ReadAllText("Assets/chat-with-bob.txt").Trim();
  21. //string prompt = " Qeustion: how to do binary search for an array in C#? Answer: ";
  22. InteractiveExecutor ex = new(new LLamaModel(new ModelParams(modelPath, contextSize: 1024, seed: 1337)));
  23. while (prompt != "skip")
  24. {
  25. await foreach (var text in ex.InferAsync(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. OldTestRunner.Run();
  61. }

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