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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using LLama;
  2. using LLama.Abstractions.Params;
  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. //LLamaInteractExecutor ex = new(new LLamaModel(new ModelParams(modelPath, contextSize: 1024, seed: 1337)));
  23. //while (true)
  24. //{
  25. // await foreach (var text in ex.InferAsync(prompt, new SessionParams() { Temperature = 0.6f, AntiPrompts = new List<string>{ "user:" } }, default(CancellationToken)))
  26. // {
  27. // Console.Write(text);
  28. // }
  29. // prompt = Console.ReadLine();
  30. //}
  31. StatelessExecutor ex = new(new LLamaModel(new ModelParams(modelPath, contextSize: 256)));
  32. while (true)
  33. {
  34. foreach (var text in ex.Infer(prompt, new SessionParams() { Temperature = 0.6f, AntiPrompts = new List<string> { "user:" }, MaxTokens = 256 }))
  35. {
  36. Console.Write(text);
  37. }
  38. prompt = Console.ReadLine();
  39. }
  40. //LLama.Examples.NewVersion.SaveAndLoadState runner = new(modelPath, prompt);
  41. //while (true)
  42. //{
  43. // var input = Console.ReadLine();
  44. // if(input == "save")
  45. // {
  46. // Console.Write("Your path to save state: ");
  47. // input = Console.ReadLine();
  48. // runner.SaveState("./ex_state.json", input);
  49. // runner.LoadState("./ex_state.json", input);
  50. // }
  51. // else
  52. // {
  53. // runner.Run(input);
  54. // }
  55. //}
  56. }
  57. else
  58. {
  59. OldTestRunner.Run();
  60. }

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