Implementation:Ollama Ollama WriteGGUF
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Format_Conversion, Binary_Formats |
| Last Updated | 2026-02-14 00:00 GMT |
Overview
Concrete tool for writing GGUF binary model files provided by the convert and fs/ggml packages.
Description
The internal writeFile function in convert.go orchestrates the GGUF writing process by calling ggml.WriteGGUF with the complete metadata KV map and tensor list.
splitDim and mergeTensors handle tensor transformations needed before writing: splitting combined weight matrices and merging separate matrices that need to be concatenated in GGUF format.
Usage
Called as the final step of ConvertModel after all tensors and metadata have been prepared.
Code Reference
Source Location
- Repository: ollama
- File: convert/convert.go (writeFile), convert/tensor.go (splitDim, mergeTensors)
- Lines: convert.go:L382-388, tensor.go:L30-89 (splitDim), tensor.go:L91-131 (mergeTensors)
Signature
// Internal to convert package
func writeFile(f *os.File, kv KV, ts []*ggml.Tensor) error
func splitDim(t Tensor, dim int, splits ...split) iter.Seq[*ggml.Tensor]
func mergeTensors(unmatched []Tensor, merges ...merge) (out []*ggml.Tensor, _ []Tensor)
Import
import "github.com/ollama/ollama/convert"
import "github.com/ollama/ollama/fs/ggml"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| f | *os.File | Yes | Output file for GGUF binary |
| kv | KV | Yes | Complete metadata key-value map |
| ts | []*ggml.Tensor | Yes | All model tensors with names, shapes, dtypes, and data |
Outputs
| Name | Type | Description |
|---|---|---|
| error | error | Non-nil if writing fails |
| Side effect | GGUF file | Complete binary file written to disk |
Usage Examples
Internal Usage
// From convert/convert.go ConvertModel
kv := converter.KV(tokenizer)
tensors := converter.Tensors(rawTensors)
err := writeFile(outputFile, kv, tensors)
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment