convert

package
v0.17.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 35 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertAdapter added in v0.3.7

func ConvertAdapter(fsys fs.FS, f *os.File, baseKV ofs.Config) error

func ConvertModel added in v0.3.7

func ConvertModel(fsys fs.FS, f *os.File) error

Convert writes an Ollama compatible model to the provided io.WriteSeeker based on configurations and files it finds in the input path. Supported input model formats include safetensors. Supported input tokenizers files include tokenizer.json (preferred) and tokenizer.model.

func LoadModelMetadata added in v0.14.0

func LoadModelMetadata(fsys fs.FS) (ModelKV, *Tokenizer, error)

Types

type AdapterConverter added in v0.3.7

type AdapterConverter interface {
	// KV maps parameters to LLM key-values
	KV(ofs.Config) KV
	// Tensors maps input tensors to LLM tensors. Adapter specific modifications can be done here.
	Tensors([]Tensor) []*ggml.Tensor
	// Replacements returns a list of string pairs to replace in tensor names.
	// See [strings.Replacer](https://pkg.go.dev/strings#Replacer) for details
	Replacements() []string
}

type AdapterParameters added in v0.3.7

type AdapterParameters struct {
	Alpha          uint32 `json:"lora_alpha"`
	LoraLayers     uint32 `json:"lora_layers"`
	LoraParameters struct {
		Rank  uint32  `json:"rank"`
		Alpha float32 `json:"alpha"`
		Scale float32 `json:"scale"`
	} `json:"lora_parameters"`
}

func (AdapterParameters) KV added in v0.3.7

func (p AdapterParameters) KV() KV

type KV added in v0.14.0

type KV map[string]any

func (KV) Architecture added in v0.14.0

func (kv KV) Architecture() string

func (KV) Bool added in v0.14.0

func (kv KV) Bool(key string, defaultValue ...bool) bool

func (KV) Bools added in v0.14.0

func (kv KV) Bools(key string, defaultValue ...[]bool) []bool

func (KV) Float added in v0.14.0

func (kv KV) Float(key string, defaultValue ...float32) float32

func (KV) Floats added in v0.14.0

func (kv KV) Floats(key string, defaultValue ...[]float32) []float32

func (KV) Ints added in v0.14.0

func (kv KV) Ints(key string, defaultValue ...[]int32) []int32

func (KV) Keys added in v0.14.0

func (kv KV) Keys() iter.Seq[string]

func (KV) Len added in v0.14.0

func (kv KV) Len() int

func (KV) String added in v0.14.0

func (kv KV) String(key string, defaultValue ...string) string

func (KV) Strings added in v0.14.0

func (kv KV) Strings(key string, defaultValue ...[]string) []string

func (KV) Uint added in v0.14.0

func (kv KV) Uint(key string, defaultValue ...uint32) uint32

func (KV) Uints added in v0.14.0

func (kv KV) Uints(key string, defaultValue ...[]uint32) []uint32

func (KV) Value added in v0.14.0

func (kv KV) Value(key string) any

type ModelConverter added in v0.3.7

type ModelConverter interface {
	ModelKV

	// Tensors maps input tensors to LLM tensors. Model specific modifications can be done here.
	Tensors([]Tensor) []*ggml.Tensor
	// Replacements returns a list of string pairs to replace in tensor names.
	// See [strings.Replacer](https://pkg.go.dev/strings#Replacer) for details
	Replacements() []string
	// contains filtered or unexported methods
}

type ModelKV added in v0.14.0

type ModelKV interface {
	// KV maps parameters to LLM key-values
	KV(*Tokenizer) KV
}

type ModelParameters added in v0.3.7

type ModelParameters struct {
	Architectures []string `json:"architectures"`
	VocabSize     uint32   `json:"vocab_size"`

	// TODO is this needed?
	ModelType string `json:"model_type"`

	TextModel struct {
		VocabSize  uint32 `json:"vocab_size"`
		HiddenSize uint32 `json:"hidden_size"`
		ModelType  string `json:"model_type"`
	} `json:"text_config"`
}

func (ModelParameters) KV added in v0.3.7

func (ModelParameters) KV(t *Tokenizer) KV

type Repacker added in v0.6.7

type Repacker func(string, []float32, []uint64) ([]float32, error)

type SpecialVocabulary added in v0.3.3

type SpecialVocabulary struct {
	Type     string
	ID       int
	Content  string
	AddToken bool

	// IDs is populated by generation_config.json
	IDs []int32
}

func (SpecialVocabulary) Key added in v0.3.3

func (sv SpecialVocabulary) Key() string

type Tensor added in v0.3.3

type Tensor interface {
	Name() string
	Shape() []uint64
	Kind() uint32
	SetRepacker(Repacker)
	WriteTo(io.Writer) (int64, error)
	Clone() Tensor
}

type Tokenizer added in v0.1.39

type Tokenizer struct {
	*Vocabulary
	SpecialVocabulary []*SpecialVocabulary
	Merges            []string

	Pre      string
	Template string
}

type Vocabulary added in v0.3.3

type Vocabulary struct {
	Model  string
	Tokens []string
	Scores []float32
	Types  []int32
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL