mirror of
https://github.com/ollama/ollama.git
synced 2026-07-07 00:08:13 +00:00
* broad lint fixes to sidestep CI scope glitch * runner: Remove CGO engines, use llama-server exclusively for GGML models Remove the vendored GGML and llama.cpp backend, CGO runner, Go model implementations, and sample. llama-server (built from upstream llama.cpp via FetchContent) is now the sole inference engine for GGUF-based models. (Safetensor based models continue to run on the new MLX engine.) This allows us to more rapidly pick up new capabilities and fixes from llama.cpp as they come out. On windows this now requires recent AMD driver versions to support ROCm v7 as llama.cpp currently does not support building against v6. * llama/compat: load Ollama-format GGUFs in llama-server Squashed from upstream/jmorganca/llama-compat on 2026-04-29. Source tip:0c33775d37. Original source commits: -25223160dllama/compat: add in-memory shim so llama-server can load Ollama-format GGUFs -7449b539allm,server: route Ollama-format gemma3 blobs through llama/compat -436f2e2b1llama/compat: make patch-apply idempotent -8c2c9d4c8llama/compat: extend gemma3 handler to cover 1B and 270M blobs -021389f7bllama/compat: shrink clip.cpp injection from 18 lines to 1 -61b367ec2llama/compat: shrink patch to pure call-site hooks (34 -> 20 lines) -36049361cllama/compat: simplify shim (gemma3-tested) -8fa664865llama/compat: add qwen35moe text handler -db0c74530llama/compat: add qwen35moe vision (clip) support -2a388da77llama/compat: split shared infra into a util TU -9a69a17dcllama/compat: document non-public API dependencies -d0f38a915llama/compat: add gpt-oss and lfm2 handlers -086071822llama/compat: add mistral3 text handler (vision TODO) -63bde9ff7llama/compat: add mistral3 vision (clip) support -3a57b89d5llama/compat: apply LLaMA RoPE permute to mistral3 vision Q/K -99cb87439llama/compat: add qwen35, gemma4, deepseek-ocr handlers -2c7850dballama/compat: add nemotron_h_moe handler (latent FFN + MTP skip) -9e3b54225llama/compat: add llama4 text + clip handlers -034fee349llama/compat: add gemma4 clip handler (gemma4v projector) -9945c5a93server: remove dhiltgen/* compat redirect table -5d4539101llama/compat: rewrite gemma4 tokenizer model to BPE -7e0765327llama/compat: add glm-ocr text handler + text-loader load-op hook -f1bd1a25allama/compat: add glm-ocr clip handler (glm4v projector) -4b5cf3420llama/compat: collapse text-loader hook back to one new patch line -eb4ecf4fcllama/compat: extend gemma4 clip handler to gemma4a (audio) -a23a5e76fllama/compat: fix gemma4a per-block norm tensor mapping -cd2dcaff4llama/compat: add embeddinggemma handler -1ce8a6b26llama/compat: add qwen3-vl + qwen2.5-vl handlers -fd98ffa1ellama/compat: add gemma3n + glm4moelite handlers -cc7bdf0bcllama/compat: handle null buft in maybe_load_tensor -0c33775d3llama/compat: disable mmap when load_op transforms text-side tensors * refine implementation * ci: fix windows MLX build * ci: fix windows llama-server build * ci: fix windows rocm build * ci: windows mlx tuning Shorten long-tail on build, and get OllamaSetup.exe back under 2g limit * ci: fix windows dependencies * win: fix dependency gathering * disable openmp * win: arm64 cross-compile build also DRY out CI steps * scheduler improvements * ci: improvements from #15982 * win: favor ninja for faster developer builds * win: fix build * win: fix arm64 cross-compile * win: avoid spaces in compiler path * misc discovery fixes, and bos handling * lint fixes * win: fix arm cross-compile build/CI bugs * llama.cpp update * win: handle multiple CRT dirs * vulkan: add windows iGPU detection * fix creation bugs for patched models, other refactoring work * tune batch size for better performance * ci and lint fixes * fix repeat_last_n bug * build: revamp build for better developer UX * amd, sampler, qwen3next fixes * version bump * fix mlx build * revamp GPU discovery Scanning the output of llama-server is turning out to be too error prone across llama.cpp updates, so this switches to a thin dynamic library load against the bundled GGML libraries so more details can be gathered from the API. * version bump * missing file * ci: fix cache miss on rocm build * refine vulkan dep handling * fix ps reporting bug on full GPU load * improve cmake wiring for customized local builds * version bump * docker build arg cleanup * improve windows exit error logs * fix community gemma4 support and ci flakes * fix mlx unit test * tighten up ps logic to avoid double counting fit log lines * version bump * fix ps view for full gpu layer offload * add MTP wiring for llama-server and create with GGUFs * pick best template by capabilities * version bump * ci: harden apt repos * remove unused cpu core discovery * adjust batch default logic to reduce OOMs * support larger tool calls * fix audio support, template show * qwen35 mtp patch support * flesh out dtypes * rocm deps * version bump * lint fix * block broken gfx1150 on windows * fix qwen3.5 moe mtp tensors in patch * mmproj oom fallback and vulkan on by default * qwen MTP compat fix * version bump * ci: fix WoA cross-compile * ci: workaround ui tool in cross-compile * version bump * win: enable OpenMP for CPU builds * build: improve developer UX * ci: windows path workaround for CPU build * win: fix WoA dependencies * win: fix large offset reads for mmproj patched loads * version bump * fix vulkan dup detection * add OLLAMA_IGPU_ENABLE and largely disable iGPUs by default * opt-in MTP, win large offset, integraton fixes * fix unit test scheduler interaction hang * fix multi-gpu filtering * version bump * review comments * fix thinking level * fix linux rocm ordering and granite 3.3 template * version bump * ci fix - non-shallow MLX checkout * bypass linux sysfs unit test on windows --------- Co-authored-by: jmorganca <jmorganca@gmail.com>
472 lines
12 KiB
Go
472 lines
12 KiB
Go
package convert
|
|
|
|
import (
|
|
"cmp"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"io/fs"
|
|
"iter"
|
|
"log/slog"
|
|
"maps"
|
|
"os"
|
|
"slices"
|
|
"strings"
|
|
|
|
ofs "github.com/ollama/ollama/fs"
|
|
"github.com/ollama/ollama/fs/ggml"
|
|
)
|
|
|
|
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"`
|
|
}
|
|
|
|
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"`
|
|
}
|
|
|
|
type KV map[string]any
|
|
|
|
func (kv KV) Architecture() string {
|
|
return kv.String("general.architecture", "unknown")
|
|
}
|
|
|
|
type valueTypes interface {
|
|
uint8 | int8 | uint16 | int16 |
|
|
uint32 | int32 | uint64 | int64 |
|
|
string | float32 | float64 | bool
|
|
}
|
|
|
|
type arrayValueTypes interface {
|
|
[]uint8 | []int8 | []uint16 | []int16 |
|
|
[]uint32 | []int32 | []uint64 | []int64 |
|
|
[]string | []float32 | []float64 | []bool
|
|
}
|
|
|
|
func keyValue[T valueTypes | arrayValueTypes](kv KV, key string, defaultValue ...T) (T, bool) {
|
|
if !strings.HasPrefix(key, "tokenizer.") && !strings.HasPrefix(key, "general.") {
|
|
key = kv.Architecture() + "." + key
|
|
}
|
|
|
|
if val, ok := kv[key].(T); ok {
|
|
return val, true
|
|
}
|
|
return defaultValue[0], false
|
|
}
|
|
|
|
func (kv KV) String(key string, defaultValue ...string) string {
|
|
val, _ := keyValue(kv, key, append(defaultValue, "")...)
|
|
return val
|
|
}
|
|
|
|
func (kv KV) Uint(key string, defaultValue ...uint32) uint32 {
|
|
val, _ := keyValue(kv, key, append(defaultValue, 0)...)
|
|
return val
|
|
}
|
|
|
|
func (kv KV) Float(key string, defaultValue ...float32) float32 {
|
|
val, _ := keyValue(kv, key, append(defaultValue, 0)...)
|
|
return val
|
|
}
|
|
|
|
func (kv KV) Bool(key string, defaultValue ...bool) bool {
|
|
val, _ := keyValue(kv, key, append(defaultValue, false)...)
|
|
return val
|
|
}
|
|
|
|
func (kv KV) Strings(key string, defaultValue ...[]string) []string {
|
|
val, _ := keyValue(kv, key, append(defaultValue, []string{""})...)
|
|
return val
|
|
}
|
|
|
|
func (kv KV) Ints(key string, defaultValue ...[]int32) []int32 {
|
|
val, _ := keyValue(kv, key, append(defaultValue, []int32{0})...)
|
|
return val
|
|
}
|
|
|
|
func (kv KV) Uints(key string, defaultValue ...[]uint32) []uint32 {
|
|
val, _ := keyValue(kv, key, append(defaultValue, []uint32{0})...)
|
|
return val
|
|
}
|
|
|
|
func (kv KV) Floats(key string, defaultValue ...[]float32) []float32 {
|
|
val, _ := keyValue(kv, key, append(defaultValue, []float32{0})...)
|
|
return val
|
|
}
|
|
|
|
func (kv KV) Bools(key string, defaultValue ...[]bool) []bool {
|
|
val, _ := keyValue(kv, key, append(defaultValue, []bool{false})...)
|
|
return val
|
|
}
|
|
|
|
func (kv KV) Len() int {
|
|
return len(kv)
|
|
}
|
|
|
|
func (kv KV) Keys() iter.Seq[string] {
|
|
return maps.Keys(kv)
|
|
}
|
|
|
|
func (kv KV) Value(key string) any {
|
|
return kv[key]
|
|
}
|
|
|
|
func (ModelParameters) KV(t *Tokenizer) KV {
|
|
kv := KV{
|
|
"general.file_type": uint32(1),
|
|
"general.quantization_version": uint32(2),
|
|
"tokenizer.ggml.pre": t.Pre,
|
|
"tokenizer.ggml.model": t.Vocabulary.Model,
|
|
"tokenizer.ggml.tokens": t.Vocabulary.Tokens,
|
|
"tokenizer.ggml.scores": t.Vocabulary.Scores,
|
|
"tokenizer.ggml.token_type": t.Vocabulary.Types,
|
|
}
|
|
|
|
if len(t.Merges) > 0 {
|
|
kv["tokenizer.ggml.merges"] = t.Merges
|
|
}
|
|
|
|
if t.Template != "" {
|
|
kv["tokenizer.chat_template"] = t.Template
|
|
}
|
|
|
|
for _, sv := range t.SpecialVocabulary {
|
|
if sv.AddTokenSet {
|
|
kv[fmt.Sprintf("tokenizer.ggml.add_%s_token", sv.Key())] = sv.AddToken
|
|
}
|
|
kv[fmt.Sprintf("tokenizer.ggml.%s_token_id", sv.Key())] = uint32(sv.ID)
|
|
if len(sv.IDs) > 0 {
|
|
kv[fmt.Sprintf("tokenizer.ggml.%s_token_ids", sv.Key())] = sv.IDs
|
|
}
|
|
}
|
|
|
|
return kv
|
|
}
|
|
|
|
func (p AdapterParameters) KV() KV {
|
|
var alpha float32
|
|
if p.LoraParameters.Alpha == 0 {
|
|
alpha = float32(p.Alpha)
|
|
} else {
|
|
alpha = p.LoraParameters.Alpha
|
|
}
|
|
|
|
kv := KV{
|
|
"adapter.lora.alpha": alpha,
|
|
"adapter.type": "lora",
|
|
"general.file_type": uint32(1),
|
|
"general.type": "adapter",
|
|
"general.version": "v0.2",
|
|
}
|
|
|
|
return kv
|
|
}
|
|
|
|
func (ModelParameters) specialTokenTypes() []string {
|
|
return []string{
|
|
"bos", "eos", "unk", "sep", "pad", "cls", "mask",
|
|
}
|
|
}
|
|
|
|
type ModelKV interface {
|
|
// KV maps parameters to LLM key-values
|
|
KV(*Tokenizer) KV
|
|
}
|
|
|
|
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
|
|
|
|
// specialTokenTypes returns any special token types the model uses
|
|
specialTokenTypes() []string
|
|
}
|
|
|
|
// MultimodalConverter splits checkpoints with embedded vision/projector
|
|
// weights into a text model GGUF and a separate projector GGUF.
|
|
type MultimodalConverter interface {
|
|
ModelConverter
|
|
TextKV(*Tokenizer) KV
|
|
TextTensors([]Tensor, *Tokenizer) []*ggml.Tensor
|
|
ProjectorKV(*Tokenizer) KV
|
|
ProjectorTensors([]Tensor) []*ggml.Tensor
|
|
}
|
|
|
|
type moreParser interface {
|
|
parseMore(fs.FS) error
|
|
}
|
|
|
|
type extraTensorParser interface {
|
|
extraTensors(fs.FS) ([]Tensor, error)
|
|
}
|
|
|
|
type tokenizerAdjuster interface {
|
|
adjustTokenizer(*Tokenizer)
|
|
}
|
|
|
|
type tokenizerAwareTensorConverter interface {
|
|
TensorsWithTokenizer([]Tensor, *Tokenizer) []*ggml.Tensor
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
func ConvertAdapter(fsys fs.FS, f *os.File, baseKV ofs.Config) error {
|
|
bts, err := fs.ReadFile(fsys, "adapter_config.json")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var p AdapterParameters
|
|
if err := json.Unmarshal(bts, &p); err != nil {
|
|
return err
|
|
}
|
|
|
|
arch := baseKV.Architecture()
|
|
if arch == "" {
|
|
return errors.New("architecture not set for the base model")
|
|
}
|
|
|
|
var conv AdapterConverter
|
|
switch arch {
|
|
case "llama":
|
|
conv = &llamaAdapter{}
|
|
case "gemma2":
|
|
conv = &gemma2Adapter{}
|
|
default:
|
|
return errors.New("unsupported architecture")
|
|
}
|
|
|
|
ts, err := parseTensors(fsys, strings.NewReplacer(conv.Replacements()...))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := json.Unmarshal(bts, conv); err != nil {
|
|
return err
|
|
}
|
|
|
|
return writeFile(f, conv.KV(baseKV), conv.Tensors(ts))
|
|
}
|
|
|
|
func LoadModelMetadata(fsys fs.FS) (ModelKV, *Tokenizer, error) {
|
|
bts, err := fs.ReadFile(fsys, "config.json")
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
bts = sanitizeNonFiniteJSON(bts)
|
|
|
|
var p ModelParameters
|
|
if err := json.Unmarshal(bts, &p); err != nil {
|
|
return nil, nil, fmt.Errorf("parse config.json: %w", err)
|
|
}
|
|
|
|
if len(p.Architectures) < 1 {
|
|
return nil, nil, errors.New("unknown architecture")
|
|
}
|
|
|
|
var conv ModelConverter
|
|
switch p.Architectures[0] {
|
|
case "LlamaForCausalLM":
|
|
conv = &llamaModel{}
|
|
case "MllamaForConditionalGeneration":
|
|
conv = &mllamaModel{}
|
|
case "Llama4ForConditionalGeneration":
|
|
conv = &llama4Model{}
|
|
case "Mistral3ForConditionalGeneration":
|
|
conv = &mistral3Model{}
|
|
case "Ministral3ForCausalLM":
|
|
conv = &mistral3CausalModel{}
|
|
case "MixtralForCausalLM":
|
|
conv = &mixtralModel{}
|
|
case "GemmaForCausalLM":
|
|
conv = &gemmaModel{}
|
|
case "Gemma2ForCausalLM":
|
|
conv = &gemma2Model{}
|
|
case "Gemma3ForCausalLM", "Gemma3ForConditionalGeneration":
|
|
conv = &gemma3Model{Architecture: p.Architectures[0]}
|
|
case "Gemma3TextModel":
|
|
conv = &embeddingGemmaModel{}
|
|
case "Gemma3nForConditionalGeneration":
|
|
conv = &gemma3nModel{}
|
|
case "Gemma4ForCausalLM", "Gemma4ForConditionalGeneration":
|
|
conv = &gemma4Model{Architecture: p.Architectures[0]}
|
|
case "Phi3ForCausalLM":
|
|
conv = &phi3Model{}
|
|
case "Qwen2ForCausalLM":
|
|
conv = &qwen2Model{}
|
|
case "Qwen2_5_VLForConditionalGeneration":
|
|
conv = &qwen25VLModel{}
|
|
case "Qwen3VLForConditionalGeneration", "Qwen3VLMoeForConditionalGeneration":
|
|
conv = &qwen3VLModel{}
|
|
case "Olmo3ForCausalLM":
|
|
conv = &olmoModel{}
|
|
case "BertModel":
|
|
conv = &bertModel{}
|
|
case "NomicBertModel", "NomicBertMoEModel":
|
|
conv = &nomicbertModel{}
|
|
case "CohereForCausalLM":
|
|
conv = &commandrModel{}
|
|
case "GptOssForCausalLM":
|
|
conv = &gptossModel{}
|
|
case "DeepseekOCRForCausalLM":
|
|
conv = &deepseekocr{}
|
|
case "DeepseekV3ForCausalLM":
|
|
conv = &deepseek2Model{}
|
|
case "Glm4MoeLiteForCausalLM":
|
|
conv = &glm4MoeLiteModel{}
|
|
case "LagunaForCausalLM":
|
|
conv = &lagunaModel{}
|
|
case "GlmOcrForConditionalGeneration":
|
|
conv = &glmOcrModel{}
|
|
case "Lfm2ForCausalLM", "Lfm2MoeForCausalLM":
|
|
conv = &lfm2Model{}
|
|
case "Lfm2VlForConditionalGeneration":
|
|
conv = &lfm2VLTextModel{}
|
|
case "Qwen3NextForCausalLM", "Qwen3_5ForConditionalGeneration", "Qwen3_5MoeForConditionalGeneration":
|
|
conv = &qwen3NextModel{}
|
|
case "NemotronH_Nano_VL_V2", "NemotronH_Nano_Omni_Reasoning_V3":
|
|
conv = &nemotronHNanoVLModel{}
|
|
case "NemotronHForCausalLM":
|
|
conv = &nemotronHModel{}
|
|
default:
|
|
return nil, nil, fmt.Errorf("unsupported architecture %q", p.Architectures[0])
|
|
}
|
|
|
|
if err := json.Unmarshal(bts, conv); err != nil {
|
|
return nil, nil, fmt.Errorf("parse config.json for %q: %w", p.Architectures[0], err)
|
|
}
|
|
|
|
if t, ok := conv.(moreParser); ok {
|
|
if err := t.parseMore(fsys); err != nil {
|
|
return nil, nil, err
|
|
}
|
|
}
|
|
|
|
t, err := parseTokenizer(fsys, conv.specialTokenTypes())
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
if ta, ok := conv.(tokenizerAdjuster); ok {
|
|
ta.adjustTokenizer(t)
|
|
}
|
|
|
|
vocabSize := int(cmp.Or(p.VocabSize, p.TextModel.VocabSize))
|
|
|
|
switch {
|
|
case vocabSize == 0:
|
|
slog.Debug("vocabulary size was not explicitly set by the model", "default size", len(t.Vocabulary.Tokens))
|
|
case vocabSize > len(t.Vocabulary.Tokens):
|
|
slog.Debug("vocabulary is smaller than expected, padding with dummy tokens", "expect", vocabSize, "actual", len(t.Vocabulary.Tokens))
|
|
for i := range vocabSize - len(t.Vocabulary.Tokens) {
|
|
t.Vocabulary.Tokens = append(t.Vocabulary.Tokens, fmt.Sprintf("[PAD%d]", i))
|
|
t.Vocabulary.Scores = append(t.Vocabulary.Scores, -1)
|
|
t.Vocabulary.Types = append(t.Vocabulary.Types, tokenTypeUserDefined)
|
|
}
|
|
case vocabSize < len(t.Vocabulary.Tokens):
|
|
slog.Debug("vocabulary is larger than expected", "want", vocabSize, "got", len(t.Vocabulary.Tokens))
|
|
p.VocabSize = uint32(len(t.Vocabulary.Tokens))
|
|
p.TextModel.VocabSize = uint32(len(t.Vocabulary.Tokens))
|
|
default:
|
|
slog.Debug("vocabulary", "size", len(t.Vocabulary.Tokens))
|
|
}
|
|
return conv, t, nil
|
|
}
|
|
|
|
// 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 ConvertModel(fsys fs.FS, f *os.File, projectorFiles ...*os.File) error {
|
|
kv, t, err := LoadModelMetadata(fsys)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
conv := kv.(ModelConverter)
|
|
|
|
ts, err := parseTensors(fsys, strings.NewReplacer(conv.Replacements()...))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if tp, ok := conv.(extraTensorParser); ok {
|
|
extra, err := tp.extraTensors(fsys)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
ts = append(ts, extra...)
|
|
}
|
|
|
|
if err := ensureUniqueTensorNames(ts); err != nil {
|
|
return err
|
|
}
|
|
|
|
if mc, ok := conv.(MultimodalConverter); ok && len(projectorFiles) > 0 && projectorFiles[0] != nil {
|
|
projectorTensors := mc.ProjectorTensors(ts)
|
|
if len(projectorTensors) > 0 {
|
|
if err := writeFile(f, mc.TextKV(t), mc.TextTensors(ts, t)); err != nil {
|
|
return err
|
|
}
|
|
return writeFile(projectorFiles[0], mc.ProjectorKV(t), projectorTensors)
|
|
}
|
|
}
|
|
|
|
var tensors []*ggml.Tensor
|
|
if tc, ok := conv.(tokenizerAwareTensorConverter); ok {
|
|
tensors = tc.TensorsWithTokenizer(ts, t)
|
|
} else {
|
|
tensors = conv.Tensors(ts)
|
|
}
|
|
|
|
return writeFile(f, conv.KV(t), tensors)
|
|
}
|
|
|
|
func ensureUniqueTensorNames(ts []Tensor) error {
|
|
names := make(map[string]struct{}, len(ts))
|
|
for _, t := range ts {
|
|
if _, ok := names[t.Name()]; ok {
|
|
return fmt.Errorf("duplicate tensor name '%s' was found for this model", t.Name())
|
|
}
|
|
names[t.Name()] = struct{}{}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func writeFile(f *os.File, kv KV, ts []*ggml.Tensor) error {
|
|
for k, v := range sourceTensorKV(ts) {
|
|
kv[k] = v
|
|
}
|
|
|
|
for i := range ts {
|
|
ts[i].Shape = slices.Clone(ts[i].Shape)
|
|
slices.Reverse(ts[i].Shape)
|
|
}
|
|
return ggml.WriteGGUF(f, kv, ts)
|
|
}
|