Llama::Model
Wrapper for the llama_model structure
Constructors
Creates a new Model instance by loading a model from a file.
Parameters:
- path: Path to the model file (.gguf format).
- n_gpu_layers: Number of layers to store in VRAM (default: 0). If 0, all layers are loaded to the CPU.
- use_mmap: Use mmap if possible (default: true). Reduces memory usage.
- use_mlock: Force the system to keep the model in RAM (default: false). May improve performance but increases memory usage.
- vocab_only: Only load the vocabulary, no weights (default: false). Useful for inspecting the vocabulary.
Raises:
- Llama::Model::Error if the model cannot be loaded.
Instance methods
Gets the default chat template for this model
Parameters:
- name: Optional template name (nil for default)
Returns:
- The chat template string, or nil if not available
Returns whether this model is a classifier model
Returns:
- true if the model has classifier outputs, false otherwise
Returns the classifier label by index
Parameters:
- i: Index of the classifier output (must be < n_cls_out)
Returns:
- The classifier label, or nil if index is out of bounds or no label is provided
Creates a new Context for this model
This method delegates to Context.new, passing self as the model parameter and forwarding all other arguments.
Returns:
- A new Context instance
Raises:
- Llama::Context::Error if the context cannot be created
Returns the token that must be provided to the decoder to start generating output For encoder-decoder models, returns the decoder start token For other models, returns -1
Gets the number of metadata key/value pairs
Returns:
- The number of metadata entries
Gets a metadata key name by index
Parameters:
- i: The index of the metadata entry
Returns:
- The key name, or nil if the index is out of bounds
Gets a metadata value as a string by key name
Parameters:
- key: The metadata key to look up
Returns:
- The metadata value as a string, or nil if not found
Gets a metadata value as a string by index
Parameters:
- i: The index of the metadata entry
Returns:
- The value as a string, or nil if the index is out of bounds
Returns the total size of all the tensors in the model in bytes
Returns:
- The total size of all tensors in the model (in bytes)
Returns the number of classifier outputs (only valid for classifier models) Returns 0 for non-classifier models