config

package
v0.17.0-alpha4 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: Apache-2.0 Imports: 23 Imported by: 1

Documentation

Index

Constants

View Source
const (
	MinimumMajorPythonVersion               int    = 3
	MinimumMinorPythonVersion               int    = 10
	MinimumMinorPythonVersionForConcurrency int    = 11
	MinimumMajorCudaVersion                 int    = 11
	DefaultPythonVersion                    string = "3.13"
)

Variables

View Source
var (
	BuildSourceEpochTimestamp int64 = -1
	BuildXCachePath           string
	PipPackageNameRegex       = regexp.MustCompile(`^([^>=<~ \n[#]+)`)
)
View Source
var CUDABaseImages []CUDABaseImage
View Source
var TFCompatibilityMatrix []TFCompatibility
View Source
var TorchCompatibilityMatrix []TorchCompatibility

Functions

func BaseDockerImageName added in v0.0.8

func BaseDockerImageName(projectDir string) string

BaseDockerImageName returns the Docker image name for base images

func DockerImageName added in v0.0.8

func DockerImageName(projectDir string) string

DockerImageName returns the default Docker image name for images

func GetProjectDir

func GetProjectDir(configFilename string) (string, error)

GetProjectDir returns the project's root directory by searching for the config file starting from the current working directory.

Types

type ArgumentType added in v0.0.8

type ArgumentType string

ArgumentType represents the type of a run argument.

const (
	ArgumentTypeString ArgumentType = "str"
	ArgumentTypeInt    ArgumentType = "int"
	ArgumentTypeFloat  ArgumentType = "float"
	ArgumentTypeBool   ArgumentType = "bool"
	ArgumentTypePath   ArgumentType = "Path"
)

type Build added in v0.0.8

type Build struct {
	GPU                bool      `json:"gpu,omitempty" yaml:"gpu,omitempty"`
	PythonVersion      string    `json:"python_version,omitempty" yaml:"python_version"`
	PythonRequirements string    `json:"python_requirements,omitempty" yaml:"python_requirements,omitempty"`
	PythonPackages     []string  `json:"python_packages,omitempty" yaml:"python_packages,omitempty"` // Deprecated, but included for backwards compatibility
	Run                []RunItem `json:"run,omitempty" yaml:"run,omitempty"`
	SystemPackages     []string  `json:"system_packages,omitempty" yaml:"system_packages,omitempty"`
	PreInstall         []string  `json:"pre_install,omitempty" yaml:"pre_install,omitempty"` // Deprecated, but included for backwards compatibility
	CUDA               string    `json:"cuda,omitempty" yaml:"cuda,omitempty"`
	CuDNN              string    `json:"cudnn,omitempty" yaml:"cudnn,omitempty"`
	// contains filtered or unexported fields
}

type BuildOptions

type BuildOptions struct {
	// SourceEpochTimestamp is the number of seconds since Unix epoch to use
	// for the build timestamp. Set to -1 to disable timestamp rewrites.
	// This is useful for reproducible builds.
	SourceEpochTimestamp int64

	// XCachePath is the path to the BuildKit cache directory.
	// If empty, inline caching is used instead of local cache.
	XCachePath string
}

BuildOptions contains runtime options passed via CLI flags, not from cog.yaml. These are separate from the Config struct because they are not part of the model configuration - they are build-time settings that affect how the container is built but not what's in it.

func DefaultBuildOptions

func DefaultBuildOptions() BuildOptions

DefaultBuildOptions returns BuildOptions with sensible defaults.

type CUDABaseImage added in v0.0.8

type CUDABaseImage struct {
	Tag     string
	CUDA    string
	CuDNN   string
	IsDevel bool
	Ubuntu  string
}

func (*CUDABaseImage) ImageTag added in v0.0.8

func (i *CUDABaseImage) ImageTag() string

type CompatibilityError

type CompatibilityError struct {
	Component1 string
	Version1   string
	Component2 string
	Version2   string
	Message    string
}

CompatibilityError indicates an incompatible version combination.

func (*CompatibilityError) ConfigError

func (e *CompatibilityError) ConfigError()

func (*CompatibilityError) Error

func (e *CompatibilityError) Error() string

type Concurrency added in v0.13.7

type Concurrency struct {
	Max int `json:"max,omitempty" yaml:"max"`
}

type Config added in v0.0.8

type Config struct {
	Build       *Build         `json:"build" yaml:"build"`
	Image       string         `json:"image,omitempty" yaml:"image,omitempty"`
	Predict     string         `json:"predict,omitempty" yaml:"predict"`
	Train       string         `json:"train,omitempty" yaml:"train,omitempty"`
	Concurrency *Concurrency   `json:"concurrency,omitempty" yaml:"concurrency,omitempty"`
	Environment []string       `json:"environment,omitempty" yaml:"environment,omitempty"`
	Weights     []WeightSource `json:"weights,omitempty" yaml:"weights,omitempty"`
	// contains filtered or unexported fields
}

func FromYAML added in v0.0.16

func FromYAML(contents []byte) (*Config, error)

FromYAML parses YAML content into an uncompleted Config. This is a convenience function primarily for testing. Callers should call Complete() on the returned config to resolve CUDA versions etc. For production code, use Load() which handles validation and completion.

Note: This function skips validation since it has no project directory context. The Complete() method will validate requirements files exist when called.

func (*Config) CUDABaseImageTag added in v0.0.8

func (c *Config) CUDABaseImageTag() (string, error)

func (*Config) Complete

func (c *Config) Complete(projectDir string) error

Complete performs CUDA resolution, requirements loading, and environment loading for a Config. Use this when building a Config struct directly (not from YAML). For configs loaded from YAML, use Load() instead which handles validation and completion.

func (*Config) ParsedEnvironment added in v0.14.9

func (c *Config) ParsedEnvironment() map[string]string

func (*Config) PythonRequirementsForArch added in v0.5.0

func (c *Config) PythonRequirementsForArch(goos string, goarch string, includePackages []string) (string, error)

PythonRequirementsForArch returns a requirements.txt file with all the GPU packages resolved for given OS and architecture.

func (*Config) RequirementsFile added in v0.15.2

func (c *Config) RequirementsFile(projectDir string) string

func (*Config) TensorFlowVersion added in v0.9.7

func (c *Config) TensorFlowVersion() (string, bool)

func (*Config) TorchVersion added in v0.9.7

func (c *Config) TorchVersion() (string, bool)

func (*Config) TorchaudioVersion added in v0.9.21

func (c *Config) TorchaudioVersion() (string, bool)

func (*Config) TorchvisionVersion added in v0.9.7

func (c *Config) TorchvisionVersion() (string, bool)

type ConfigError

type ConfigError interface {
	error
	ConfigError() // marker method
}

ConfigError is the base interface for all config errors. Allows callers to use errors.As to get config-specific details.

type DeprecationWarning

type DeprecationWarning struct {
	Field       string
	Replacement string
	Message     string
}

DeprecationWarning indicates use of a deprecated field. This is a warning, not an error - validation still succeeds.

func (*DeprecationWarning) ConfigError

func (w *DeprecationWarning) ConfigError()

func (*DeprecationWarning) Error

func (w *DeprecationWarning) Error() string

type LoadResult

type LoadResult struct {
	Config   *Config
	Warnings []DeprecationWarning
	RootDir  string
}

LoadResult contains the loaded config and any warnings.

func Load

func Load(r io.Reader, projectDir string) (*LoadResult, error)

Load parses, validates, and completes a config from an io.Reader. The projectDir is used for validation (checking that referenced files exist) and for completion (resolving CUDA versions, loading requirements files, etc.). Always returns warnings if present, even on success.

type ParseError

type ParseError struct {
	Filename string
	Err      error
}

ParseError indicates the YAML file could not be parsed.

func (*ParseError) ConfigError

func (e *ParseError) ConfigError()

func (*ParseError) Error

func (e *ParseError) Error() string

func (*ParseError) Unwrap

func (e *ParseError) Unwrap() error

type RunArgument added in v0.0.8

type RunArgument struct {
	Type    ArgumentType `json:"type"`
	Default *string      `json:"default"`
	Min     *string      `json:"min"`
	Max     *string      `json:"max"`
	Options *[]string    `json:"options"`
	Help    *string      `json:"help"`
}

RunArgument describes a single argument for a prediction run.

type RunItem added in v0.7.0

type RunItem struct {
	Command string `json:"command,omitempty" yaml:"command"`
	Mounts  []struct {
		Type   string `json:"type,omitempty" yaml:"type"`
		ID     string `json:"id,omitempty" yaml:"id"`
		Target string `json:"target,omitempty" yaml:"target"`
	} `json:"mounts,omitempty" yaml:"mounts,omitempty"`
}

func (*RunItem) UnmarshalJSON added in v0.7.1

func (r *RunItem) UnmarshalJSON(data []byte) error

func (*RunItem) UnmarshalYAML added in v0.7.0

func (r *RunItem) UnmarshalYAML(unmarshal func(any) error) error

type SchemaError

type SchemaError struct {
	Field   string
	Message string
}

SchemaError indicates the config structure doesn't match the schema. For example, wrong type for a field or unknown field.

func (*SchemaError) ConfigError

func (e *SchemaError) ConfigError()

func (*SchemaError) Error

func (e *SchemaError) Error() string

type TFCompatibility added in v0.0.8

type TFCompatibility struct {
	TF           string
	TFCPUPackage string
	TFGPUPackage string
	CUDA         string
	CuDNN        string
	Pythons      []string
}

func (*TFCompatibility) UnmarshalJSON added in v0.0.8

func (compat *TFCompatibility) UnmarshalJSON(data []byte) error

type TorchCompatibility added in v0.0.8

type TorchCompatibility struct {
	Torch         string
	Torchvision   string
	Torchaudio    string
	FindLinks     string
	ExtraIndexURL string
	CUDA          *string
	Pythons       []string
}

func (*TorchCompatibility) TorchVersion added in v0.0.8

func (c *TorchCompatibility) TorchVersion() string

func (*TorchCompatibility) TorchvisionVersion added in v0.0.8

func (c *TorchCompatibility) TorchvisionVersion() string

type ValidateOption

type ValidateOption func(*validateOptions)

ValidateOption configures validation behavior.

func WithProjectDir

func WithProjectDir(dir string) ValidateOption

WithProjectDir sets the project directory for resolving relative paths.

func WithRequirementsFS

func WithRequirementsFS(fsys fs.FS) ValidateOption

WithRequirementsFS sets the filesystem for reading python_requirements file.

func WithStrictDeprecations

func WithStrictDeprecations() ValidateOption

WithStrictDeprecations treats deprecation warnings as errors.

type ValidationError

type ValidationError struct {
	Field   string
	Value   string
	Message string
}

ValidationError indicates a semantic validation failure. The config parses correctly but values are invalid.

func (*ValidationError) ConfigError

func (e *ValidationError) ConfigError()

func (*ValidationError) Error

func (e *ValidationError) Error() string

type ValidationResult

type ValidationResult struct {
	Errors   []error
	Warnings []DeprecationWarning
}

ValidationResult holds all errors and warnings from validation.

func NewValidationResult

func NewValidationResult() *ValidationResult

NewValidationResult creates an empty ValidationResult.

func ValidateConfigFile

func ValidateConfigFile(cfg *configFile, opts ...ValidateOption) *ValidationResult

ValidateConfigFile checks a configFile for errors. Returns all validation errors and deprecation warnings. Does not mutate the input.

func (*ValidationResult) AddError

func (r *ValidationResult) AddError(err error)

AddError adds a validation error.

func (*ValidationResult) AddWarning

func (r *ValidationResult) AddWarning(w DeprecationWarning)

AddWarning adds a deprecation warning.

func (*ValidationResult) Err

func (r *ValidationResult) Err() error

Err returns a combined error if there are any validation errors, nil otherwise.

func (*ValidationResult) HasErrors

func (r *ValidationResult) HasErrors() bool

HasErrors returns true if there are any validation errors.

func (*ValidationResult) HasWarnings

func (r *ValidationResult) HasWarnings() bool

HasWarnings returns true if there are any deprecation warnings.

type WeightSource

type WeightSource struct {
	Name   string `json:"name,omitempty" yaml:"name,omitempty"`
	Source string `json:"source" yaml:"source"`
	Target string `json:"target,omitempty" yaml:"target,omitempty"`
}

WeightSource defines a weight file or directory to include in the model.

Jump to

Keyboard shortcuts

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