Namespace: LLama
The abstraction of a LLama model, which holds the context in the native library.
public class LLamaModel : System.IDisposable
Inheritance Object → LLamaModel
Implements IDisposable
The context size.
public int ContextSize { get; }
The model params set for this model.
public ModelParams Params { get; set; }
The native handle, which is used to be passed to the native APIs. Please avoid using it
unless you know what is the usage of the Native API.
public SafeLLamaContextHandle NativeHandle { get; }
The encoding set for this model to deal with text input.
public Encoding Encoding { get; }
public LLamaModel(ModelParams Params, string encoding, ILLamaLogger logger)
Params ModelParams
Model params.
encoding String
Encoding to deal with text input.
logger ILLamaLogger
The logger.
Tokenize a string.
public IEnumerable<int> Tokenize(string text, bool addBos)
text String
addBos Boolean
Whether to add a bos to the text.
Detokenize the tokens to text.
public string DeTokenize(IEnumerable<int> tokens)
tokens IEnumerable<Int32>
Save the state to specified path.
public void SaveState(string filename)
filename String
Get the state data as a byte array.
public Byte[] GetStateData()
Load the state from specified path.
public void LoadState(string filename)
filename String
Load the state from memory.
public void LoadState(Byte[] stateData)
stateData Byte[]
Perform the sampling. Please don't use it unless you fully know what it does.
public int Sample(LLamaTokenDataArray candidates, float temperature, MiroStateType mirostat, float mirostatTau, float mirostatEta, int topK, float topP, float tfsZ, float typicalP)
candidates LLamaTokenDataArray
temperature Single
mirostat MiroStateType
mirostatTau Single
mirostatEta Single
topK Int32
topP Single
tfsZ Single
typicalP Single
Apply the penalty for the tokens. Please don't use it unless you fully know what it does.
public LLamaTokenDataArray ApplyPenalty(IEnumerable<int> lastTokens, Dictionary<int, float> logitBias, int repeatLastTokensCount, float repeatPenalty, float alphaFrequency, float alphaPresence, bool penalizeNL)
lastTokens IEnumerable<Int32>
logitBias Dictionary<Int32, Single>
repeatLastTokensCount Int32
repeatPenalty Single
alphaFrequency Single
alphaPresence Single
penalizeNL Boolean
public int Eval(Int32[] tokens, int pastTokensCount)
tokens Int32[]
pastTokensCount Int32
Int32
The updated pastTokensCount.
internal IEnumerable<string> GenerateResult(IEnumerable<int> ids)
public void Dispose()