# SafeLlamaModelHandle Namespace: LLama.Native A reference to a set of llama model weights ```csharp public sealed class SafeLlamaModelHandle : SafeLLamaHandleBase, System.IDisposable ``` Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [CriticalFinalizerObject](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.constrainedexecution.criticalfinalizerobject) → [SafeHandle](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.safehandle) → [SafeLLamaHandleBase](./llama.native.safellamahandlebase.md) → [SafeLlamaModelHandle](./llama.native.safellamamodelhandle.md)
Implements [IDisposable](https://docs.microsoft.com/en-us/dotnet/api/system.idisposable) ## Properties ### **VocabCount** Total number of tokens in vocabulary of this model ```csharp public int VocabCount { get; } ``` #### Property Value [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)
### **ContextSize** Total number of tokens in the context ```csharp public int ContextSize { get; } ``` #### Property Value [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)
### **EmbeddingSize** Dimension of embedding vectors ```csharp public int EmbeddingSize { get; } ``` #### Property Value [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)
### **IsInvalid** ```csharp public bool IsInvalid { get; } ``` #### Property Value [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)
### **IsClosed** ```csharp public bool IsClosed { get; } ``` #### Property Value [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)
## Methods ### **ReleaseHandle()** ```csharp protected bool ReleaseHandle() ``` #### Returns [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)
### **LoadFromFile(String, LLamaContextParams)** Load a model from the given file path into memory ```csharp public static SafeLlamaModelHandle LoadFromFile(string modelPath, LLamaContextParams lparams) ``` #### Parameters `modelPath` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)
`lparams` [LLamaContextParams](./llama.native.llamacontextparams.md)
#### Returns [SafeLlamaModelHandle](./llama.native.safellamamodelhandle.md)
#### Exceptions [RuntimeError](./llama.exceptions.runtimeerror.md)
### **ApplyLoraFromFile(String, String, Int32)** Apply a LoRA adapter to a loaded model ```csharp public void ApplyLoraFromFile(string lora, string modelBase, int threads) ``` #### Parameters `lora` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)
`modelBase` [String](https://docs.microsoft.com/en-us/dotnet/api/system.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](https://docs.microsoft.com/en-us/dotnet/api/system.int32)
#### Exceptions [RuntimeError](./llama.exceptions.runtimeerror.md)
### **TokenToSpan(Int32, Span<Byte>)** Convert a single llama token into bytes ```csharp public int TokenToSpan(int llama_token, Span dest) ``` #### Parameters `llama_token` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)
Token to decode `dest` [Span<Byte>](https://docs.microsoft.com/en-us/dotnet/api/system.span-1)
A span to attempt to write into. If this is too small nothing will be written #### Returns [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)
The size of this token. **nothing will be written** if this is larger than `dest` ### **TokenToString(Int32, Encoding)** Convert a single llama token into a string ```csharp public string TokenToString(int llama_token, Encoding encoding) ``` #### Parameters `llama_token` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)
`encoding` [Encoding](https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding)
Encoding to use to decode the bytes into a string #### Returns [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)
### **TokenToString(Int32, Encoding, StringBuilder)** Append a single llama token to a string builder ```csharp public void TokenToString(int llama_token, Encoding encoding, StringBuilder dest) ``` #### Parameters `llama_token` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)
Token to decode `encoding` [Encoding](https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding)
`dest` [StringBuilder](https://docs.microsoft.com/en-us/dotnet/api/system.text.stringbuilder)
string builder to append the result to ### **Tokenize(String, Boolean, Encoding)** Convert a string of text into tokens ```csharp public Int32[] Tokenize(string text, bool add_bos, Encoding encoding) ``` #### Parameters `text` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)
`add_bos` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)
`encoding` [Encoding](https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding)
#### Returns [Int32[]](https://docs.microsoft.com/en-us/dotnet/api/system.int32)
### **CreateContext(LLamaContextParams)** Create a new context for this model ```csharp public SafeLLamaContextHandle CreateContext(LLamaContextParams params) ``` #### Parameters `params` [LLamaContextParams](./llama.native.llamacontextparams.md)
#### Returns [SafeLLamaContextHandle](./llama.native.safellamacontexthandle.md)