|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- using LLama.Abstractions;
- using System.Text;
- using System.Text.Json.Serialization;
- using LLama.Native;
- using System.Collections.Generic;
-
- namespace LLama.Common
- {
- /// <summary>
- /// The parameters for initializing a LLama model.
- /// </summary>
- public record ModelParams
- : ILLamaParams
- {
- /// <inheritdoc />
- public uint? ContextSize { get; set; }
-
- /// <inheritdoc />
- public int MainGpu { get; set; } = 0;
-
- /// <inheritdoc />
- public GPUSplitMode SplitMode { get; set; } = GPUSplitMode.None;
-
- /// <inheritdoc />
- public int GpuLayerCount { get; set; } = 20;
-
- /// <inheritdoc />
- public uint Seed { get; set; } = 0xFFFFFFFF;
-
- /// <inheritdoc />
- public bool UseMemorymap { get; set; } = true;
-
- /// <inheritdoc />
- public bool UseMemoryLock { get; set; }
-
- /// <inheritdoc />
- public string ModelPath { get; set; }
-
- /// <inheritdoc />
- public AdapterCollection LoraAdapters { get; set; } = new();
-
- /// <inheritdoc />
- public string LoraBase { get; set; } = string.Empty;
-
- /// <inheritdoc />
- public uint? Threads { get; set; }
-
- /// <inheritdoc />
- public uint? BatchThreads { get; set; }
-
- /// <inheritdoc />
- public uint BatchSize { get; set; } = 512;
-
- /// <inheritdoc />
- public bool EmbeddingMode { get; set; }
-
- /// <inheritdoc />
- public TensorSplitsCollection TensorSplits { get; set; } = new();
-
- /// <inheritdoc />
- public List<MetadataOverride> MetadataOverrides { get; set; } = new();
-
- /// <inheritdoc />
- public float? RopeFrequencyBase { get; set; }
-
- /// <inheritdoc />
- public float? RopeFrequencyScale { get; set; }
-
- /// <inheritdoc />
- public float? YarnExtrapolationFactor { get; set; }
-
- /// <inheritdoc />
- public float? YarnAttentionFactor { get; set; }
-
- /// <inheritdoc />
- public float? YarnBetaFast { get; set; }
-
- /// <inheritdoc />
- public float? YarnBetaSlow { get; set; }
-
- /// <inheritdoc />
- public uint? YarnOriginalContext { get; set; }
-
- /// <inheritdoc />
- public RopeScalingType? YarnScalingType { get; set; }
-
- /// <inheritdoc />
- public GGMLType? TypeK { get; set; }
-
- /// <inheritdoc />
- public GGMLType? TypeV { get; set; }
-
- /// <inheritdoc />
- public bool NoKqvOffload { get; set; }
-
- /// <inheritdoc />
- public float DefragThreshold { get; set; }
-
- /// <inheritdoc />
- public bool DoPooling { get; set; }
-
- /// <inheritdoc />
- public bool VocabOnly { get; set; }
-
- /// <summary>
- /// `Encoding` cannot be directly JSON serialized, instead store the name as a string which can
- /// </summary>
- [JsonPropertyName("Encoding")]
- [JsonInclude]
- private string EncodingName { get; set; } = Encoding.UTF8.WebName;
-
- /// <inheritdoc />
- [JsonIgnore]
- public Encoding Encoding
- {
- get => Encoding.GetEncoding(EncodingName);
- set => EncodingName = value.WebName;
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <param name="modelPath">The model path.</param>
- [JsonConstructor]
- public ModelParams(string modelPath)
- {
- ModelPath = modelPath;
- }
-
- private ModelParams()
- {
- // This constructor (default parameterless constructor) is used by Newtonsoft to deserialize!
- ModelPath = "";
- }
- }
- }
|