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.

IModelParams.cs 2.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace LLama.Abstractions
  5. {
  6. /// <summary>
  7. /// The parameters for initializing a LLama model.
  8. /// </summary>
  9. public interface IModelParams
  10. {
  11. /// <summary>
  12. /// the GPU that is used for scratch and small tensors
  13. /// </summary>
  14. int MainGpu { get; set; }
  15. /// <summary>
  16. /// Number of layers to run in VRAM / GPU memory (n_gpu_layers)
  17. /// </summary>
  18. int GpuLayerCount { get; set; }
  19. /// <summary>
  20. /// Use mmap for faster loads (use_mmap)
  21. /// </summary>
  22. bool UseMemorymap { get; set; }
  23. /// <summary>
  24. /// Use mlock to keep model in memory (use_mlock)
  25. /// </summary>
  26. bool UseMemoryLock { get; set; }
  27. /// <summary>
  28. /// Model path (model)
  29. /// </summary>
  30. string ModelPath { get; set; }
  31. /// <summary>
  32. /// Number of threads (-1 = autodetect) (n_threads)
  33. /// </summary>
  34. int Threads { get; set; }
  35. /// <summary>
  36. /// how split tensors should be distributed across GPUs
  37. /// </summary>
  38. float[]? TensorSplits { get; set; }
  39. /// <summary>
  40. /// Load vocab only (no weights)
  41. /// </summary>
  42. bool VocabOnly { get; set; }
  43. /// <summary>
  44. /// List of LoRA adapters to apply
  45. /// </summary>
  46. AdapterCollection LoraAdapters { get; }
  47. /// <summary>
  48. /// base model path for the lora adapter (lora_base)
  49. /// </summary>
  50. string LoraBase { get; set; }
  51. }
  52. /// <summary>
  53. /// A LoRA adapter to apply to a model
  54. /// </summary>
  55. /// <param name="Path">Path to the LoRA file</param>
  56. /// <param name="Scale">Strength of this LoRA</param>
  57. public readonly record struct LoraAdapter(string Path, float Scale);
  58. /// <summary>
  59. /// A list of LoraAdapter objects
  60. /// </summary>
  61. public sealed class AdapterCollection
  62. : List<LoraAdapter>, IEquatable<AdapterCollection>
  63. {
  64. /// <inheritdoc />
  65. public bool Equals(AdapterCollection? other)
  66. {
  67. if (other == null)
  68. return false;
  69. return this.SequenceEqual(other);
  70. }
  71. /// <inheritdoc/>
  72. public override bool Equals(object? obj)
  73. {
  74. return Equals(obj as AdapterCollection);
  75. }
  76. /// <inheritdoc/>
  77. public override int GetHashCode()
  78. {
  79. unchecked
  80. {
  81. var hash = 17;
  82. for (var i = 0; i < Count; i++)
  83. {
  84. hash += this[i].GetHashCode();
  85. hash *= 7823;
  86. }
  87. return hash;
  88. }
  89. }
  90. }
  91. }