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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 int GpuLayerCount { get; set; } = 20;
  20. /// <inheritdoc />
  21. public uint Seed { get; set; } = 0xFFFFFFFF;
  22. /// <inheritdoc />
  23. public bool UseMemorymap { get; set; } = true;
  24. /// <inheritdoc />
  25. public bool UseMemoryLock { get; set; }
  26. /// <inheritdoc />
  27. public string ModelPath { get; set; }
  28. /// <inheritdoc />
  29. public AdapterCollection LoraAdapters { get; set; } = new();
  30. /// <inheritdoc />
  31. public string LoraBase { get; set; } = string.Empty;
  32. /// <inheritdoc />
  33. public uint? Threads { get; set; }
  34. /// <inheritdoc />
  35. public uint? BatchThreads { get; set; }
  36. /// <inheritdoc />
  37. public uint BatchSize { get; set; } = 512;
  38. /// <inheritdoc />
  39. public bool EmbeddingMode { get; set; }
  40. /// <inheritdoc />
  41. public TensorSplitsCollection TensorSplits { get; set; } = new();
  42. /// <inheritdoc />
  43. public List<MetadataOverride> MetadataOverrides { get; } = new();
  44. /// <inheritdoc />
  45. public float? RopeFrequencyBase { get; set; }
  46. /// <inheritdoc />
  47. public float? RopeFrequencyScale { get; set; }
  48. /// <inheritdoc />
  49. public float? YarnExtrapolationFactor { get; set; }
  50. /// <inheritdoc />
  51. public float? YarnAttentionFactor { get; set; }
  52. /// <inheritdoc />
  53. public float? YarnBetaFast { get; set; }
  54. /// <inheritdoc />
  55. public float? YarnBetaSlow { get; set; }
  56. /// <inheritdoc />
  57. public uint? YarnOriginalContext { get; set; }
  58. /// <inheritdoc />
  59. public RopeScalingType? YarnScalingType { get; set; }
  60. /// <inheritdoc />
  61. public GGMLType? TypeK { get; set; }
  62. /// <inheritdoc />
  63. public GGMLType? TypeV { get; set; }
  64. /// <inheritdoc />
  65. public bool NoKqvOffload { get; set; }
  66. /// <inheritdoc />
  67. public bool VocabOnly { get; set; }
  68. /// <summary>
  69. /// `Encoding` cannot be directly JSON serialized, instead store the name as a string which can
  70. /// </summary>
  71. [JsonPropertyName("Encoding")]
  72. [JsonInclude]
  73. private string EncodingName { get; set; } = Encoding.UTF8.WebName;
  74. /// <inheritdoc />
  75. [JsonIgnore]
  76. public Encoding Encoding
  77. {
  78. get => Encoding.GetEncoding(EncodingName);
  79. set => EncodingName = value.WebName;
  80. }
  81. /// <summary>
  82. ///
  83. /// </summary>
  84. /// <param name="modelPath">The model path.</param>
  85. [JsonConstructor]
  86. public ModelParams(string modelPath)
  87. {
  88. ModelPath = modelPath;
  89. }
  90. private ModelParams()
  91. {
  92. // This constructor (default parameterless constructor) is used by Newtonsoft to deserialize!
  93. ModelPath = "";
  94. }
  95. }
  96. }