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

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

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