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.

LLamaModelParams.cs 2.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace LLama.Native
  4. {
  5. /// <summary>
  6. /// A C# representation of the llama.cpp `llama_model_params` struct
  7. /// </summary>
  8. [StructLayout(LayoutKind.Sequential)]
  9. public unsafe struct LLamaModelParams
  10. {
  11. /// <summary>
  12. /// // number of layers to store in VRAM
  13. /// </summary>
  14. public int n_gpu_layers;
  15. /// <summary>
  16. /// how to split the model across multiple GPUs
  17. /// </summary>
  18. public GPUSplitMode split_mode;
  19. /// <summary>
  20. /// the GPU that is used for scratch and small tensors
  21. /// </summary>
  22. public int main_gpu;
  23. /// <summary>
  24. /// how to split layers across multiple GPUs (size: <see cref="NativeApi.llama_max_devices"/>)
  25. /// </summary>
  26. public float* tensor_split;
  27. /// <summary>
  28. /// called with a progress value between 0 and 1, pass NULL to disable. If the provided progress_callback
  29. /// returns true, model loading continues. If it returns false, model loading is immediately aborted.
  30. /// </summary>
  31. #if NETSTANDARD2_0
  32. // this code is intended to be used when running LlamaSharp on NET Framework 4.8 (NET Standard 2.0)
  33. // as NET Framework 4.8 does not play nice with the LlamaProgressCallback type
  34. public IntPtr progress_callback;
  35. #else
  36. public LlamaProgressCallback progress_callback;
  37. #endif
  38. /// <summary>
  39. /// context pointer passed to the progress callback
  40. /// </summary>
  41. public void* progress_callback_user_data;
  42. /// <summary>
  43. /// override key-value pairs of the model meta data
  44. /// </summary>
  45. public LLamaModelMetadataOverride* kv_overrides;
  46. /// <summary>
  47. /// only load the vocabulary, no weights
  48. /// </summary>
  49. public bool vocab_only
  50. {
  51. readonly get => Convert.ToBoolean(_vocab_only);
  52. set => _vocab_only = Convert.ToSByte(value);
  53. }
  54. private sbyte _vocab_only;
  55. /// <summary>
  56. /// use mmap if possible
  57. /// </summary>
  58. public bool use_mmap
  59. {
  60. readonly get => Convert.ToBoolean(_use_mmap);
  61. set => _use_mmap = Convert.ToSByte(value);
  62. }
  63. private sbyte _use_mmap;
  64. /// <summary>
  65. /// force system to keep model in RAM
  66. /// </summary>
  67. public bool use_mlock
  68. {
  69. readonly get => Convert.ToBoolean(_use_mlock);
  70. set => _use_mlock = Convert.ToSByte(value);
  71. }
  72. private sbyte _use_mlock;
  73. }
  74. }