Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Ollama Ollama LlamaModel KV

From Leeroopedia
Knowledge Sources
Domains Model_Architecture, Format_Conversion
Last Updated 2026-02-14 00:00 GMT

Overview

Concrete tool for extracting LLaMA architecture hyperparameters into GGUF key-value format provided by the convert package.

Description

llamaModel.KV maps LLaMA-specific config.json fields to GGUF metadata keys. It handles special cases like RoPE scaling parameters, GQA head counts, and vocabulary size adjustments.

The base ModelParameters.KV method handles architecture-independent metadata: file type, quantization version, and tokenizer entries (vocabulary tokens, scores, types, merges, special tokens, chat template).

Usage

Called internally during model conversion to populate the GGUF metadata section.

Code Reference

Source Location

  • Repository: ollama
  • File: convert/convert_llama.go (llamaModel.KV), convert/convert.go (ModelParameters.KV)
  • Lines: convert_llama.go:L51-127 (llamaModel.KV), convert.go:L130-158 (ModelParameters.KV)

Signature

func (p *llamaModel) KV(t *Tokenizer) KV
func (ModelParameters) KV(t *Tokenizer) KV

Import

import "github.com/ollama/ollama/convert"

I/O Contract

Inputs

Name Type Required Description
t *Tokenizer Yes Parsed tokenizer with vocabulary, merges, and special tokens

Outputs

Name Type Description
KV KV (map) GGUF key-value metadata map with architecture and tokenizer entries

Usage Examples

Internal Usage

// From convert/convert.go
kv := converter.KV(tokenizer)
// kv now contains entries like:
// "llama.embedding_length": 4096
// "llama.block_count": 32
// "llama.attention.head_count": 32
// "tokenizer.ggml.tokens": [...]

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment