modelpack

package
v1.1.36 Latest Latest
Warning

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

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

Documentation

Overview

Package modelpack provides native support for CNCF ModelPack format models. It enables docker/model-runner to pull, store, and run models in ModelPack format without conversion. Both Docker and ModelPack formats are supported natively through the types.ModelConfig interface.

The struct types (ModelDescriptor, ModelConfig, ModelFS, ModelCapabilities) are re-exported directly from the official CNCF model-spec Go module so that serialization tags and field definitions stay in sync with the specification.

See: https://github.com/modelpack/model-spec

Index

Constants

View Source
const (
	// MediaTypePrefix is the prefix for all CNCF model config media types.
	MediaTypePrefix = "application/vnd.cncf.model."

	// MediaTypeWeightPrefix is the prefix for all CNCF model weight media types.
	MediaTypeWeightPrefix = "application/vnd.cncf.model.weight."

	// MediaTypeModelConfigV1 is the CNCF model config v1 media type.
	MediaTypeModelConfigV1 = specv1.MediaTypeModelConfig

	// ArtifactTypeModelManifest is the CNCF model manifest artifact type.
	// Required on the manifest when producing model-spec artifacts.
	ArtifactTypeModelManifest = specv1.ArtifactTypeModelManifest

	// MediaTypeWeightRaw is the CNCF model-spec media type for unarchived,
	// uncompressed model weights. This is the type used by modctl and the
	// official model-spec (v0.0.7+).
	MediaTypeWeightRaw = specv1.MediaTypeModelWeightRaw

	// MediaTypeWeightConfigRaw is the CNCF model-spec media type for
	// unarchived, uncompressed weight config files (tokenizer.json,
	// config.json, chat templates, etc.).
	MediaTypeWeightConfigRaw = specv1.MediaTypeModelWeightConfigRaw

	// MediaTypeDocRaw is the CNCF model-spec media type for unarchived,
	// uncompressed documentation files (README.md, LICENSE, etc.).
	MediaTypeDocRaw = specv1.MediaTypeModelDocRaw

	// MediaTypeWeightGGUF is the CNCF ModelPack media type for GGUF weight
	// layers. This is a DMR extension not in the official model-spec; kept
	// for read-compatibility with artifacts produced by older DMR versions.
	MediaTypeWeightGGUF = "application/vnd.cncf.model.weight.v1.gguf"

	// MediaTypeWeightSafetensors is the CNCF ModelPack media type for
	// safetensors weight layers. This is a DMR extension not in the official
	// model-spec; kept for read-compatibility with older DMR artifacts.
	MediaTypeWeightSafetensors = "application/vnd.cncf.model.weight.v1.safetensors"
)

Variables

This section is empty.

Functions

func HashToDigest added in v1.1.36

func HashToDigest(hashStr string) digest.Digest

HashToDigest converts a hash string (in "algorithm:hex" form) to a digest.Digest. This allows callers to pass oci.Hash.String() values without importing the oci package from modelpack.

func IsModelPackConfig

func IsModelPackConfig(raw []byte) bool

IsModelPackConfig detects if raw config bytes are in ModelPack format. It parses the JSON structure for precise detection, avoiding false positives from string matching. ModelPack format characteristics: config.paramSize or descriptor.createdAt Docker format uses: config.parameters and descriptor.created

func IsModelPackGenericWeightMediaType added in v1.1.29

func IsModelPackGenericWeightMediaType(mediaType string) bool

IsModelPackGenericWeightMediaType checks if the given media type is a format-agnostic CNCF ModelPack weight layer type (e.g., MediaTypeWeightRaw). Unlike IsModelPackWeightMediaType, this returns false for format-specific types like MediaTypeWeightGGUF or MediaTypeWeightSafetensors, which already encode the format in the media type itself and must not be matched via the model config format. Use this when the actual format must be inferred from the model config rather than the layer media type.

func IsModelPackWeightMediaType added in v1.1.29

func IsModelPackWeightMediaType(mediaType string) bool

IsModelPackWeightMediaType checks if the given media type is a CNCF ModelPack weight layer type. This includes both format-specific types (e.g., .gguf, .safetensors) and format-agnostic types from the official model-spec (e.g., .raw, .tar).

func LayerKindToMediaType added in v1.1.36

func LayerKindToMediaType(kind LayerKind) oci.MediaType

LayerKindToMediaType maps a LayerKind to the CNCF model-spec raw media type.

func MapLayerMediaType

func MapLayerMediaType(dockerMT oci.MediaType, path string) oci.MediaType

MapLayerMediaType returns the CNCF model-spec media type for the given Docker layer media type and optional filepath annotation.

Types

type LayerKind added in v1.1.36

type LayerKind int

LayerKind is a semantic classification of a model artifact layer. It maps to specific CNCF model-spec media types.

const (
	// KindWeight is a primary model weight file (GGUF, safetensors, DDUF,
	// mmproj, etc.).
	KindWeight LayerKind = iota
	// KindWeightConfig is a weight config file: tokenizer.json, config.json,
	// vLLM config archives, chat templates, etc.
	KindWeightConfig
	// KindDoc is a documentation file: README.md, LICENSE, etc.
	KindDoc
)

func ClassifyLayer added in v1.1.36

func ClassifyLayer(dockerMT oci.MediaType, path string) LayerKind

ClassifyLayer determines the CNCF model-spec LayerKind for a layer. Resolution order:

  1. Explicit Docker semantic media types (most specific).
  2. Filepath/annotation heuristics for ambiguous media types.
  3. Docker media type fallback.

type Model

type Model struct {
	// Descriptor provides metadata about the model provenance and identity.
	Descriptor ModelDescriptor `json:"descriptor"`

	// ModelFS describes the layer content addresses.
	ModelFS ModelFS `json:"modelfs"`

	// Config defines the execution parameters for the model.
	Config ModelConfig `json:"config,omitempty"`
}

Model represents the CNCF ModelPack config structure. It provides the `application/vnd.cncf.model.config.v1+json` mediatype when marshalled to JSON.

The struct mirrors specv1.Model but is declared as its own named type so that it can implement the types.ModelConfig interface required by DMR.

func DockerConfigToModelPack added in v1.1.36

func DockerConfigToModelPack(
	cfg types.Config,
	desc types.Descriptor,
	diffIDs []digest.Digest,
) Model

DockerConfigToModelPack converts a Docker-format model config into a CNCF ModelPack Model config. The diffIDs should already be in digest.Digest ("algorithm:hex") format.

func (*Model) GetArchitecture

func (m *Model) GetArchitecture() string

GetArchitecture returns the model architecture.

func (*Model) GetContextSize

func (m *Model) GetContextSize() *int32

GetContextSize returns the context size. ModelPack spec does not define this field, so it always returns nil.

func (*Model) GetFormat

func (m *Model) GetFormat() types.Format

GetFormat returns the model format, converted to types.Format.

func (*Model) GetParameters

func (m *Model) GetParameters() string

GetParameters returns the parameters description. ModelPack uses ParamSize instead of Parameters, so return ParamSize.

func (*Model) GetQuantization

func (m *Model) GetQuantization() string

GetQuantization returns the quantization method.

func (*Model) GetSize

func (m *Model) GetSize() string

GetSize returns the parameter size (e.g., "8b").

type ModelCapabilities

type ModelCapabilities = specv1.ModelCapabilities

ModelCapabilities defines the special capabilities that the model supports.

type ModelConfig

type ModelConfig = specv1.ModelConfig

ModelConfig defines the execution parameters for an inference engine.

type ModelDescriptor

type ModelDescriptor = specv1.ModelDescriptor

ModelDescriptor defines the general information of a model.

type ModelFS

type ModelFS = specv1.ModelFS

ModelFS describes the layer content addresses.

Jump to

Keyboard shortcuts

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