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.

InferenceParams.cs 3.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using LLama.Abstractions;
  2. using System;
  3. using System.Collections.Generic;
  4. using LLama.Native;
  5. using LLama.Sampling;
  6. using LLama.Control;
  7. using LLama.Transform;
  8. using System.Text;
  9. namespace LLama.Common
  10. {
  11. using llama_token = Int32;
  12. /// <summary>
  13. /// The paramters used for inference.
  14. /// </summary>
  15. public record InferenceParams
  16. : IInferenceParams
  17. {
  18. /// <summary>
  19. /// number of tokens to keep from initial prompt
  20. /// </summary>
  21. public int TokensKeep { get; set; } = 0;
  22. /// <summary>
  23. /// how many new tokens to predict (n_predict), set to -1 to inifinitely generate response
  24. /// until it complete.
  25. /// </summary>
  26. public int MaxTokens { get; set; } = -1;
  27. /// <summary>
  28. /// logit bias for specific tokens
  29. /// </summary>
  30. public Dictionary<llama_token, float>? LogitBias { get; set; } = null;
  31. /// <summary>
  32. /// Sequences where the model will stop generating further tokens.
  33. /// </summary>
  34. public IReadOnlyList<string> AntiPrompts { get; set; } = Array.Empty<string>();
  35. /// <inheritdoc />
  36. public int TopK { get; set; } = 40;
  37. /// <inheritdoc />
  38. public float TopP { get; set; } = 0.95f;
  39. /// <inheritdoc />
  40. public float MinP { get; set; } = 0.05f;
  41. /// <inheritdoc />
  42. public float TfsZ { get; set; } = 1.0f;
  43. /// <inheritdoc />
  44. public float TypicalP { get; set; } = 1.0f;
  45. /// <inheritdoc />
  46. public float Temperature { get; set; } = 0.8f;
  47. /// <inheritdoc />
  48. public float RepeatPenalty { get; set; } = 1.1f;
  49. /// <inheritdoc />
  50. public int RepeatLastTokensCount { get; set; } = 64;
  51. /// <inheritdoc />
  52. public float FrequencyPenalty { get; set; } = .0f;
  53. /// <inheritdoc />
  54. public float PresencePenalty { get; set; } = .0f;
  55. /// <inheritdoc />
  56. public MirostatType Mirostat { get; set; } = MirostatType.Disable;
  57. /// <inheritdoc />
  58. public float MirostatTau { get; set; } = 5.0f;
  59. /// <inheritdoc />
  60. public float MirostatEta { get; set; } = 0.1f;
  61. /// <inheritdoc />
  62. public bool PenalizeNL { get; set; } = true;
  63. /// <inheritdoc />
  64. public SafeLLamaGrammarHandle? Grammar { get; set; }
  65. /// <inheritdoc />
  66. public ISamplingPipeline? SamplingPipeline { get; set; }
  67. /// <inheritdoc />
  68. public IGenerationControl GenerationControl { get; set; } = new DefaultGenerationControl();
  69. /// <inheritdoc />
  70. public ITokenizer Tokenizer { get; set; } = new DefaultTokenizer(Encoding.UTF8);
  71. }
  72. /// <summary>
  73. /// Type of "mirostat" sampling to use.
  74. /// https://github.com/basusourya/mirostat
  75. /// </summary>
  76. public enum MirostatType
  77. {
  78. /// <summary>
  79. /// Disable Mirostat sampling
  80. /// </summary>
  81. Disable = 0,
  82. /// <summary>
  83. /// Original mirostat algorithm
  84. /// </summary>
  85. Mirostat = 1,
  86. /// <summary>
  87. /// Mirostat 2.0 algorithm
  88. /// </summary>
  89. Mirostat2 = 2
  90. }
  91. }