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:Unslothai Unsloth OLLAMA TEMPLATES

From Leeroopedia
Revision as of 17:02, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Unslothai_Unsloth_OLLAMA_TEMPLATES.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Model_Deployment, Inference
Last Updated 2026-02-07 00:00 GMT

Overview

Concrete data module providing Ollama Modelfile template registry and model-to-template mapping for 50+ model families provided by the Unsloth library.

Description

The ollama_template_mappers.py module provides three data structures:

  • OLLAMA_TEMPLATES: Dictionary mapping template keys (e.g., "llama-3.1", "mistral", "qwen-25") to complete Ollama Modelfile strings with placeholders for GGUF file path and EOS token.
  • OLLAMA_TEMPLATE_TO_MODEL_MAPPER: Maps template keys to lists of model names that use that template.
  • MODEL_TO_OLLAMA_TEMPLATE_MAPPER: Reverse mapping from model names to template keys. Built by inverting OLLAMA_TEMPLATE_TO_MODEL_MAPPER.

These are used automatically during GGUF save/push operations to generate the correct Modelfile.

Usage

Typically used internally by save_pretrained_gguf and push_to_hub_gguf. Can also be imported directly for custom Ollama deployment scripts.

Code Reference

Source Location

  • Repository: unsloth
  • File: unsloth/ollama_template_mappers.py
  • Lines: L21-1706 (OLLAMA_TEMPLATES dict), L1709-2181 (OLLAMA_TEMPLATE_TO_MODEL_MAPPER), L2183-2192 (MODEL_TO_OLLAMA_TEMPLATE_MAPPER)

Signature

# Module-level data structures
OLLAMA_TEMPLATES: Dict[str, str] = {
    "unsloth": '...',
    "llama-3": '...',
    "llama-3.1": '...',
    "mistral": '...',
    "chatml": '...',
    "gemma": '...',
    "qwen-25": '...',
    "phi-4": '...',
    # ... 50+ templates
}

OLLAMA_TEMPLATE_TO_MODEL_MAPPER: Dict[str, List[str]] = {
    "llama-3.1": ["Llama-3.1", "Llama-3.2", ...],
    # ...
}

MODEL_TO_OLLAMA_TEMPLATE_MAPPER: Dict[str, str] = {
    "Llama-3.1": "llama-3.1",
    "Mistral": "mistral",
    # ... reverse lookup
}

Import

from unsloth.ollama_template_mappers import (
    OLLAMA_TEMPLATES,
    MODEL_TO_OLLAMA_TEMPLATE_MAPPER,
)

I/O Contract

Inputs

Name Type Required Description
template_key str Yes (for OLLAMA_TEMPLATES) Template identifier (e.g., "llama-3.1")
model_name str Yes (for mapper) Model name to look up template

Outputs

Name Type Description
template str Ollama Modelfile string with {__FILE_LOCATION__} and {__EOS_TOKEN__} placeholders
template_key str Template identifier for the given model name

Usage Examples

Look Up Template for a Model

from unsloth.ollama_template_mappers import (
    OLLAMA_TEMPLATES,
    MODEL_TO_OLLAMA_TEMPLATE_MAPPER,
)

# Find template key for model
template_key = MODEL_TO_OLLAMA_TEMPLATE_MAPPER.get("Llama-3.1")
# Returns: "llama-3.1"

# Get the Modelfile template
modelfile = OLLAMA_TEMPLATES[template_key]
modelfile = modelfile.replace("{__FILE_LOCATION__}", "./model.gguf")
modelfile = modelfile.replace("{__EOS_TOKEN__}", "<|eot_id|>")

print(modelfile)

Related Pages

Implements Principle

Page Connections

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