Implementation:Ollama Ollama Imagegen Manifest
| Knowledge Sources | |
|---|---|
| Domains | Image Generation, Model Storage |
| Last Updated | 2025-02-15 00:00 GMT |
Overview
Handles manifest loading and blob resolution for image generation models stored in Ollama's content-addressed blob storage.
Description
The manifest.go file defines the Manifest and ModelManifest types for parsing Ollama model manifests. It resolves model names (supporting formats like "modelname", "modelname:tag", "host/namespace/name:tag") to manifest file paths, loads JSON manifests, and provides methods to access tensor layers by component (text_encoder, transformer, vae) and config files. It also handles blob path resolution by converting digest format (sha256:abc) to file paths (sha256-abc) and supports reading tensor metadata including quantization type detection.
Usage
Used by all image generation model loaders to locate and read model weights and configuration files from Ollama's blob storage.
Code Reference
Source Location
- Repository: Ollama
- File: x/imagegen/manifest/manifest.go
- Lines: 1-307
Signature
type ManifestLayer struct {
MediaType string `json:"mediaType"`
Digest string `json:"digest"`
Size int64 `json:"size"`
Name string `json:"name,omitempty"`
}
type Manifest struct {
SchemaVersion int `json:"schemaVersion"`
MediaType string `json:"mediaType"`
Config ManifestLayer `json:"config"`
Layers []ManifestLayer `json:"layers"`
}
type ModelManifest struct {
Manifest *Manifest
BlobDir string
}
func LoadManifest(modelName string) (*ModelManifest, error)
func (m *ModelManifest) BlobPath(digest string) string
func (m *ModelManifest) GetTensorLayers(component string) []ManifestLayer
func (m *ModelManifest) ReadConfigJSON(configPath string, v any) error
Import
import "github.com/ollama/ollama/x/imagegen/manifest"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| modelName | string | Yes | Model name in Ollama format (e.g., "flux2-klein:latest") |
| component | string | No | Component filter for tensor layers (e.g., "transformer") |
Outputs
| Name | Type | Description |
|---|---|---|
| *ModelManifest | *ModelManifest | Parsed manifest with blob resolution methods |
| error | error | Error if manifest cannot be loaded or parsed |
Usage Examples
manifest, err := manifest.LoadManifest("flux2-klein:latest")
if err != nil {
return err
}
// Get transformer tensor layers
layers := manifest.GetTensorLayers("transformer")
// Read config file
var cfg TransformerConfig
err = manifest.ReadConfigJSON("transformer/config.json", &cfg)