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.

LLamaParams.cs 6.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using System;
  2. using System.Collections.Generic;
  3. #pragma warning disable
  4. // ReSharper disable all
  5. namespace LLama.OldVersion
  6. {
  7. using llama_token = Int32;
  8. [Obsolete("The entire LLama.OldVersion namespace will be removed")]
  9. public struct LLamaParams
  10. {
  11. public int seed; // RNG seed
  12. public int n_threads = Math.Max(Environment.ProcessorCount / 2, 1); // number of threads (-1 = autodetect)
  13. public int n_predict = -1; // new tokens to predict
  14. public int n_ctx = 512; // context size
  15. public int n_batch = 512; // batch size for prompt processing (must be >=32 to use BLAS)
  16. public int n_keep = 0; // number of tokens to keep from initial prompt
  17. public int n_gpu_layers = -1; // number of layers to store in VRAM
  18. // sampling parameters
  19. public Dictionary<llama_token, float> logit_bias; // logit bias for specific tokens
  20. public int top_k = 40; // <= 0 to use vocab size
  21. public float top_p = 0.95f; // 1.0 = disabled
  22. public float tfs_z = 1.00f; // 1.0 = disabled
  23. public float typical_p = 1.00f; // 1.0 = disabled
  24. public float temp = 0.80f; // 1.0 = disabled
  25. public float repeat_penalty = 1.10f; // 1.0 = disabled
  26. public int repeat_last_n = 64; // last n tokens to penalize (0 = disable penalty, -1 = context size)
  27. public float frequency_penalty = 0.00f; // 0.0 = disabled
  28. public float presence_penalty = 0.00f; // 0.0 = disabled
  29. public int mirostat = 0; // 0 = disabled, 1 = mirostat, 2 = mirostat 2.0
  30. public float mirostat_tau = 5.00f; // target entropy
  31. public float mirostat_eta = 0.10f; // learning rate
  32. public string model = "models/lamma-7B/ggml-model.bin"; // model path
  33. public string prompt = ""; // initial prompt (set to empty string for interactive mode)
  34. public string path_session = ""; // path to file for saving/loading model eval state
  35. public string input_prefix = ""; // string to prefix user inputs with
  36. public string input_suffix = ""; // string to suffix user inputs with
  37. public List<string> antiprompt; // string upon seeing which more user input is prompted
  38. public string lora_adapter = ""; // lora adapter path
  39. public string lora_base = ""; // base model path for the lora adapter
  40. public bool memory_f16 = true; // use f16 instead of f32 for memory kv
  41. public bool random_prompt = false; // randomize prompt if none provided
  42. public bool use_color = false; // use color to distinguish generations and inputs
  43. public bool interactive = false; // interactive mode
  44. public bool prompt_cache_all = false; // save user input and generations to prompt cache
  45. public bool embedding = false; // get only sentence embedding
  46. public bool interactive_first = false; // wait for user input immediately
  47. public bool instruct = false; // instruction mode (used for Alpaca models)
  48. public bool penalize_nl = true; // consider newlines as a repeatable token
  49. public bool perplexity = false; // compute perplexity over the prompt
  50. public bool use_mmap = true; // use mmap for faster loads
  51. public bool use_mlock = false; // use mlock to keep model in memory
  52. public bool mem_test = false; // compute maximum memory usage
  53. public bool verbose_prompt = false; // print prompt tokens before generation
  54. public LLamaParams(int seed = 0, int n_threads = -1, int n_predict = -1,
  55. int n_ctx = 512, int n_batch = 512, int n_keep = 0, int n_gpu_layers = -1,
  56. Dictionary<llama_token, float>? logit_bias = null, int top_k = 40, float top_p = 0.95f,
  57. float tfs_z = 1.00f, float typical_p = 1.00f, float temp = 0.80f, float repeat_penalty = 1.10f,
  58. int repeat_last_n = 64, float frequency_penalty = 0.00f, float presence_penalty = 0.00f,
  59. int mirostat = 0, float mirostat_tau = 5.00f, float mirostat_eta = 0.10f,
  60. string model = "models/lamma-7B/ggml-model.bin", string prompt = "",
  61. string path_session = "", string input_prefix = "", string input_suffix = "",
  62. List<string> antiprompt = null, string lora_adapter = "", string lora_base = "",
  63. bool memory_f16 = true, bool random_prompt = false, bool use_color = false, bool interactive = false,
  64. bool prompt_cache_all = false, bool embedding = false, bool interactive_first = false,
  65. bool instruct = false, bool penalize_nl = true,
  66. bool perplexity = false, bool use_mmap = true, bool use_mlock = false, bool mem_test = false,
  67. bool verbose_prompt = false)
  68. {
  69. this.seed = seed;
  70. if (n_threads != -1)
  71. {
  72. this.n_threads = n_threads;
  73. }
  74. this.n_predict = n_predict;
  75. this.n_ctx = n_ctx;
  76. this.n_batch = n_batch;
  77. this.n_keep = n_keep;
  78. this.n_gpu_layers = n_gpu_layers == -1 ? 20 : n_gpu_layers;
  79. if (logit_bias == null)
  80. {
  81. logit_bias = new Dictionary<llama_token, float>();
  82. }
  83. this.logit_bias = logit_bias;
  84. this.top_k = top_k;
  85. this.top_p = top_p;
  86. this.tfs_z = tfs_z;
  87. this.typical_p = typical_p;
  88. this.temp = temp;
  89. this.repeat_penalty = repeat_penalty;
  90. this.repeat_last_n = repeat_last_n;
  91. this.frequency_penalty = frequency_penalty;
  92. this.presence_penalty = presence_penalty;
  93. this.mirostat = mirostat;
  94. this.mirostat_tau = mirostat_tau;
  95. this.mirostat_eta = mirostat_eta;
  96. this.model = model;
  97. this.prompt = prompt;
  98. this.path_session = path_session;
  99. this.input_prefix = input_prefix;
  100. this.input_suffix = input_suffix;
  101. if (antiprompt == null)
  102. {
  103. antiprompt = new List<string>();
  104. }
  105. this.antiprompt = antiprompt;
  106. this.lora_adapter = lora_adapter;
  107. this.lora_base = lora_base;
  108. this.memory_f16 = memory_f16;
  109. this.random_prompt = random_prompt;
  110. this.use_color = use_color;
  111. this.interactive = interactive;
  112. this.prompt_cache_all = prompt_cache_all;
  113. this.embedding = embedding;
  114. this.interactive_first = interactive_first;
  115. this.instruct = instruct;
  116. this.penalize_nl = penalize_nl;
  117. this.perplexity = perplexity;
  118. this.use_mmap = use_mmap;
  119. this.use_mlock = use_mlock;
  120. this.mem_test = mem_test;
  121. this.verbose_prompt = verbose_prompt;
  122. }
  123. }
  124. }