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 XServer Show

From Leeroopedia
Knowledge Sources
Domains Server, Model Metadata
Last Updated 2025-02-15 00:00 GMT

Overview

Extracts model metadata from safetensors-based models for the ollama show command, providing architecture info, parameter counts, tensor details, and dtype information.

Description

GetSafetensorsLLMInfo reads config.json from the model manifest and builds a GGML-compatible KV info map with architecture, context length, embedding length, block count, attention heads, vocab size, and parameter count. Handles HuggingFace architecture naming conventions and multimodal models with text_config sub-objects. GetSafetensorsTensorInfo parses safetensors blob headers to enumerate individual tensors with their shapes, dtypes, and sizes.

Usage

Called by the ollama show command to display detailed model information for safetensors models, matching the metadata display that GGUF models already support.

Code Reference

Source Location

  • Repository: Ollama
  • File: x/server/show.go
  • Lines: 1-501

Signature

type modelConfig struct {
    Architectures         []string `json:"architectures"`
    ModelType             string   `json:"model_type"`
    HiddenSize            int      `json:"hidden_size"`
    NumHiddenLayers       int      `json:"num_hidden_layers"`
    // ... more fields
}

func GetSafetensorsLLMInfo(name model.Name) (map[string]any, error)
func GetSafetensorsTensorInfo(name model.Name) ([]api.Tensor, error)
func GetSafetensorsDtype(name model.Name) (string, error)

Import

import "github.com/ollama/ollama/x/server"

I/O Contract

Inputs

Name Type Required Description
name model.Name Yes Parsed model name to look up

Outputs

Name Type Description
info map[string]any GGML-compatible KV metadata map
tensors []api.Tensor Tensor details with shapes and dtypes
error error Non-nil if manifest or config reading fails

Usage Examples

name := model.ParseName("my-model:latest")

info, err := server.GetSafetensorsLLMInfo(name)
// info["general.architecture"] = "glm4moelite"
// info["general.parameter_count"] = 14000000000

tensors, err := server.GetSafetensorsTensorInfo(name)
for _, t := range tensors {
    fmt.Printf("%s: %v (%s)\n", t.Name, t.Shape, t.Type)
}

Related Pages

Page Connections

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