Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Ollama Ollama Convert Gemma3

From Leeroopedia
Revision as of 13:24, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Ollama_Ollama_Convert_Gemma3.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Model Conversion, GGUF Format
Last Updated 2025-02-15 00:00 GMT

Overview

Implements the GGUF model converter for the Google Gemma 3 multimodal architecture, supporting sliding window attention patterns, SigLIP vision encoder, and YaRN RoPE scaling.

Description

The gemma3Model struct embeds gemmaModel and adds multimodal support with text and vision configurations. It handles both causal-only (Gemma3ForCausalLM) and multimodal variants, emitting architecture-appropriate KV metadata. Key features include: sliding window attention pattern configuration (via sliding_window_pattern or layer_types), per-model-size head count inference (4B/12B/27B), final logit softcapping, dual RoPE frequency bases (local and global), YaRN rope scaling parameters, and SigLIP vision encoder config (layers, embedding length, image/patch size, channels). Inherits the add-one norm weight repacking from gemmaModel.

Usage

Invoked automatically when the model's architecture matches Gemma3ForCausalLM or Gemma3ForConditionalGeneration.

Code Reference

Source Location

  • Repository: Ollama
  • File: convert/convert_gemma3.go
  • Lines: 1-180

Signature

type gemma3Model struct {
    gemmaModel
    Architecture             string
    TextModel                struct { ... } `json:"text_config"`
    VisionModel              struct { ... } `json:"vision_config"`
    SlidingWindowPattern     *uint32        `json:"sliding_window_pattern"`
    LayerTypes               []string       `json:"layer_types"`
    MultiModalTokensPerImage uint32         `json:"mm_tokens_per_image"`
    RopeScaling              *struct { ... } `json:"rope_scaling"`
}

func (p *gemma3Model) KV(t *Tokenizer) KV
func (p *gemma3Model) Replacements() []string

Import

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

I/O Contract

Inputs

Name Type Required Description
t *Tokenizer Yes Tokenizer data for GGUF metadata

Outputs

Name Type Description
KV KV GGUF metadata with gemma3.* keys for text, vision, sliding window, and RoPE

Usage Examples

// Converter registered for Gemma 3 architectures
// m := &gemma3Model{}
// json.Unmarshal(configData, m)
// kv := m.KV(tokenizer)
// Sliding window pattern is computed from layer_types or sliding_window_pattern

Related Pages

Page Connections

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