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.

LLamaContextParams.cs 4.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace LLama.Native
  4. {
  5. /// <summary>
  6. /// Called by llama.cpp with a progress value between 0 and 1
  7. /// </summary>
  8. /// <param name="progress"></param>
  9. /// <param name="ctx"></param>
  10. public delegate void LlamaProgressCallback(float progress, IntPtr ctx);
  11. /// <summary>
  12. /// A C# representation of the llama.cpp `llama_context_params` struct
  13. /// </summary>
  14. [StructLayout(LayoutKind.Sequential)]
  15. public struct LLamaContextParams
  16. {
  17. /// <summary>
  18. /// RNG seed, -1 for random
  19. /// </summary>
  20. public int seed;
  21. /// <summary>
  22. /// text context
  23. /// </summary>
  24. public int n_ctx;
  25. /// <summary>
  26. /// prompt processing batch size
  27. /// </summary>
  28. public int n_batch;
  29. /// <summary>
  30. /// number of layers to store in VRAM
  31. /// </summary>
  32. public int n_gpu_layers;
  33. /// <summary>
  34. /// the GPU that is used for scratch and small tensors
  35. /// </summary>
  36. public int main_gpu;
  37. /// <summary>
  38. /// how to split layers across multiple GPUs
  39. /// </summary>
  40. public nint tensor_split;
  41. /// <summary>
  42. /// ref: https://github.com/ggerganov/llama.cpp/pull/2054
  43. /// RoPE base frequency
  44. /// </summary>
  45. public float rope_freq_base;
  46. /// <summary>
  47. /// ref: https://github.com/ggerganov/llama.cpp/pull/2054
  48. /// RoPE frequency scaling factor
  49. /// </summary>
  50. public float rope_freq_scale;
  51. /// <summary>
  52. /// called with a progress value between 0 and 1, pass NULL to disable
  53. /// </summary>
  54. public IntPtr progress_callback;
  55. /// <summary>
  56. /// context pointer passed to the progress callback
  57. /// </summary>
  58. public IntPtr progress_callback_user_data;
  59. /// <summary>
  60. /// if true, reduce VRAM usage at the cost of performance
  61. /// </summary>
  62. public bool low_vram
  63. {
  64. readonly get => Convert.ToBoolean(_low_vram);
  65. set => _low_vram = Convert.ToSByte(value);
  66. }
  67. private sbyte _low_vram;
  68. /// <summary>
  69. /// if true, use experimental mul_mat_q kernels
  70. /// </summary>
  71. public bool mul_mat_q
  72. {
  73. readonly get => Convert.ToBoolean(_mul_mat_q);
  74. set => _mul_mat_q = Convert.ToSByte(value);
  75. }
  76. private sbyte _mul_mat_q;
  77. /// <summary>
  78. /// use fp16 for KV cache
  79. /// </summary>
  80. public bool f16_kv
  81. {
  82. readonly get => Convert.ToBoolean(_f16_kv);
  83. set => _f16_kv = Convert.ToSByte(value);
  84. }
  85. private sbyte _f16_kv;
  86. /// <summary>
  87. /// the llama_eval() call computes all logits, not just the last one
  88. /// </summary>
  89. public bool logits_all
  90. {
  91. readonly get => Convert.ToBoolean(_logits_all);
  92. set => _logits_all = Convert.ToSByte(value);
  93. }
  94. private sbyte _logits_all;
  95. /// <summary>
  96. /// only load the vocabulary, no weights
  97. /// </summary>
  98. public bool vocab_only
  99. {
  100. readonly get => Convert.ToBoolean(_vocab_only);
  101. set => _vocab_only = Convert.ToSByte(value);
  102. }
  103. private sbyte _vocab_only;
  104. /// <summary>
  105. /// use mmap if possible
  106. /// </summary>
  107. public bool use_mmap
  108. {
  109. readonly get => Convert.ToBoolean(_use_mmap);
  110. set => _use_mmap = Convert.ToSByte(value);
  111. }
  112. private sbyte _use_mmap;
  113. /// <summary>
  114. /// force system to keep model in RAM
  115. /// </summary>
  116. public bool use_mlock
  117. {
  118. readonly get => Convert.ToBoolean(_use_mlock);
  119. set => _use_mlock = Convert.ToSByte(value);
  120. }
  121. private sbyte _use_mlock;
  122. /// <summary>
  123. /// embedding mode only
  124. /// </summary>
  125. public bool embedding
  126. {
  127. readonly get => Convert.ToBoolean(_embedding);
  128. set => _embedding = Convert.ToSByte(value);
  129. }
  130. private sbyte _embedding;
  131. }
  132. }