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

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