Documentation
¶
Overview ¶
Package gollama provides Go bindings for ggml (the tensor library used by llama.cpp). This file contains bindings for the core GGML tensor operations and utilities.
GGML (Georgi Gerganov Machine Learning) is the tensor library that powers llama.cpp. It provides low-level operations for neural network computation.
Usage ¶
Most users should use the high-level llama.cpp API in gollama.go. Use the GGML bindings when you need direct access to tensor operations, type information, backend management, or low-level memory operations.
Important Note ¶
GGML functions may not be exported in all llama.cpp builds. This package gracefully handles missing functions by returning errors instead of panicking, allowing code to compile and run even when GGML symbols are not available.
Example Usage ¶
// Initialize the library
gollama.Backend_init()
defer gollama.Backend_free()
// Query type information
size, err := gollama.Ggml_type_size(gollama.GGML_TYPE_F32)
if err != nil {
log.Printf("GGML function not available: %v", err)
return
}
fmt.Printf("F32 size: %d bytes\n", size)
// Check if a type is quantized
isQuantized, err := gollama.Ggml_type_is_quantized(gollama.GGML_TYPE_Q4_0)
if err == nil {
fmt.Printf("Q4_0 is quantized: %v\n", isQuantized)
}
// Enumerate backend devices
count, err := gollama.Ggml_backend_dev_count()
if err == nil && count > 0 {
for i := uint64(0); i < count; i++ {
dev, _ := gollama.Ggml_backend_dev_get(i)
name, _ := gollama.Ggml_backend_dev_name(dev)
fmt.Printf("Device %d: %s\n", i, name)
}
}
For more details, see the GGML API documentation at: https://github.com/xDarkicex/librallama.cpp/blob/main/docs/GGML_API.md
Package gollama provides Go bindings for llama.cpp using purego. This package allows you to use llama.cpp functionality from Go without CGO.
The bindings are designed to be as close to the original llama.cpp C API as possible, while providing Go-friendly interfaces where appropriate.
Example usage:
// Initialize the library
gollama.Backend_init()
defer gollama.Backend_free()
// Load a model
params := gollama.Model_default_params()
model, err := gollama.Model_load_from_file("model.gguf", params)
if err != nil {
log.Fatal(err)
}
defer gollama.Model_free(model)
// Create context and generate text
ctxParams := gollama.Context_default_params()
ctx, err := gollama.Init_from_model(model, ctxParams)
if err != nil {
log.Fatal(err)
}
defer gollama.Free(ctx)
Index ¶
- Constants
- Variables
- func ApplyConfig(config *Config) error
- func Backend_free()
- func Backend_init() error
- func BatchRegisterFunctions(libHandle uintptr, functions []FunctionRegistration, tryMode bool) error
- func Batch_free(batch LlamaBatch)
- func CheckResult(result int, function string) error
- func CleanLibraryCache() error
- func Cleanup()
- func Decode(ctx LlamaContext, batch LlamaBatch) error
- func Encode(ctx LlamaContext, batch LlamaBatch) error
- func ErrorfromCode(code int) error
- func Free(ctx LlamaContext)
- func GetConfigPath() string
- func GetLibraryCacheDir() (string, error)
- func GetSHA256ForFile(filepath string) (string, error)
- func Get_embeddings(ctx LlamaContext) *float32
- func Get_embeddings_ith(ctx LlamaContext, i int32) *float32
- func Get_logits(ctx LlamaContext) *float32
- func Get_logits_ith(ctx LlamaContext, i int32) *float32
- func Ggml_backend_buffer_free(buffer GgmlBackendBuffer) error
- func Ggml_backend_buffer_get_size(buffer GgmlBackendBuffer) (uint64, error)
- func Ggml_backend_buffer_is_host(buffer GgmlBackendBuffer) (bool, error)
- func Ggml_backend_buffer_name(buffer GgmlBackendBuffer) (string, error)
- func Ggml_backend_dev_count() (uint64, error)
- func Ggml_backend_dev_description(device GgmlBackendDevice) (string, error)
- func Ggml_backend_dev_memory(device GgmlBackendDevice) (free uint64, total uint64, err error)
- func Ggml_backend_dev_name(device GgmlBackendDevice) (string, error)
- func Ggml_backend_free(backend GgmlBackend) error
- func Ggml_backend_is_cpu(backend GgmlBackend) (bool, error)
- func Ggml_backend_load_all() error
- func Ggml_backend_load_all_from_path(path string) error
- func Ggml_backend_name(backend GgmlBackend) (string, error)
- func Ggml_backend_unload(reg GgmlBackendReg) error
- func Ggml_blck_size(typ GgmlType) (int32, error)
- func Ggml_type_is_quantized(typ GgmlType) (bool, error)
- func Ggml_type_name(typ GgmlType) (string, error)
- func Ggml_type_size(typ GgmlType) (uint64, error)
- func Ggml_type_sizef(typ GgmlType) (uint64, error)
- func HandleError(err error, context string) error
- func IsFatalError(err error) bool
- func IsRetryableError(err error) bool
- func LoadLibraryWithVersion(version string) error
- func Max_devices() uint64
- func Memory_clear(ctx LlamaContext, reset bool) bool
- func MergeVariantLibraries(goos, goarch, version, libsDir string, variantDirs []string) error
- func Model_free(model LlamaModel)
- func Model_n_embd(model LlamaModel) int32
- func Must(err error)
- func PopulateLibDirectoryFromResults(results []DownloadResult, version, libsDir string) error
- func Print_system_info() string
- func RegisterFunction(fptr interface{}, name string) error
- func RegisterFunctionSet(libHandle uintptr, functions []FunctionRegistration, tryMode bool) error
- func Sampler_free(sampler LlamaSampler)
- func SetGlobalConfig(config *Config) error
- func SetGlobalErrorHandler(handler *ErrorHandler)
- func Set_causal_attn(ctx LlamaContext, causal bool)
- func Set_embeddings(ctx LlamaContext, embeddings bool)
- func Supports_gpu_offload() bool
- func Supports_mlock() bool
- func Supports_mmap() bool
- func Token_to_piece(model LlamaModel, token LlamaToken, special bool) string
- func Try(fn func() error) (err error)
- func WrapError(err error, message string) error
- func WrapErrorf(err error, format string, args ...interface{}) error
- type Config
- type DownloadResult
- type DownloadTask
- type ErrorCategory
- type ErrorHandler
- type FunctionRegistration
- type GgmlBackend
- type GgmlBackendBuffer
- type GgmlBackendBufferType
- type GgmlBackendDevCaps
- type GgmlBackendDevProps
- type GgmlBackendDevType
- type GgmlBackendDevice
- type GgmlBackendReg
- type GgmlContext
- type GgmlCplan
- type GgmlGuid
- type GgmlObject
- type GgmlOp
- type GgmlTensor
- type GgmlType
- type LibraryDownloader
- func (d *LibraryDownloader) CleanCache() error
- func (d *LibraryDownloader) DownloadAllVariants(release *ReleaseInfo, goos, goarch string) (*VariantDownloadResult, error)
- func (d *LibraryDownloader) DownloadAndExtract(downloadURL, filename string) (string, error)
- func (d *LibraryDownloader) DownloadAndExtractWithChecksum(downloadURL, filename, expectedChecksum string) (string, string, error)
- func (d *LibraryDownloader) DownloadMultiplePlatforms(platforms []string, version string) ([]DownloadResult, error)
- func (d *LibraryDownloader) FindAllVariantAssets(release *ReleaseInfo, goos, goarch string) ([]VariantAsset, error)
- func (d *LibraryDownloader) FindAssetByPattern(release *ReleaseInfo, pattern string) (string, string, error)
- func (d *LibraryDownloader) FindLibraryPath(extractedDir string) (string, error)
- func (d *LibraryDownloader) FindLibraryPathForPlatform(extractedDir, goos string) (string, error)
- func (d *LibraryDownloader) GetCacheDir() string
- func (d *LibraryDownloader) GetLatestRelease() (*ReleaseInfo, error)
- func (d *LibraryDownloader) GetPlatformAssetPattern() (string, error)
- func (d *LibraryDownloader) GetPlatformAssetPatternForPlatform(goos, goarch string) (string, error)
- func (d *LibraryDownloader) GetReleaseByTag(tag string) (*ReleaseInfo, error)
- type LibraryLoadInfo
- type LibraryLoader
- func (l *LibraryLoader) ApplyLibraryLoad(info *LibraryLoadInfo, rootPath string) error
- func (l *LibraryLoader) GetHandle() uintptr
- func (l *LibraryLoader) IsLoaded() bool
- func (l *LibraryLoader) LoadLibrary() error
- func (l *LibraryLoader) LoadLibraryWithDependencies(libPath string) (*LibraryLoadInfo, []string)
- func (l *LibraryLoader) LoadLibraryWithVersion(version string) error
- func (l *LibraryLoader) UnloadLibrary() error
- type LlamaAdapterLora
- type LlamaAttentionType
- type LlamaBatch
- type LlamaChatMessage
- type LlamaContext
- type LlamaContextParams
- type LlamaError
- type LlamaFlashAttnType
- type LlamaFtype
- type LlamaGpuBackend
- type LlamaLogitBias
- type LlamaMemory
- type LlamaModel
- type LlamaModelParams
- type LlamaModelQuantizeParams
- type LlamaPoolingType
- type LlamaPos
- type LlamaRopeScalingType
- type LlamaSampler
- type LlamaSamplerChainParams
- type LlamaSeqId
- type LlamaSplitMode
- type LlamaToken
- type LlamaTokenAttr
- type LlamaTokenData
- type LlamaTokenDataArray
- type LlamaTokenType
- type LlamaVocab
- type LlamaVocabType
- type ReleaseInfo
- type VariantAsset
- type VariantDownloadResult
- type VariantInfo
Constants ¶
const ( LLAMA_ERR_SUCCESS = 0 LLAMA_ERR_FAIL = -1 LLAMA_ERR_INVALID_PARAM = -2 LLAMA_ERR_OUT_OF_MEMORY = -3 LLAMA_ERR_FILE_NOT_FOUND = -4 LLAMA_ERR_FILE_READ = -5 LLAMA_ERR_FILE_WRITE = -6 LLAMA_ERR_INVALID_FORMAT = -7 LLAMA_ERR_UNSUPPORTED = -8 LLAMA_ERR_BACKEND_INIT = -9 LLAMA_ERR_CONTEXT_FULL = -10 LLAMA_ERR_TOKEN_INVALID = -11 LLAMA_ERR_MODEL_CORRUPTED = -12 LLAMA_ERR_GPU_UNAVAILABLE = -13 )
Error codes matching llama.cpp return values
const ( // Version is the gollama.cpp version Version = "0.2.3" // LlamaCppBuild is the llama.cpp build number this version is based on LlamaCppBuild = "b6862" // FullVersion combines both version numbers FullVersion = "v" + Version + "-llamacpp." + LlamaCppBuild )
Version information
const ( LLAMA_DEFAULT_SEED = 0xFFFFFFFF LLAMA_TOKEN_NULL = -1 // File magic numbers LLAMA_FILE_MAGIC_GGLA = 0x67676c61 LLAMA_FILE_MAGIC_GGSN = 0x6767736e LLAMA_FILE_MAGIC_GGSQ = 0x67677371 // Session constants LLAMA_SESSION_MAGIC = LLAMA_FILE_MAGIC_GGSN LLAMA_SESSION_VERSION = 9 LLAMA_STATE_SEQ_MAGIC = LLAMA_FILE_MAGIC_GGSQ LLAMA_STATE_SEQ_VERSION = 2 )
Constants from llama.h
Variables ¶
var ( // Library errors ErrLibraryNotLoaded = errors.New("llama.cpp library not loaded") ErrLibraryLoadFailed = errors.New("failed to load llama.cpp library") ErrFunctionNotFound = errors.New("function not found in library") ErrInvalidLibraryPath = errors.New("invalid library path") // Model errors ErrModelNotLoaded = errors.New("model not loaded") ErrModelLoadFailed = errors.New("failed to load model") ErrModelSaveFailed = errors.New("failed to save model") ErrInvalidModelPath = errors.New("invalid model path") ErrModelCorrupted = errors.New("model file corrupted") ErrUnsupportedModelType = errors.New("unsupported model type") // Context errors ErrContextNotCreated = errors.New("context not created") ErrContextCreationFailed = errors.New("failed to create context") ErrInvalidContextSize = errors.New("invalid context size") ErrContextFull = errors.New("context is full") // Token errors ErrTokenizationFailed = errors.New("tokenization failed") ErrInvalidToken = errors.New("invalid token") ErrTokenOutOfRange = errors.New("token out of vocabulary range") // Generation errors ErrGenerationFailed = errors.New("text generation failed") ErrSamplingFailed = errors.New("token sampling failed") ErrInvalidSamplingParams = errors.New("invalid sampling parameters") // Memory errors ErrOutOfMemory = errors.New("out of memory") ErrMemoryAllocationFailed = errors.New("memory allocation failed") ErrInvalidMemorySize = errors.New("invalid memory size") // Configuration errors ErrInvalidConfig = errors.New("invalid configuration") ErrConfigValidationFailed = errors.New("configuration validation failed") ErrUnsupportedPlatform = errors.New("unsupported platform") // Backend errors ErrBackendNotAvailable = errors.New("backend not available") ErrBackendInitFailed = errors.New("backend initialization failed") ErrGPUNotAvailable = errors.New("GPU not available") ErrCUDANotAvailable = errors.New("CUDA not available") ErrMetalNotAvailable = errors.New("metal backend not available") ErrVulkanNotAvailable = errors.New("vulkan backend not available") // File I/O errors ErrFileNotFound = errors.New("file not found") ErrFileReadFailed = errors.New("failed to read file") ErrFileWriteFailed = errors.New("failed to write file") ErrInvalidFileFormat = errors.New("invalid file format") // Parameter errors ErrInvalidParameter = errors.New("invalid parameter") ErrParameterOutOfRange = errors.New("parameter out of range") ErrMissingParameter = errors.New("missing required parameter") // Thread/concurrency errors ErrThreadingFailed = errors.New("threading operation failed") ErrConcurrencyViolation = errors.New("concurrency violation") ErrDeadlock = errors.New("deadlock detected") )
Error types for different categories of errors
Functions ¶
func ApplyConfig ¶
ApplyConfig applies the configuration to the library
func BatchRegisterFunctions ¶
func BatchRegisterFunctions(libHandle uintptr, functions []FunctionRegistration, tryMode bool) error
BatchRegisterFunctions is a convenience wrapper that registers functions in batch and returns true if all required functions were registered successfully
func CheckResult ¶
CheckResult checks a result code and returns an appropriate error
func CleanLibraryCache ¶
func CleanLibraryCache() error
CleanLibraryCache removes cached library files to force re-download
func ErrorfromCode ¶
ErrorfromCode converts a llama.cpp error code to a Go error
func GetConfigPath ¶
func GetConfigPath() string
GetConfigPath returns the default configuration file path
func GetLibraryCacheDir ¶
GetLibraryCacheDir returns the directory where downloaded libraries are cached
func GetSHA256ForFile ¶
GetSHA256ForFile calculates the SHA256 checksum for a given file
func Get_embeddings ¶
func Get_embeddings(ctx LlamaContext) *float32
Get_embeddings returns the embeddings for the context
func Get_embeddings_ith ¶
func Get_embeddings_ith(ctx LlamaContext, i int32) *float32
Get_embeddings_ith returns the embeddings for the ith sequence in the context
func Get_logits_ith ¶
func Get_logits_ith(ctx LlamaContext, i int32) *float32
Get_logits_ith gets logits for a specific token
func Ggml_backend_buffer_free ¶
func Ggml_backend_buffer_free(buffer GgmlBackendBuffer) error
Ggml_backend_buffer_free frees a backend buffer
func Ggml_backend_buffer_get_size ¶
func Ggml_backend_buffer_get_size(buffer GgmlBackendBuffer) (uint64, error)
Ggml_backend_buffer_get_size returns the size of a backend buffer
func Ggml_backend_buffer_is_host ¶
func Ggml_backend_buffer_is_host(buffer GgmlBackendBuffer) (bool, error)
Ggml_backend_buffer_is_host checks if a buffer is host memory
func Ggml_backend_buffer_name ¶
func Ggml_backend_buffer_name(buffer GgmlBackendBuffer) (string, error)
Ggml_backend_buffer_name returns the name of a backend buffer
func Ggml_backend_dev_count ¶
Ggml_backend_dev_count returns the number of available backend devices
func Ggml_backend_dev_description ¶
func Ggml_backend_dev_description(device GgmlBackendDevice) (string, error)
Ggml_backend_dev_description returns the description of a backend device
func Ggml_backend_dev_memory ¶
func Ggml_backend_dev_memory(device GgmlBackendDevice) (free uint64, total uint64, err error)
Ggml_backend_dev_memory returns the memory statistics of a backend device
func Ggml_backend_dev_name ¶
func Ggml_backend_dev_name(device GgmlBackendDevice) (string, error)
Ggml_backend_dev_name returns the name of a backend device
func Ggml_backend_free ¶
func Ggml_backend_free(backend GgmlBackend) error
Ggml_backend_free frees a backend
func Ggml_backend_is_cpu ¶
func Ggml_backend_is_cpu(backend GgmlBackend) (bool, error)
Ggml_backend_is_cpu checks if a backend is CPU-based Note: This function is not available in current GGML builds
func Ggml_backend_load_all ¶
func Ggml_backend_load_all() error
Ggml_backend_load_all loads all available backends
func Ggml_backend_load_all_from_path ¶
Ggml_backend_load_all_from_path loads all available backends from a specific path
func Ggml_backend_name ¶
func Ggml_backend_name(backend GgmlBackend) (string, error)
Ggml_backend_name returns the name of a backend
func Ggml_backend_unload ¶
func Ggml_backend_unload(reg GgmlBackendReg) error
Ggml_backend_unload unloads a dynamically loaded backend and unregisters it
func Ggml_blck_size ¶
Ggml_blck_size returns the block size of a GGML type
func Ggml_type_is_quantized ¶
Ggml_type_is_quantized returns whether a GGML type is quantized
func Ggml_type_name ¶
Ggml_type_name returns the string name of a GGML type
func Ggml_type_size ¶
Ggml_type_size returns the size in bytes of a GGML type element
func Ggml_type_sizef ¶
Ggml_type_sizef returns the size in bytes of a GGML type (float version)
func HandleError ¶
HandleError is a convenience function that uses the global error handler
func IsFatalError ¶
IsFatalError checks if an error is fatal and should stop execution
func IsRetryableError ¶
IsRetryableError checks if an error is retryable
func LoadLibraryWithVersion ¶
LoadLibraryWithVersion loads a specific version of the llama.cpp library
func Memory_clear ¶
func Memory_clear(ctx LlamaContext, reset bool) bool
Memory_clear clears the KV cache
func MergeVariantLibraries ¶
MergeVariantLibraries merges library files from multiple variant directories into the single target libs directory for the given platform and version. If two variants contain a library with the same file name but different content, it returns an error to prevent ambiguous or conflicting embeddings.
Target layout: <libsDir>/<goos>_<goarch>_<version>/ Copied files: *.dylib, *.so, *.dll (base name only; subdir structure is not preserved)
func Model_n_embd ¶
func Model_n_embd(model LlamaModel) int32
Model_n_embd returns the number of embedding dimensions for the model
func PopulateLibDirectoryFromResults ¶
func PopulateLibDirectoryFromResults(results []DownloadResult, version, libsDir string) error
PopulateLibDirectoryFromResults copies downloaded library artifacts into the local libs directory so they can be embedded in future builds. Only the llama.cpp build defined by LlamaCppBuild is supported.
func Print_system_info ¶
func Print_system_info() string
Print_system_info prints system information
func RegisterFunction ¶
RegisterFunction registers a function with the global library handle
func RegisterFunctionSet ¶
func RegisterFunctionSet(libHandle uintptr, functions []FunctionRegistration, tryMode bool) error
RegisterFunctions registers multiple function pointers with error handling If any required function fails to register and we're not in try mode, it returns an error This consolidates repeated registerLibFunc calls and reduces code duplication
func SetGlobalConfig ¶
SetGlobalConfig sets the global configuration
func SetGlobalErrorHandler ¶
func SetGlobalErrorHandler(handler *ErrorHandler)
SetGlobalErrorHandler sets the global error handler
func Set_causal_attn ¶
func Set_causal_attn(ctx LlamaContext, causal bool)
Set_causal_attn sets whether to use causal attention
func Set_embeddings ¶
func Set_embeddings(ctx LlamaContext, embeddings bool)
Set_embeddings sets whether to extract embeddings
func Supports_gpu_offload ¶
func Supports_gpu_offload() bool
Supports_gpu_offload returns whether GPU offload is supported
func Token_to_piece ¶
func Token_to_piece(model LlamaModel, token LlamaToken, special bool) string
Token_to_piece converts a token to its string representation using model
func WrapErrorf ¶
WrapErrorf wraps an error with formatted additional context
Types ¶
type Config ¶
type Config struct {
// Library settings
LibraryPath string `json:"library_path,omitempty"`
CacheDir string `json:"cache_dir,omitempty"`
UseEmbedded bool `json:"use_embedded"`
EnableLogging bool `json:"enable_logging"`
LogLevel int `json:"log_level"`
// Performance settings
NumThreads int `json:"num_threads"`
EnableGPU bool `json:"enable_gpu"`
GPULayers int `json:"gpu_layers"`
MetalEnabled bool `json:"metal_enabled"`
CUDAEnabled bool `json:"cuda_enabled"`
VulkanEnabled bool `json:"vulkan_enabled"`
// Memory settings
ContextSize int `json:"context_size"`
BatchSize int `json:"batch_size"`
UbatchSize int `json:"ubatch_size"`
MemoryMapEnabled bool `json:"memory_map_enabled"`
MemoryLockEnabled bool `json:"memory_lock_enabled"`
// Model settings
ModelPath string `json:"model_path,omitempty"`
VocabOnly bool `json:"vocab_only"`
UseQuantization bool `json:"use_quantization"`
QuantizationType string `json:"quantization_type,omitempty"`
// Backend settings
BackendType string `json:"backend_type,omitempty"`
DeviceID int `json:"device_id"`
// Debug settings
VerboseLogging bool `json:"verbose_logging"`
DebugMode bool `json:"debug_mode"`
}
Config holds configuration options for gollama
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a configuration with sensible defaults
func GetGlobalConfig ¶
func GetGlobalConfig() *Config
GetGlobalConfig returns the global configuration
func LoadConfig ¶
LoadConfig loads configuration from a JSON file
func LoadConfigFromEnv ¶
func LoadConfigFromEnv() *Config
LoadConfigFromEnv loads configuration from environment variables
func LoadDefaultConfig ¶
func LoadDefaultConfig() *Config
LoadDefaultConfig loads configuration from the default locations
func (*Config) SaveConfig ¶
SaveConfig saves configuration to a JSON file
type DownloadResult ¶
type DownloadResult struct {
Platform string
Success bool
Error error
LibraryPath string
SHA256Sum string
ExtractedDir string
Embedded bool
}
DownloadResult represents the result of a download task
func DownloadLibrariesForPlatforms ¶
func DownloadLibrariesForPlatforms(platforms []string, version string) ([]DownloadResult, error)
DownloadLibrariesForPlatforms downloads libraries for multiple platforms in parallel platforms should be in the format []string{"linux/amd64", "darwin/arm64", "windows/amd64"} version can be empty for latest version or specify a specific version like "b6862"
type DownloadTask ¶
type DownloadTask struct {
Platform string
AssetName string
DownloadURL string
TargetDir string
ExpectedSHA2 string
ResultIndex int
}
DownloadTask represents a single download task for parallel processing
type ErrorCategory ¶
type ErrorCategory int
ErrorCategory represents different categories of errors
const ( CategoryLibrary ErrorCategory = iota CategoryModel CategoryContext CategoryToken CategoryGeneration CategoryMemory CategoryConfig CategoryBackend CategoryFile CategoryParameter CategoryThread )
func CategorizeError ¶
func CategorizeError(err error) ErrorCategory
CategorizeError determines the category of an error
func (ErrorCategory) String ¶
func (ec ErrorCategory) String() string
String returns the string representation of an error category
type ErrorHandler ¶
type ErrorHandler struct {
// contains filtered or unexported fields
}
ErrorHandler provides centralized error handling and logging
func GetGlobalErrorHandler ¶
func GetGlobalErrorHandler() *ErrorHandler
GetGlobalErrorHandler returns the global error handler
func NewErrorHandler ¶
func NewErrorHandler(enableLogging bool) *ErrorHandler
NewErrorHandler creates a new error handler
func (*ErrorHandler) HandleError ¶
func (eh *ErrorHandler) HandleError(err error, context string) error
HandleError processes and logs an error
func (*ErrorHandler) SetLogCallback ¶
func (eh *ErrorHandler) SetLogCallback(callback func(level int, message string))
SetLogCallback sets the log callback function
type FunctionRegistration ¶
type FunctionRegistration struct {
FunctionPtr interface{} // Pointer to the function pointer variable
Name string // C function name
Required bool // Whether registration must succeed
OnlyDarwin bool // Register only on Darwin platform
}
FunctionRegistration holds metadata for a single function to register
type GgmlBackend ¶
type GgmlBackend uintptr
GGML backend types
func Ggml_backend_init_best ¶
func Ggml_backend_init_best() (GgmlBackend, error)
Ggml_backend_init_best initializes the best available backend (GPU or CPU)
func Ggml_backend_init_by_name ¶
func Ggml_backend_init_by_name(name string, params string) (GgmlBackend, error)
Ggml_backend_init_by_name initializes a backend by name with optional parameters
func Ggml_backend_init_by_type ¶
func Ggml_backend_init_by_type(deviceType GgmlBackendDevType, params string) (GgmlBackend, error)
Ggml_backend_init_by_type initializes a backend by device type with optional parameters
type GgmlBackendBuffer ¶
type GgmlBackendBuffer uintptr
type GgmlBackendBufferType ¶
type GgmlBackendBufferType uintptr
func Ggml_backend_cpu_buffer_type ¶
func Ggml_backend_cpu_buffer_type() (GgmlBackendBufferType, error)
Ggml_backend_cpu_buffer_type returns the CPU buffer type
type GgmlBackendDevCaps ¶
type GgmlBackendDevCaps struct {
Async bool // asynchronous operations
HostBuffer bool // pinned host buffer
BufferFromHostPtr bool // creating buffers from host ptr
Events bool // event synchronization
}
GGML backend device capabilities
type GgmlBackendDevProps ¶
type GgmlBackendDevProps struct {
Name string // device name
Description string // device description
MemoryFree uint64 // device free memory in bytes
MemoryTotal uint64 // device total memory in bytes
Type GgmlBackendDevType // device type
DeviceID string // device id (e.g., PCI bus id)
Caps GgmlBackendDevCaps // device capabilities
}
GGML backend device properties
type GgmlBackendDevType ¶
type GgmlBackendDevType int32
GGML backend device types
const ( GGML_BACKEND_DEVICE_TYPE_CPU GgmlBackendDevType = 0 GGML_BACKEND_DEVICE_TYPE_GPU GgmlBackendDevType = 1 GGML_BACKEND_DEVICE_TYPE_IGPU GgmlBackendDevType = 2 GGML_BACKEND_DEVICE_TYPE_ACCEL GgmlBackendDevType = 3 )
type GgmlBackendDevice ¶
type GgmlBackendDevice uintptr
func Ggml_backend_dev_get ¶
func Ggml_backend_dev_get(index uint64) (GgmlBackendDevice, error)
Ggml_backend_dev_get returns a backend device by index
type GgmlBackendReg ¶
type GgmlBackendReg uintptr
func Ggml_backend_load ¶
func Ggml_backend_load(path string) (GgmlBackendReg, error)
Ggml_backend_load dynamically loads a backend from a library path and returns a backend registry
type GgmlObject ¶
type GgmlObject int32
GGML object type
const ( GGML_OBJECT_TENSOR GgmlObject = 0 GGML_OBJECT_GRAPH GgmlObject = 1 GGML_OBJECT_WORK GgmlObject = 2 )
type GgmlType ¶
type GgmlType int32
GGML tensor types
const ( GGML_TYPE_F32 GgmlType = 0 GGML_TYPE_F16 GgmlType = 1 GGML_TYPE_Q4_0 GgmlType = 2 GGML_TYPE_Q4_1 GgmlType = 3 GGML_TYPE_Q5_0 GgmlType = 6 GGML_TYPE_Q5_1 GgmlType = 7 GGML_TYPE_Q8_0 GgmlType = 8 GGML_TYPE_Q8_1 GgmlType = 9 GGML_TYPE_Q2_K GgmlType = 10 GGML_TYPE_Q3_K GgmlType = 11 GGML_TYPE_Q4_K GgmlType = 12 GGML_TYPE_Q5_K GgmlType = 13 GGML_TYPE_Q6_K GgmlType = 14 GGML_TYPE_Q8_K GgmlType = 15 GGML_TYPE_IQ2_XXS GgmlType = 16 GGML_TYPE_IQ2_XS GgmlType = 17 GGML_TYPE_IQ3_XXS GgmlType = 18 GGML_TYPE_IQ1_S GgmlType = 19 GGML_TYPE_IQ4_NL GgmlType = 20 GGML_TYPE_IQ3_S GgmlType = 21 GGML_TYPE_IQ2_S GgmlType = 22 GGML_TYPE_IQ4_XS GgmlType = 23 GGML_TYPE_I8 GgmlType = 24 GGML_TYPE_I16 GgmlType = 25 GGML_TYPE_I32 GgmlType = 26 GGML_TYPE_I64 GgmlType = 27 GGML_TYPE_F64 GgmlType = 28 GGML_TYPE_IQ1_M GgmlType = 29 GGML_TYPE_BF16 GgmlType = 30 GGML_TYPE_COUNT GgmlType = 31 )
type LibraryDownloader ¶
type LibraryDownloader struct {
// contains filtered or unexported fields
}
LibraryDownloader handles downloading pre-built llama.cpp binaries
func NewLibraryDownloader ¶
func NewLibraryDownloader() (*LibraryDownloader, error)
NewLibraryDownloader creates a new library downloader instance
func NewLibraryDownloaderWithCacheDir ¶
func NewLibraryDownloaderWithCacheDir(customCacheDir string) (*LibraryDownloader, error)
NewLibraryDownloaderWithCacheDir creates a new library downloader instance with a custom cache directory
func (*LibraryDownloader) CleanCache ¶
func (d *LibraryDownloader) CleanCache() error
CleanCache removes old cached library files
func (*LibraryDownloader) DownloadAllVariants ¶
func (d *LibraryDownloader) DownloadAllVariants(release *ReleaseInfo, goos, goarch string) (*VariantDownloadResult, error)
DownloadAllVariants downloads all variants for a platform and verifies common files are identical
func (*LibraryDownloader) DownloadAndExtract ¶
func (d *LibraryDownloader) DownloadAndExtract(downloadURL, filename string) (string, error)
DownloadAndExtract downloads and extracts the library archive
func (*LibraryDownloader) DownloadAndExtractWithChecksum ¶
func (d *LibraryDownloader) DownloadAndExtractWithChecksum(downloadURL, filename, expectedChecksum string) (string, string, error)
DownloadAndExtractWithChecksum downloads and extracts the library archive with checksum verification
func (*LibraryDownloader) DownloadMultiplePlatforms ¶
func (d *LibraryDownloader) DownloadMultiplePlatforms(platforms []string, version string) ([]DownloadResult, error)
DownloadMultiplePlatforms downloads libraries for multiple platforms in parallel
func (*LibraryDownloader) FindAllVariantAssets ¶
func (d *LibraryDownloader) FindAllVariantAssets(release *ReleaseInfo, goos, goarch string) ([]VariantAsset, error)
FindAllVariantAssets finds all variant assets for a specific platform and architecture Pattern: llama-<version>-bin-<os>-<variant>[-<variant-version>]-<arch>.zip
func (*LibraryDownloader) FindAssetByPattern ¶
func (d *LibraryDownloader) FindAssetByPattern(release *ReleaseInfo, pattern string) (string, string, error)
FindAssetByPattern finds an asset that matches the given pattern
func (*LibraryDownloader) FindLibraryPath ¶
func (d *LibraryDownloader) FindLibraryPath(extractedDir string) (string, error)
FindLibraryPath finds the main library file in the extracted directory
func (*LibraryDownloader) FindLibraryPathForPlatform ¶
func (d *LibraryDownloader) FindLibraryPathForPlatform(extractedDir, goos string) (string, error)
FindLibraryPathForPlatform finds the main library file for a specific platform
func (*LibraryDownloader) GetCacheDir ¶
func (d *LibraryDownloader) GetCacheDir() string
GetCacheDir returns the cache directory being used
func (*LibraryDownloader) GetLatestRelease ¶
func (d *LibraryDownloader) GetLatestRelease() (*ReleaseInfo, error)
GetLatestRelease fetches the latest release information from GitHub
func (*LibraryDownloader) GetPlatformAssetPattern ¶
func (d *LibraryDownloader) GetPlatformAssetPattern() (string, error)
GetPlatformAssetPattern returns the asset name pattern for the current platform
func (*LibraryDownloader) GetPlatformAssetPatternForPlatform ¶
func (d *LibraryDownloader) GetPlatformAssetPatternForPlatform(goos, goarch string) (string, error)
GetPlatformAssetPatternForPlatform returns the asset name pattern for a specific platform
func (*LibraryDownloader) GetReleaseByTag ¶
func (d *LibraryDownloader) GetReleaseByTag(tag string) (*ReleaseInfo, error)
GetReleaseByTag fetches release information for a specific tag
type LibraryLoadInfo ¶
LibraryLoadInfo consolidates the result of a library load attempt
type LibraryLoader ¶
type LibraryLoader struct {
// contains filtered or unexported fields
}
Library loader manages the loading and lifecycle of llama.cpp shared libraries
func (*LibraryLoader) ApplyLibraryLoad ¶
func (l *LibraryLoader) ApplyLibraryLoad(info *LibraryLoadInfo, rootPath string) error
ApplyLibraryLoad applies the result of a successful library load to the loader state
func (*LibraryLoader) GetHandle ¶
func (l *LibraryLoader) GetHandle() uintptr
GetHandle returns the library handle
func (*LibraryLoader) IsLoaded ¶
func (l *LibraryLoader) IsLoaded() bool
IsLoaded returns whether the library is loaded
func (*LibraryLoader) LoadLibrary ¶
func (l *LibraryLoader) LoadLibrary() error
LoadLibrary loads the appropriate llama.cpp library for the current platform
func (*LibraryLoader) LoadLibraryWithDependencies ¶
func (l *LibraryLoader) LoadLibraryWithDependencies(libPath string) (*LibraryLoadInfo, []string)
LoadLibraryWithDependencies encapsulates the common pattern of: 1. Preloading dependent libraries 2. Loading the main library 3. Setting up configuration on success This is used in multiple places in LoadLibraryWithVersion to reduce duplication
func (*LibraryLoader) LoadLibraryWithVersion ¶
func (l *LibraryLoader) LoadLibraryWithVersion(version string) error
LoadLibraryWithVersion loads the llama.cpp library for a specific version If version is empty, it loads the default build version (LlamaCppBuild) Resolution order: 1) Embedded (only if version == LlamaCppBuild) 2) Local ./libs (only if version == LlamaCppBuild) 3) Cache directory entries matching current GOOS (best-effort scan) 4) Download + extract to cache 5) Return a detailed error if all fail
func (*LibraryLoader) UnloadLibrary ¶
func (l *LibraryLoader) UnloadLibrary() error
UnloadLibrary unloads the library and cleans up resources
type LlamaAdapterLora ¶
type LlamaAdapterLora uintptr
type LlamaAttentionType ¶
type LlamaAttentionType int32
const ( LLAMA_ATTENTION_TYPE_CAUSAL LlamaAttentionType = 0 LLAMA_ATTENTION_TYPE_NON_CAUSAL LlamaAttentionType = 1 )
type LlamaBatch ¶
type LlamaBatch struct {
NTokens int32 // number of tokens
Token *LlamaToken // tokens
Embd *float32 // embeddings (if using embeddings instead of tokens)
Pos *LlamaPos // positions
NSeqId *int32 // number of sequence IDs per token
SeqId **LlamaSeqId // sequence IDs
Logits *int8 // whether to compute logits for each token
}
func Batch_get_one ¶
func Batch_get_one(tokens []LlamaToken) LlamaBatch
Batch_get_one creates a batch from a single set of tokens
func Batch_init ¶
func Batch_init(nTokens, embd, nSeqMax int32) LlamaBatch
Batch_init creates a new batch
type LlamaChatMessage ¶
Chat message
type LlamaContext ¶
type LlamaContext uintptr
func Init_from_model ¶
func Init_from_model(model LlamaModel, params LlamaContextParams) (LlamaContext, error)
Init_from_model creates a context from a model
type LlamaContextParams ¶
type LlamaContextParams struct {
NCtx uint32 // text context, 0 = from model
NBatch uint32 // logical maximum batch size
NUbatch uint32 // physical maximum batch size
NSeqMax uint32 // max number of sequences
NThreads int32 // number of threads to use for generation
NThreadsBatch int32 // number of threads to use for batch processing
RopeScalingType LlamaRopeScalingType // RoPE scaling type
PoolingType LlamaPoolingType // pooling type for embeddings
AttentionType LlamaAttentionType // attention type
FlashAttnType LlamaFlashAttnType // when to enable Flash Attention
RopeFreqBase float32 // RoPE base frequency
RopeFreqScale float32 // RoPE frequency scaling factor
YarnExtFactor float32 // YaRN extrapolation mix factor
YarnAttnFactor float32 // YaRN magnitude scaling factor
YarnBetaFast float32 // YaRN low correction dim
YarnBetaSlow float32 // YaRN high correction dim
YarnOrigCtx uint32 // YaRN original context size
DefragThold float32 // [DEPRECATED] defragment the KV cache if holes/size > thold
CbEval uintptr // evaluation callback
CbEvalUserData uintptr // user data for evaluation callback
TypeK int32 // data type for K cache
TypeV int32 // data type for V cache
AbortCallback uintptr // abort callback
AbortCallbackData uintptr // user data for abort callback
Embeddings uint8 // whether to extract embeddings, together with logits (bool as uint8)
Offload_kqv uint8 // whether to offload KQV ops (incl. KV cache) to GPU (bool as uint8)
NoPerf uint8 // whether to skip performance timings (bool as uint8)
OpOffload uint8 // offload host tensor operations to device (bool as uint8)
SwaFull uint8 // use full-size SWA cache (bool as uint8)
KvUnified uint8 // use a unified KV buffer across input sequences (bool as uint8)
}
Context parameters
Layout MUST match struct llama_context_params in llama.h for the bundled llama.cpp build (b6862). The struct is passed/returned BY VALUE across the FFI boundary, so any drift silently lands fields on the wrong C offsets.
func ContextDefaultParams ¶
func ContextDefaultParams() LlamaContextParams
func Context_default_params ¶
func Context_default_params() LlamaContextParams
Context_default_params returns default context parameters
type LlamaError ¶
type LlamaError struct {
Code int `json:"code"`
Message string `json:"message"`
Function string `json:"function,omitempty"`
File string `json:"file,omitempty"`
Line int `json:"line,omitempty"`
Cause error `json:"cause,omitempty"`
}
LlamaError represents a structured error from the llama.cpp library
func NewLlamaError ¶
func NewLlamaError(code int, message string) *LlamaError
NewLlamaError creates a new LlamaError
func NewLlamaErrorWithCause ¶
func NewLlamaErrorWithCause(code int, message string, cause error) *LlamaError
NewLlamaErrorWithCause creates a new LlamaError with an underlying cause
func NewLlamaErrorWithContext ¶
func NewLlamaErrorWithContext(code int, message, function string) *LlamaError
NewLlamaErrorWithContext creates a new LlamaError with function context
type LlamaFlashAttnType ¶
type LlamaFlashAttnType int32
const ( LLAMA_FLASH_ATTN_TYPE_AUTO LlamaFlashAttnType = -1 LLAMA_FLASH_ATTN_TYPE_DISABLED LlamaFlashAttnType = 0 LLAMA_FLASH_ATTN_TYPE_ENABLED LlamaFlashAttnType = 1 )
type LlamaFtype ¶
type LlamaFtype int32
const ( LLAMA_FTYPE_ALL_F32 LlamaFtype = 0 LLAMA_FTYPE_MOSTLY_F16 LlamaFtype = 1 LLAMA_FTYPE_MOSTLY_Q4_0 LlamaFtype = 2 LLAMA_FTYPE_MOSTLY_Q4_1 LlamaFtype = 3 LLAMA_FTYPE_MOSTLY_Q8_0 LlamaFtype = 7 LLAMA_FTYPE_MOSTLY_Q5_0 LlamaFtype = 8 LLAMA_FTYPE_MOSTLY_Q5_1 LlamaFtype = 9 LLAMA_FTYPE_MOSTLY_Q2_K LlamaFtype = 10 LLAMA_FTYPE_MOSTLY_Q3_K_S LlamaFtype = 11 LLAMA_FTYPE_MOSTLY_Q3_K_M LlamaFtype = 12 LLAMA_FTYPE_MOSTLY_Q3_K_L LlamaFtype = 13 LLAMA_FTYPE_MOSTLY_Q4_K_S LlamaFtype = 14 LLAMA_FTYPE_MOSTLY_Q4_K_M LlamaFtype = 15 LLAMA_FTYPE_MOSTLY_Q5_K_S LlamaFtype = 16 LLAMA_FTYPE_MOSTLY_Q5_K_M LlamaFtype = 17 LLAMA_FTYPE_MOSTLY_Q6_K LlamaFtype = 18 LLAMA_FTYPE_MOSTLY_IQ2_XXS LlamaFtype = 19 LLAMA_FTYPE_MOSTLY_IQ2_XS LlamaFtype = 20 LLAMA_FTYPE_MOSTLY_Q2_K_S LlamaFtype = 21 LLAMA_FTYPE_MOSTLY_IQ3_XS LlamaFtype = 22 )
type LlamaGpuBackend ¶
type LlamaGpuBackend int32
const ( LLAMA_GPU_BACKEND_NONE LlamaGpuBackend = 0 LLAMA_GPU_BACKEND_CPU LlamaGpuBackend = 1 LLAMA_GPU_BACKEND_CUDA LlamaGpuBackend = 2 LLAMA_GPU_BACKEND_METAL LlamaGpuBackend = 3 LLAMA_GPU_BACKEND_HIP LlamaGpuBackend = 4 LLAMA_GPU_BACKEND_VULKAN LlamaGpuBackend = 5 LLAMA_GPU_BACKEND_OPENCL LlamaGpuBackend = 6 LLAMA_GPU_BACKEND_SYCL LlamaGpuBackend = 7 )
func DetectGpuBackend ¶
func DetectGpuBackend() LlamaGpuBackend
DetectGpuBackend detects the available GPU backend on the current system
func (LlamaGpuBackend) String ¶
func (b LlamaGpuBackend) String() string
String returns the string representation of the GPU backend
type LlamaMemory ¶
type LlamaMemory uintptr
Common types matching llama.cpp
func Get_memory ¶
func Get_memory(ctx LlamaContext) LlamaMemory
Get_memory returns the memory handle for the context
type LlamaModel ¶
type LlamaModel uintptr
Opaque types (represented as pointers)
func Model_load_from_file ¶
func Model_load_from_file(pathModel string, params LlamaModelParams) (LlamaModel, error)
Model_load_from_file loads a model from a file
type LlamaModelParams ¶
type LlamaModelParams struct {
Devices uintptr // ggml_backend_dev_t * - NULL-terminated list of devices
TensorBuftOverrides uintptr // const struct llama_model_tensor_buft_override *
NGpuLayers int32 // number of layers to store in VRAM
SplitMode LlamaSplitMode // how to split the model across multiple GPUs
MainGpu int32 // the GPU that is used for the entire model
TensorSplit *float32 // proportion of the model to offload to each GPU
ProgressCallback uintptr // llama_progress_callback function pointer
ProgressCallbackUserData uintptr // context pointer passed to the progress callback
KvOverrides uintptr // const struct llama_model_kv_override *
VocabOnly uint8 // only load the vocabulary, no weights (bool as uint8)
UseMmap uint8 // use mmap if possible (bool as uint8)
UseMlock uint8 // force system to keep model in RAM (bool as uint8)
CheckTensors uint8 // validate model tensor data (bool as uint8)
UseExtraBufts uint8 // use extra buffer types (bool as uint8)
NoHost uint8 // bypass host buffer allowing extra buffers to be used (bool as uint8)
}
Model parameters
func ModelDefaultParams ¶
func ModelDefaultParams() LlamaModelParams
Helper functions for platforms where struct returns aren't supported - moved to ROADMAP "wait for purego struct support" section
func Model_default_params ¶
func Model_default_params() LlamaModelParams
Model_default_params returns default model parameters
type LlamaModelQuantizeParams ¶
type LlamaModelQuantizeParams struct {
NThread int32 // number of threads to use for quantizing
Ftype LlamaFtype // quantize to this llama_ftype
OutputTensorType int32 // output tensor type
TokenEmbeddingType int32 // itoken embeddings tensor type
AllowRequantize uint8 // allow quantizing non-f32/f16 tensors (bool as uint8)
QuantizeOutputTensor uint8 // quantize output.weight (bool as uint8)
OnlyF32 uint8 // quantize only f32 tensors (bool as uint8)
PureF16 uint8 // disable k-quant mixtures and quantize all tensors to the same type (bool as uint8)
KeepSplit uint8 // keep split tensors (bool as uint8)
IMatrix *byte // importance matrix data
KqsWarning uint8 // warning for quantization quality loss (bool as uint8)
}
Model quantize parameters
type LlamaPoolingType ¶
type LlamaPoolingType int32
const ( LLAMA_POOLING_TYPE_UNSPECIFIED LlamaPoolingType = -1 LLAMA_POOLING_TYPE_NONE LlamaPoolingType = 0 LLAMA_POOLING_TYPE_MEAN LlamaPoolingType = 1 LLAMA_POOLING_TYPE_CLS LlamaPoolingType = 2 LLAMA_POOLING_TYPE_LAST LlamaPoolingType = 3 LLAMA_POOLING_TYPE_RANK LlamaPoolingType = 4 )
type LlamaRopeScalingType ¶
type LlamaRopeScalingType int32
const ( LLAMA_ROPE_SCALING_TYPE_UNSPECIFIED LlamaRopeScalingType = -1 LLAMA_ROPE_SCALING_TYPE_NONE LlamaRopeScalingType = 0 LLAMA_ROPE_SCALING_TYPE_LINEAR LlamaRopeScalingType = 1 LLAMA_ROPE_SCALING_TYPE_YARN LlamaRopeScalingType = 2 )
type LlamaSampler ¶
type LlamaSampler uintptr
func Sampler_chain_init ¶
func Sampler_chain_init(params LlamaSamplerChainParams) LlamaSampler
Sampler_chain_init creates a sampler chain
func Sampler_init_greedy ¶
func Sampler_init_greedy() LlamaSampler
Sampler_init_greedy creates a greedy sampler
type LlamaSamplerChainParams ¶
type LlamaSamplerChainParams struct {
NoPerf uint8 // whether to measure performance timings (bool as uint8)
}
Sampler chain parameters
func SamplerChainDefaultParams ¶
func SamplerChainDefaultParams() LlamaSamplerChainParams
func Sampler_chain_default_params ¶
func Sampler_chain_default_params() LlamaSamplerChainParams
Sampler_chain_default_params returns default sampler chain parameters
type LlamaSplitMode ¶
type LlamaSplitMode int32
const ( LLAMA_SPLIT_MODE_NONE LlamaSplitMode = 0 LLAMA_SPLIT_MODE_LAYER LlamaSplitMode = 1 LLAMA_SPLIT_MODE_ROW LlamaSplitMode = 2 )
type LlamaToken ¶
type LlamaToken int32
Common types matching llama.cpp
func Sampler_sample ¶
func Sampler_sample(sampler LlamaSampler, ctx LlamaContext, idx int32) LlamaToken
Sampler_sample samples a token from the logits at the given index (-1 for last token)
func Tokenize ¶
func Tokenize(model LlamaModel, text string, addSpecial, parseSpecial bool) ([]LlamaToken, error)
Tokenize tokenizes text
type LlamaTokenAttr ¶
type LlamaTokenAttr int32
const ( LLAMA_TOKEN_ATTR_UNDEFINED LlamaTokenAttr = 0 LLAMA_TOKEN_ATTR_UNKNOWN LlamaTokenAttr = 1 << 0 LLAMA_TOKEN_ATTR_UNUSED LlamaTokenAttr = 1 << 1 LLAMA_TOKEN_ATTR_NORMAL LlamaTokenAttr = 1 << 2 LLAMA_TOKEN_ATTR_CONTROL LlamaTokenAttr = 1 << 3 LLAMA_TOKEN_ATTR_USER_DEF LlamaTokenAttr = 1 << 4 LLAMA_TOKEN_ATTR_BYTE LlamaTokenAttr = 1 << 5 LLAMA_TOKEN_ATTR_LSTRIP LlamaTokenAttr = 1 << 6 LLAMA_TOKEN_ATTR_RSTRIP LlamaTokenAttr = 1 << 7 LLAMA_TOKEN_ATTR_SINGLE_WORD LlamaTokenAttr = 1 << 8 )
type LlamaTokenData ¶
type LlamaTokenData struct {
Id LlamaToken // token id
Logit float32 // log-odds of the token
P float32 // probability of the token
}
Structs
type LlamaTokenDataArray ¶
type LlamaTokenDataArray struct {
Data *LlamaTokenData // pointer to token data array
Size uint64 // number of tokens
Selected int64 // index of selected token (-1 if none)
Sorted uint8 // whether the array is sorted by probability (bool as uint8)
}
func Token_data_array_from_logits ¶
func Token_data_array_from_logits(model LlamaModel, logits *float32) *LlamaTokenDataArray
Token_data_array_from_logits creates a token data array from logits
func Token_data_array_init ¶
func Token_data_array_init(model LlamaModel) *LlamaTokenDataArray
Token_data_array_init creates a token data array (helper function)
type LlamaTokenType ¶
type LlamaTokenType int32
const ( LLAMA_TOKEN_TYPE_UNDEFINED LlamaTokenType = iota LLAMA_TOKEN_TYPE_NORMAL LLAMA_TOKEN_TYPE_UNKNOWN LLAMA_TOKEN_TYPE_CONTROL LLAMA_TOKEN_TYPE_USER_DEFINED LLAMA_TOKEN_TYPE_UNUSED LLAMA_TOKEN_TYPE_BYTE )
type LlamaVocab ¶
type LlamaVocab uintptr
type LlamaVocabType ¶
type LlamaVocabType int32
Enums
const ( LLAMA_VOCAB_TYPE_NONE LlamaVocabType = iota LLAMA_VOCAB_TYPE_SPM LLAMA_VOCAB_TYPE_BPE LLAMA_VOCAB_TYPE_WPM LLAMA_VOCAB_TYPE_UGM LLAMA_VOCAB_TYPE_RWKV )
type ReleaseInfo ¶
type ReleaseInfo = github.RepositoryRelease
ReleaseInfo represents GitHub release information Using go-github's Release type directly
type VariantAsset ¶
type VariantAsset struct {
AssetName string
DownloadURL string
Variant string // e.g., "cpu", "cuda-12.6.0", "vulkan", "hip-6.2"
}
VariantAsset represents a single variant asset for a platform
type VariantDownloadResult ¶
type VariantDownloadResult struct {
Platform string
Variants []VariantInfo
Success bool
Error error
CommonLibPath string // Path to verified common library files
}
VariantDownloadResult represents the result of downloading all variants for a platform