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

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

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