2023-09-30 23:21:18 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2023-08-24 07:09:00 +08:00
|
|
|
|
|
|
|
|
|
namespace LLama.Abstractions
|
2023-08-06 06:44:54 +08:00
|
|
|
|
{
|
2023-08-25 06:15:53 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The parameters for initializing a LLama model.
|
|
|
|
|
/// </summary>
|
2023-08-06 06:44:54 +08:00
|
|
|
|
public interface IModelParams
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// the GPU that is used for scratch and small tensors
|
|
|
|
|
/// </summary>
|
|
|
|
|
int MainGpu { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Number of layers to run in VRAM / GPU memory (n_gpu_layers)
|
|
|
|
|
/// </summary>
|
|
|
|
|
int GpuLayerCount { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Use mmap for faster loads (use_mmap)
|
|
|
|
|
/// </summary>
|
|
|
|
|
bool UseMemorymap { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Use mlock to keep model in memory (use_mlock)
|
|
|
|
|
/// </summary>
|
|
|
|
|
bool UseMemoryLock { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Model path (model)
|
|
|
|
|
/// </summary>
|
|
|
|
|
string ModelPath { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// how split tensors should be distributed across GPUs
|
|
|
|
|
/// </summary>
|
2023-08-07 03:29:38 +08:00
|
|
|
|
float[]? TensorSplits { get; set; }
|
2023-08-06 06:44:54 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-09-30 23:21:18 +08:00
|
|
|
|
/// Load vocab only (no weights)
|
2023-08-06 06:44:54 +08:00
|
|
|
|
/// </summary>
|
2023-09-30 23:21:18 +08:00
|
|
|
|
bool VocabOnly { get; set; }
|
2023-08-06 06:44:54 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-09-30 23:21:18 +08:00
|
|
|
|
/// List of LoRA adapters to apply
|
2023-08-06 06:44:54 +08:00
|
|
|
|
/// </summary>
|
2023-09-30 23:21:18 +08:00
|
|
|
|
AdapterCollection LoraAdapters { get; }
|
2023-08-06 06:44:54 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-09-30 23:21:18 +08:00
|
|
|
|
/// base model path for the lora adapter (lora_base)
|
2023-08-06 06:44:54 +08:00
|
|
|
|
/// </summary>
|
2023-09-30 23:21:18 +08:00
|
|
|
|
string LoraBase { get; set; }
|
|
|
|
|
}
|
2023-08-22 08:25:45 +08:00
|
|
|
|
|
2023-09-30 23:21:18 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A LoRA adapter to apply to a model
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Path">Path to the LoRA file</param>
|
|
|
|
|
/// <param name="Scale">Strength of this LoRA</param>
|
|
|
|
|
public readonly record struct LoraAdapter(string Path, float Scale);
|
2023-09-29 08:18:21 +08:00
|
|
|
|
|
2023-09-30 23:21:18 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A list of LoraAdapter objects
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class AdapterCollection
|
|
|
|
|
: List<LoraAdapter>, IEquatable<AdapterCollection>
|
|
|
|
|
{
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public bool Equals(AdapterCollection? other)
|
|
|
|
|
{
|
|
|
|
|
if (other == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return this.SequenceEqual(other);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public override bool Equals(object? obj)
|
|
|
|
|
{
|
|
|
|
|
return Equals(obj as AdapterCollection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
|
|
|
|
unchecked
|
|
|
|
|
{
|
|
|
|
|
var hash = 17;
|
|
|
|
|
for (var i = 0; i < Count; i++)
|
|
|
|
|
{
|
|
|
|
|
hash += this[i].GetHashCode();
|
|
|
|
|
hash *= 7823;
|
|
|
|
|
}
|
|
|
|
|
return hash;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-06 06:44:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|