SafeLlamaModelHandle
Namespace: LLama.Native
A reference to a set of llama model weights
1 |
|
Inheritance Object → CriticalFinalizerObject → SafeHandle → SafeLLamaHandleBase → SafeLlamaModelHandle
Implements IDisposable
Attributes NullableContextAttribute, NullableAttribute
Fields
handle
1 |
|
Properties
RopeType
Get the rope (positional embedding) type for this model
1 |
|
Property Value
ContextSize
The number of tokens in the context that this model was trained for
1 |
|
Property Value
RopeFrequency
Get the rope frequency this model was trained with
1 |
|
Property Value
EmbeddingSize
Dimension of embedding vectors
1 |
|
Property Value
SizeInBytes
Get the size of this model in bytes
1 |
|
Property Value
ParameterCount
Get the number of parameters in this model
1 |
|
Property Value
LayerCount
Get the number of layers in this model
1 |
|
Property Value
HeadCount
Get the number of heads in this model
1 |
|
Property Value
KVHeadCount
Get the number of KV heads in this model
1 |
|
Property Value
HasEncoder
Returns true if the model contains an encoder that requires llama_encode() call
1 |
|
Property Value
HasDecoder
Returns true if the model contains a decoder that requires llama_decode() call
1 |
|
Property Value
IsRecurrent
Returns true if the model is recurrent (like Mamba, RWKV, etc.)
1 |
|
Property Value
Description
Get a description of this model
1 |
|
Property Value
MetadataCount
Get the number of metadata key/value pairs
1 |
|
Property Value
Vocab
Get the vocabulary of this model
1 |
|
Property Value
IsInvalid
1 |
|
Property Value
IsClosed
1 |
|
Property Value
Constructors
SafeLlamaModelHandle()
1 |
|
Methods
ReleaseHandle()
1 |
|
Returns
LoadFromFile(String, LLamaModelParams)
Load a model from the given file path into memory
1 |
|
Parameters
modelPath
String
lparams
LLamaModelParams
Returns
Exceptions
LoadLoraFromFile(String)
Load a LoRA adapter from file. The adapter will be associated with this model but will not be applied
1 |
|
Parameters
path
String
Returns
Exceptions
TokenToSpan(LLamaToken, Span<Byte>, Int32, Boolean)
Convert a single llama token into bytes
1 |
|
Parameters
token
LLamaToken
Token to decode
dest
Span<Byte>
A span to attempt to write into. If this is too small nothing will be written
lstrip
Int32
User can skip up to 'lstrip' leading spaces before copying (useful when encoding/decoding multiple tokens with 'add_space_prefix')
special
Boolean
If true, special characters will be converted to text. If false they will be invisible.
Returns
UInt32
The size of this token. nothing will be written if this is larger than dest
Tokenize(String, Boolean, Boolean, Encoding)
Convert a string of text into tokens
1 |
|
Parameters
text
String
addBos
Boolean
special
Boolean
Allow tokenizing special and/or control tokens which otherwise are not exposed and treated as plaintext.
encoding
Encoding
Returns
CreateContext(LLamaContextParams)
Create a new context for this model
1 |
|
Parameters
params
LLamaContextParams
Returns
MetadataValueByKey(String)
Get the metadata value for the given key
1 |
|
Parameters
key
String
The key to fetch
Returns
Nullable<Memory<Byte>>
The value, null if there is no such key
MetadataKeyByIndex(Int32)
Get the metadata key for the given index
1 |
|
Parameters
index
Int32
The index to get
Returns
Nullable<Memory<Byte>>
The key, null if there is no such key or if the buffer was too small
MetadataValueByIndex(Int32)
Get the metadata value for the given index
1 |
|
Parameters
index
Int32
The index to get
Returns
Nullable<Memory<Byte>>
The value, null if there is no such value or if the buffer was too small
GetTemplate(String, Boolean)
Get the default chat template. Returns nullptr if not available If name is NULL, returns the default chat template
1 |
|
Parameters
name
String
The name of the template, in case there are many or differently named. Set to 'null' for the default behaviour of finding an appropriate match.
strict
Boolean
Setting this to true will cause the call to throw if no valid templates are found.