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.
Index ¶
- Constants
- func HashToDigest(hashStr string) digest.Digest
- func IsModelPackConfig(raw []byte) bool
- func IsModelPackGenericWeightMediaType(mediaType string) bool
- func IsModelPackWeightMediaType(mediaType string) bool
- func LayerKindToMediaType(kind LayerKind) oci.MediaType
- func MapLayerMediaType(dockerMT oci.MediaType, path string) oci.MediaType
- type LayerKind
- type Model
- type ModelCapabilities
- type ModelConfig
- type ModelDescriptor
- type ModelFS
Constants ¶
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
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 ¶
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
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
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
LayerKindToMediaType maps a LayerKind to the CNCF model-spec raw media type.
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
ClassifyLayer determines the CNCF model-spec LayerKind for a layer. Resolution order:
- Explicit Docker semantic media types (most specific).
- Filepath/annotation heuristics for ambiguous media types.
- 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 ¶
GetArchitecture returns the model architecture.
func (*Model) GetContextSize ¶
GetContextSize returns the context size. ModelPack spec does not define this field, so it always returns nil.
func (*Model) GetParameters ¶
GetParameters returns the parameters description. ModelPack uses ParamSize instead of Parameters, so return ParamSize.
func (*Model) GetQuantization ¶
GetQuantization returns the quantization method.
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.