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