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.

SaveAndLoadState.cs 1.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace LLama.Examples
  7. {
  8. public class SaveAndLoadState: IDisposable
  9. {
  10. LLamaModel _model;
  11. public SaveAndLoadState(string modelPath, string prompt)
  12. {
  13. _model = new LLamaModel(new LLamaParams(model: modelPath, n_ctx: 2048, n_predict: -1, top_k: 10000, instruct: true,
  14. repeat_penalty: 1.1f, n_batch: 256, temp: 0.2f)).WithPrompt(prompt);
  15. }
  16. public void Run(string question)
  17. {
  18. // Only run once here.
  19. Console.Write("\nUser:");
  20. Console.ForegroundColor = ConsoleColor.Green;
  21. Console.WriteLine(question);
  22. Console.ForegroundColor = ConsoleColor.White;
  23. var outputs = _model.Call(question);
  24. foreach (var output in outputs)
  25. {
  26. Console.Write(output);
  27. }
  28. }
  29. public void SaveState(string filename)
  30. {
  31. _model.SaveState(filename);
  32. Console.WriteLine("Saved state!");
  33. }
  34. public void LoadState(string filename)
  35. {
  36. _model.LoadState(filename);
  37. Console.WriteLine("Loaded state!");
  38. }
  39. public void Dispose()
  40. {
  41. _model.Dispose();
  42. }
  43. }
  44. }

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