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 Imagegen Engine Main

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

Overview

Standalone CLI binary for direct model inference, supporting text generation, image generation, and multimodal models with GPU profiling.

Description

The main.go file in cmd/engine provides a standalone CLI for testing and running models directly without the Ollama server. It parses flags for model path, prompt, generation parameters (max-tokens, temperature, top-p, top-k), image generation parameters (width, height, steps, seed, output path), and utility options (list tensors, CPU profiling, GPU capture, wired memory limit). The main function detects model type and dispatches to the appropriate pipeline: Z-Image or FLUX.2 for image generation, and Gemma3/Llama/GPT-OSS for text generation. It supports multi-image input for editing, negative prompts for CFG, TeaCache for fast inference, and fused QKV for non-quantized models.

Usage

Used for development and testing of MLX models outside the Ollama server framework, supporting GPU trace capture and profiling.

Code Reference

Source Location

  • Repository: Ollama
  • File: x/imagegen/cmd/engine/main.go
  • Lines: 1-294

Signature

func main()

// CLI flags:
// -model        Model directory
// -prompt       Text prompt
// -max-tokens   Max tokens for text generation
// -width        Image width
// -height       Image height
// -steps        Denoising steps
// -seed         Random seed
// -output       Output image path
// -zimage       Z-Image generation mode
// -flux2        FLUX.2 Klein generation mode
// -teacache     Enable TeaCache
// -gpu-capture  GPU trace capture path

Import

import (
    "github.com/ollama/ollama/x/imagegen"
    "github.com/ollama/ollama/x/imagegen/models/flux2"
    "github.com/ollama/ollama/x/imagegen/models/zimage"
)

I/O Contract

Inputs

Name Type Required Description
-model string Yes Path to model directory
-prompt string Yes Text prompt for generation
-output string No Output file path (default "output.png")

Outputs

Name Type Description
stdout text Generated text or status messages
output file PNG Generated image file

Usage Examples

// Command line usage:
// go run ./x/imagegen/cmd/engine -model /path/to/zimage -zimage -prompt "a cat" -output cat.png
// go run ./x/imagegen/cmd/engine -model /path/to/llama -prompt "Hello" -max-tokens 100

Related Pages

Page Connections

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