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 2.9 kB

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