Automated fixes: interface{} → any, range-over-int, t.Context(),
wg.Go(), strings.SplitSeq, strings.Builder, slices.Contains,
maps helpers, min/max builtins.
Co-Authored-By: Virgil <virgil@lethean.io>
37 lines
954 B
Go
37 lines
954 B
Go
//go:build darwin && arm64
|
|
|
|
package metal
|
|
|
|
import "fmt"
|
|
|
|
// LoadConfig holds configuration applied during model loading.
|
|
type LoadConfig struct {
|
|
ContextLen int // Context window size (0 = model default, unbounded KV cache)
|
|
AdapterPath string // Path to LoRA adapter directory (empty = no adapter)
|
|
}
|
|
|
|
// LoadAndInit initialises Metal and loads a model from the given path.
|
|
// Returns a *Model ready for generation.
|
|
func LoadAndInit(path string, cfg ...LoadConfig) (*Model, error) {
|
|
Init()
|
|
im, err := loadModel(path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("metal: %w", err)
|
|
}
|
|
m := &Model{
|
|
model: im,
|
|
tokenizer: im.Tokenizer(),
|
|
modelType: im.ModelType(),
|
|
}
|
|
if len(cfg) > 0 {
|
|
if cfg[0].ContextLen > 0 {
|
|
m.contextLen = cfg[0].ContextLen
|
|
}
|
|
if cfg[0].AdapterPath != "" {
|
|
if err := applyLoadedLoRA(im, cfg[0].AdapterPath); err != nil {
|
|
return nil, fmt.Errorf("metal: load adapter: %w", err)
|
|
}
|
|
}
|
|
}
|
|
return m, nil
|
|
}
|