format

package
v1.0.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2026 License: Apache-2.0, Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package format provides a unified interface for handling different model formats. It uses the Strategy pattern to encapsulate format-specific behavior while providing a common interface for model creation and metadata extraction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(f Format)

Register adds a format implementation to the global registry. This should be called in init() functions by format implementations.

Types

type DDUFFormat added in v1.0.12

type DDUFFormat struct{}

DDUFFormat implements the Format interface for DDUF (Diffusers Unified Format) model files. DDUF is a single-file archive format for diffusion models used by HuggingFace Diffusers.

func (*DDUFFormat) DiscoverShards added in v1.0.12

func (d *DDUFFormat) DiscoverShards(path string) ([]string, error)

DiscoverShards finds all DDUF shard files for a model. DDUF is a single-file format, so this always returns a slice containing only the input path.

func (*DDUFFormat) ExtractConfig added in v1.0.12

func (d *DDUFFormat) ExtractConfig(paths []string) (types.Config, error)

ExtractConfig parses DDUF file(s) and extracts model configuration metadata. DDUF files are zip archives containing model config, so we extract what we can.

func (*DDUFFormat) MediaType added in v1.0.12

func (d *DDUFFormat) MediaType() oci.MediaType

MediaType returns the OCI media type for DDUF layers.

func (*DDUFFormat) Name added in v1.0.12

func (d *DDUFFormat) Name() types.Format

Name returns the format identifier for DDUF.

type Format

type Format interface {
	// Name returns the format identifier (e.g., "gguf" or "safetensors")
	Name() types.Format

	// MediaType returns the OCI media type for weight layers of this format
	MediaType() oci.MediaType

	// DiscoverShards finds all shard files for a sharded model given a starting path.
	// For single-file models, it returns a slice containing only the input path.
	// Returns an error if shards are incomplete or cannot be found.
	DiscoverShards(path string) ([]string, error)

	// ExtractConfig parses the weight files and extracts model configuration metadata.
	// This includes parameters count, quantization type, architecture, etc.
	ExtractConfig(paths []string) (types.Config, error)
}

Format defines the interface for model format-specific operations. Implementations handle the differences between GGUF and Safetensors formats.

func DetectFromPath

func DetectFromPath(path string) (Format, error)

DetectFromPath determines the model format based on file extension. Returns the appropriate Format implementation or an error if unrecognized.

func DetectFromPaths

func DetectFromPaths(paths []string) (Format, error)

DetectFromPaths determines the model format based on a list of file paths. All paths must be of the same format. Returns an error if formats are mixed.

func Get

func Get(name types.Format) (Format, error)

Get returns the format implementation for the given format type. Returns an error if the format is not registered.

type GGUFFormat

type GGUFFormat struct{}

GGUFFormat implements the Format interface for GGUF model files.

func (*GGUFFormat) DiscoverShards

func (g *GGUFFormat) DiscoverShards(path string) ([]string, error)

DiscoverShards finds all GGUF shard files for a sharded model. GGUF shards follow the pattern: <name>-00001-of-00015.gguf For single-file models, returns a slice containing only the input path.

func (*GGUFFormat) ExtractConfig

func (g *GGUFFormat) ExtractConfig(paths []string) (types.Config, error)

ExtractConfig parses GGUF file(s) and extracts model configuration metadata.

func (*GGUFFormat) MediaType

func (g *GGUFFormat) MediaType() oci.MediaType

MediaType returns the OCI media type for GGUF layers.

func (*GGUFFormat) Name

func (g *GGUFFormat) Name() types.Format

Name returns the format identifier for GGUF.

type SafetensorsFormat

type SafetensorsFormat struct{}

SafetensorsFormat implements the Format interface for Safetensors model files.

func (*SafetensorsFormat) DiscoverShards

func (s *SafetensorsFormat) DiscoverShards(path string) ([]string, error)

DiscoverShards finds all Safetensors shard files for a sharded model. Safetensors shards follow the pattern: <name>-00001-of-00003.safetensors For single-file models, returns a slice containing only the input path.

func (*SafetensorsFormat) ExtractConfig

func (s *SafetensorsFormat) ExtractConfig(paths []string) (types.Config, error)

ExtractConfig parses Safetensors file(s) and extracts model configuration metadata.

func (*SafetensorsFormat) MediaType

func (s *SafetensorsFormat) MediaType() oci.MediaType

MediaType returns the OCI media type for Safetensors layers.

func (*SafetensorsFormat) Name

func (s *SafetensorsFormat) Name() types.Format

Name returns the format identifier for Safetensors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL