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.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 bool VocabOnly { get; set; }
  70. /// <summary>
  71. /// `Encoding` cannot be directly JSON serialized, instead store the name as a string which can
  72. /// </summary>
  73. [JsonPropertyName("Encoding")]
  74. [JsonInclude]
  75. private string EncodingName { get; set; } = Encoding.UTF8.WebName;
  76. /// <inheritdoc />
  77. [JsonIgnore]
  78. public Encoding Encoding
  79. {
  80. get => Encoding.GetEncoding(EncodingName);
  81. set => EncodingName = value.WebName;
  82. }
  83. /// <summary>
  84. ///
  85. /// </summary>
  86. /// <param name="modelPath">The model path.</param>
  87. [JsonConstructor]
  88. public ModelParams(string modelPath)
  89. {
  90. ModelPath = modelPath;
  91. }
  92. private ModelParams()
  93. {
  94. // This constructor (default parameterless constructor) is used by Newtonsoft to deserialize!
  95. ModelPath = "";
  96. }
  97. }
  98. }