-
Notifications
You must be signed in to change notification settings - Fork 370
/
Copy pathModelParams.cs
143 lines (106 loc) · 3.78 KB
/
ModelParams.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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; }
/// <inheritdoc />
public int GpuLayerCount { get; set; } = 20;
/// <inheritdoc />
public uint SeqMax { get; set; } = 1;
/// <inheritdoc />
public bool UseMemorymap { get; set; } = true;
/// <inheritdoc />
public bool UseMemoryLock { get; set; }
/// <inheritdoc />
public string ModelPath { get; set; }
/// <inheritdoc />
public int? Threads { get; set; }
/// <inheritdoc />
public int? BatchThreads { get; set; }
/// <inheritdoc />
public uint BatchSize { get; set; } = 512;
/// <inheritdoc />
public uint UBatchSize { get; set; } = 512;
/// <inheritdoc />
public bool Embeddings { get; set; }
/// <inheritdoc />
public TensorSplitsCollection TensorSplits { get; set; } = new();
/// <inheritdoc />
public bool CheckTensors { get; }
/// <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 bool FlashAttention { get; set; }
/// <inheritdoc />
public float? DefragThreshold { get; set; }
/// <inheritdoc />
public LLamaPoolingType PoolingType { get; set; } = LLamaPoolingType.Unspecified;
/// <inheritdoc />
public LLamaAttentionType AttentionType { get; set; } = LLamaAttentionType.Unspecified;
/// <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 = "";
}
}
}