Namespace: LLama.Native
A reference to a set of llama model weights
public sealed class SafeLlamaModelHandle : SafeLLamaHandleBase, System.IDisposable
Inheritance Object → CriticalFinalizerObject → SafeHandle → SafeLLamaHandleBase → SafeLlamaModelHandle
Implements IDisposable
Total number of tokens in vocabulary of this model
public int VocabCount { get; }
Total number of tokens in the context
public int ContextSize { get; }
Dimension of embedding vectors
public int EmbeddingSize { get; }
public bool IsInvalid { get; }
public bool IsClosed { get; }
protected bool ReleaseHandle()
Load a model from the given file path into memory
public static SafeLlamaModelHandle LoadFromFile(string modelPath, LLamaContextParams lparams)
modelPath String
lparams LLamaContextParams
Apply a LoRA adapter to a loaded model
public void ApplyLoraFromFile(string lora, string modelBase, int threads)
lora String
modelBase String
A path to a higher quality model to use as a base for the layers modified by the
adapter. Can be NULL to use the current loaded model.
threads Int32
Convert a single llama token into bytes
public int TokenToSpan(int llama_token, Span<byte> dest)
llama_token Int32
Token to decode
dest Span<Byte>
A span to attempt to write into. If this is too small nothing will be written
Int32
The size of this token. nothing will be written if this is larger than dest
Convert a single llama token into a string
public string TokenToString(int llama_token, Encoding encoding)
llama_token Int32
encoding Encoding
Encoding to use to decode the bytes into a string
Append a single llama token to a string builder
public void TokenToString(int llama_token, Encoding encoding, StringBuilder dest)
llama_token Int32
Token to decode
encoding Encoding
dest StringBuilder
string builder to append the result to
Convert a string of text into tokens
public Int32[] Tokenize(string text, bool add_bos, Encoding encoding)
text String
add_bos Boolean
encoding Encoding
Create a new context for this model
public SafeLLamaContextHandle CreateContext(LLamaContextParams params)
params LLamaContextParams