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.

ModelParams.cs 3.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using LLama.Abstractions;
  2. using System.Text;
  3. using System.Text.Json.Serialization;
  4. using LLama.Native;
  5. using System.Collections.Generic;
  6. namespace LLama.Common
  7. {
  8. /// <summary>
  9. /// The parameters for initializing a LLama model.
  10. /// </summary>
  11. public record ModelParams
  12. : ILLamaParams
  13. {
  14. /// <inheritdoc />
  15. public uint? ContextSize { get; set; }
  16. /// <inheritdoc />
  17. public int MainGpu { get; set; } = 0;
  18. /// <inheritdoc />
  19. public GPUSplitMode SplitMode { get; set; } = GPUSplitMode.None;
  20. /// <inheritdoc />
  21. public int GpuLayerCount { get; set; } = 20;
  22. /// <inheritdoc />
  23. public uint Seed { get; set; } = 0xFFFFFFFF;
  24. /// <inheritdoc />
  25. public bool UseMemorymap { get; set; } = true;
  26. /// <inheritdoc />
  27. public bool UseMemoryLock { get; set; }
  28. /// <inheritdoc />
  29. public string ModelPath { get; set; }
  30. /// <inheritdoc />
  31. public AdapterCollection LoraAdapters { get; set; } = new();
  32. /// <inheritdoc />
  33. public string LoraBase { get; set; } = string.Empty;
  34. /// <inheritdoc />
  35. public uint? Threads { get; set; }
  36. /// <inheritdoc />
  37. public uint? BatchThreads { get; set; }
  38. /// <inheritdoc />
  39. public uint BatchSize { get; set; } = 512;
  40. /// <inheritdoc />
  41. public bool EmbeddingMode { get; set; }
  42. /// <inheritdoc />
  43. public TensorSplitsCollection TensorSplits { get; set; } = new();
  44. /// <inheritdoc />
  45. public List<MetadataOverride> MetadataOverrides { get; set; } = new();
  46. /// <inheritdoc />
  47. public float? RopeFrequencyBase { get; set; }
  48. /// <inheritdoc />
  49. public float? RopeFrequencyScale { get; set; }
  50. /// <inheritdoc />
  51. public float? YarnExtrapolationFactor { get; set; }
  52. /// <inheritdoc />
  53. public float? YarnAttentionFactor { get; set; }
  54. /// <inheritdoc />
  55. public float? YarnBetaFast { get; set; }
  56. /// <inheritdoc />
  57. public float? YarnBetaSlow { get; set; }
  58. /// <inheritdoc />
  59. public uint? YarnOriginalContext { get; set; }
  60. /// <inheritdoc />
  61. public RopeScalingType? YarnScalingType { get; set; }
  62. /// <inheritdoc />
  63. public GGMLType? TypeK { get; set; }
  64. /// <inheritdoc />
  65. public GGMLType? TypeV { get; set; }
  66. /// <inheritdoc />
  67. public bool NoKqvOffload { get; set; }
  68. /// <inheritdoc />
  69. public float DefragThreshold { get; set; }
  70. /// <inheritdoc />
  71. public bool DoPooling { get; set; }
  72. /// <inheritdoc />
  73. public bool VocabOnly { get; set; }
  74. /// <summary>
  75. /// `Encoding` cannot be directly JSON serialized, instead store the name as a string which can
  76. /// </summary>
  77. [JsonPropertyName("Encoding")]
  78. [JsonInclude]
  79. private string EncodingName { get; set; } = Encoding.UTF8.WebName;
  80. /// <inheritdoc />
  81. [JsonIgnore]
  82. public Encoding Encoding
  83. {
  84. get => Encoding.GetEncoding(EncodingName);
  85. set => EncodingName = value.WebName;
  86. }
  87. /// <summary>
  88. ///
  89. /// </summary>
  90. /// <param name="modelPath">The model path.</param>
  91. [JsonConstructor]
  92. public ModelParams(string modelPath)
  93. {
  94. ModelPath = modelPath;
  95. }
  96. private ModelParams()
  97. {
  98. // This constructor (default parameterless constructor) is used by Newtonsoft to deserialize!
  99. ModelPath = "";
  100. }
  101. }
  102. }