Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions cmd/cli/commands/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,7 @@ func newInspectCmd() *cobra.Command {
c := &cobra.Command{
Use: "inspect MODEL",
Short: "Display detailed information on one model",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return fmt.Errorf(
"'docker model inspect' requires 1 argument.\n\n" +
"Usage: docker model inspect MODEL\n\n" +
"See 'docker model inspect --help' for more information",
)
}
return nil
},
Args: requireExactArgs(1, "inspect", "MODEL"),
RunE: func(cmd *cobra.Command, args []string) error {
if _, err := ensureStandaloneRunnerAvailable(cmd.Context(), asPrinter(cmd), false); err != nil {
return fmt.Errorf("unable to initialize standalone model runner: %w", err)
Expand Down
15 changes: 8 additions & 7 deletions cmd/cli/commands/install-runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,13 @@ func newInstallRunner() *cobra.Command {
},
ValidArgsFunction: completion.NoComplete,
}
c.Flags().Uint16Var(&port, "port", 0,
"Docker container port for Docker Model Runner (default: 12434 for Docker Engine, 12435 for Cloud mode)")
c.Flags().StringVar(&host, "host", "127.0.0.1", "Host address to bind Docker Model Runner")
c.Flags().StringVar(&gpuMode, "gpu", "auto", "Specify GPU support (none|auto|cuda|rocm|musa|cann)")
c.Flags().StringVar(&backend, "backend", "", backendUsage)
c.Flags().BoolVar(&doNotTrack, "do-not-track", false, "Do not track models usage in Docker Model Runner")
c.Flags().BoolVar(&debug, "debug", false, "Enable debug logging")
addRunnerFlags(c, runnerFlagOptions{
Port: &port,
Host: &host,
GpuMode: &gpuMode,
Backend: &backend,
DoNotTrack: &doNotTrack,
Debug: &debug,
})
return c
}
9 changes: 2 additions & 7 deletions cmd/cli/commands/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,8 @@ func newPackagedCmd() *cobra.Command {
"When packaging a Safetensors model, --safetensors-dir should point to a directory containing .safetensors files and config files (*.json, merges.txt). All files will be auto-discovered and config files will be packaged into a tar archive.\n" +
"When packaging from an existing model using --from, you can modify properties like context size to create a variant of the original model.",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return fmt.Errorf(
"'docker model package' requires 1 argument.\n\n"+
"Usage: docker model %s\n\n"+
"See 'docker model package --help' for more information",
cmd.Use,
)
if err := requireExactArgs(1, "package", "MODEL")(cmd, args); err != nil {
return err
}

// Validate that exactly one of --gguf, --safetensors-dir, or --from is provided (mutually exclusive)
Expand Down
11 changes: 1 addition & 10 deletions cmd/cli/commands/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,7 @@ func newPullCmd() *cobra.Command {
c := &cobra.Command{
Use: "pull MODEL",
Short: "Pull a model from Docker Hub or HuggingFace to your local environment",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return fmt.Errorf(
"'docker model pull' requires 1 argument.\n\n" +
"Usage: docker model pull MODEL\n\n" +
"See 'docker model pull --help' for more information",
)
}
return nil
},
Args: requireExactArgs(1, "pull", "MODEL"),
RunE: func(cmd *cobra.Command, args []string) error {
if _, err := ensureStandaloneRunnerAvailable(cmd.Context(), asPrinter(cmd), false); err != nil {
return fmt.Errorf("unable to initialize standalone model runner: %w", err)
Expand Down
11 changes: 1 addition & 10 deletions cmd/cli/commands/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,7 @@ func newPushCmd() *cobra.Command {
c := &cobra.Command{
Use: "push MODEL",
Short: "Push a model to Docker Hub",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return fmt.Errorf(
"'docker model push' requires 1 argument.\n\n" +
"Usage: docker model push MODEL\n\n" +
"See 'docker model push --help' for more information",
)
}
return nil
},
Args: requireExactArgs(1, "push", "MODEL"),
RunE: func(cmd *cobra.Command, args []string) error {
if _, err := ensureStandaloneRunnerAvailable(cmd.Context(), asPrinter(cmd), false); err != nil {
return fmt.Errorf("unable to initialize standalone model runner: %w", err)
Expand Down
15 changes: 8 additions & 7 deletions cmd/cli/commands/reinstall-runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ func newReinstallRunner() *cobra.Command {
},
ValidArgsFunction: completion.NoComplete,
}
c.Flags().Uint16Var(&port, "port", 0,
"Docker container port for Docker Model Runner (default: 12434 for Docker Engine, 12435 for Cloud mode)")
c.Flags().StringVar(&host, "host", "127.0.0.1", "Host address to bind Docker Model Runner")
c.Flags().StringVar(&gpuMode, "gpu", "auto", "Specify GPU support (none|auto|cuda|musa|rocm|cann)")
c.Flags().StringVar(&backend, "backend", "", backendUsage)
c.Flags().BoolVar(&doNotTrack, "do-not-track", false, "Do not track models usage in Docker Model Runner")
c.Flags().BoolVar(&debug, "debug", false, "Enable debug logging")
addRunnerFlags(c, runnerFlagOptions{
Port: &port,
Host: &host,
GpuMode: &gpuMode,
Backend: &backend,
DoNotTrack: &doNotTrack,
Debug: &debug,
})
return c
}
13 changes: 7 additions & 6 deletions cmd/cli/commands/restart-runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ func newRestartRunner() *cobra.Command {
},
ValidArgsFunction: completion.NoComplete,
}
c.Flags().Uint16Var(&port, "port", 0,
"Docker container port for Docker Model Runner (default: 12434 for Docker Engine, 12435 for Cloud mode)")
c.Flags().StringVar(&host, "host", "127.0.0.1", "Host address to bind Docker Model Runner")
c.Flags().StringVar(&gpuMode, "gpu", "auto", "Specify GPU support (none|auto|cuda|musa|rocm|cann)")
c.Flags().BoolVar(&doNotTrack, "do-not-track", false, "Do not track models usage in Docker Model Runner")
c.Flags().BoolVar(&debug, "debug", false, "Enable debug logging")
addRunnerFlags(c, runnerFlagOptions{
Port: &port,
Host: &host,
GpuMode: &gpuMode,
DoNotTrack: &doNotTrack,
Debug: &debug,
})
return c
}
11 changes: 1 addition & 10 deletions cmd/cli/commands/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,7 @@ func newRemoveCmd() *cobra.Command {
c := &cobra.Command{
Use: "rm [MODEL...]",
Short: "Remove local models downloaded from Docker Hub",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf(
"'docker model rm' requires at least 1 argument.\n\n" +
"Usage: docker model rm [MODEL...]\n\n" +
"See 'docker model rm --help' for more information",
)
}
return nil
},
Args: requireMinArgs(1, "rm", "[MODEL...]"),
RunE: func(cmd *cobra.Command, args []string) error {
if _, err := ensureStandaloneRunnerAvailable(cmd.Context(), asPrinter(cmd), false); err != nil {
return fmt.Errorf("unable to initialize standalone model runner: %w", err)
Expand Down
12 changes: 1 addition & 11 deletions cmd/cli/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,17 +730,7 @@ func newRunCmd() *cobra.Command {
},
ValidArgsFunction: completion.ModelNames(getDesktopClient, 1),
}
c.Args = func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf(
"'docker model run' requires at least 1 argument.\n\n" +
"Usage: docker model run " + cmdArgs + "\n\n" +
"See 'docker model run --help' for more information",
)
}

return nil
}
c.Args = requireMinArgs(1, "run", cmdArgs)

c.Flags().BoolVar(&debug, "debug", false, "Enable debug logging")
c.Flags().BoolVar(&ignoreRuntimeMemoryCheck, "ignore-runtime-memory-check", false, "Do not block pull if estimated runtime memory for model exceeds system resources.")
Expand Down
13 changes: 7 additions & 6 deletions cmd/cli/commands/start-runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ func newStartRunner() *cobra.Command {
},
ValidArgsFunction: completion.NoComplete,
}
c.Flags().Uint16Var(&port, "port", 0,
"Docker container port for Docker Model Runner (default: 12434 for Docker Engine, 12435 for Cloud mode)")
c.Flags().StringVar(&gpuMode, "gpu", "auto", "Specify GPU support (none|auto|cuda|musa|rocm|cann)")
c.Flags().StringVar(&backend, "backend", "", backendUsage)
c.Flags().BoolVar(&doNotTrack, "do-not-track", false, "Do not track models usage in Docker Model Runner")
c.Flags().BoolVar(&debug, "debug", false, "Enable debug logging")
addRunnerFlags(c, runnerFlagOptions{
Port: &port,
GpuMode: &gpuMode,
Backend: &backend,
DoNotTrack: &doNotTrack,
Debug: &debug,
})
return c
}
11 changes: 1 addition & 10 deletions cmd/cli/commands/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,7 @@ func newTagCmd() *cobra.Command {
c := &cobra.Command{
Use: "tag SOURCE TARGET",
Short: "Tag a model",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) != 2 {
return fmt.Errorf(
"'docker model tag' requires 2 arguments.\n\n" +
"Usage: docker model tag SOURCE TARGET\n\n" +
"See 'docker model tag --help' for more information",
)
}
return nil
},
Args: requireExactArgs(2, "tag", "SOURCE TARGET"),
RunE: func(cmd *cobra.Command, args []string) error {
if _, err := ensureStandaloneRunnerAvailable(cmd.Context(), asPrinter(cmd), false); err != nil {
return fmt.Errorf("unable to initialize standalone model runner: %w", err)
Expand Down
63 changes: 63 additions & 0 deletions cmd/cli/commands/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,66 @@ func stripDefaultsFromModelName(model string) string {
// For other cases (ai/ with custom tag, custom org with :latest, etc.), keep as-is
return model
}

// requireExactArgs returns a cobra.PositionalArgs validator that ensures exactly n arguments are provided
func requireExactArgs(n int, cmdName string, usageArgs string) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error {
if len(args) != n {
return fmt.Errorf(
"'docker model %s' requires %d argument(s).\n\n"+
"Usage: docker model %s %s\n\n"+
"See 'docker model %s --help' for more information",
cmdName, n, cmdName, usageArgs, cmdName,
)
}
return nil
}
}

// requireMinArgs returns a cobra.PositionalArgs validator that ensures at least n arguments are provided
func requireMinArgs(n int, cmdName string, usageArgs string) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error {
if len(args) < n {
return fmt.Errorf(
"'docker model %s' requires at least %d argument(s).\n\n"+
"Usage: docker model %s %s\n\n"+
"See 'docker model %s --help' for more information",
cmdName, n, cmdName, usageArgs, cmdName,
)
}
return nil
}
}

// runnerOptions holds common runner configuration options
type runnerFlagOptions struct {
Port *uint16
Host *string
GpuMode *string
Backend *string
DoNotTrack *bool
Debug *bool
}

// addRunnerFlags adds common runner flags to a command
func addRunnerFlags(cmd *cobra.Command, opts runnerFlagOptions) {
if opts.Port != nil {
cmd.Flags().Uint16Var(opts.Port, "port", 0,
"Docker container port for Docker Model Runner (default: 12434 for Docker Engine, 12435 for Cloud mode)")
}
if opts.Host != nil {
cmd.Flags().StringVar(opts.Host, "host", "127.0.0.1", "Host address to bind Docker Model Runner")
}
if opts.GpuMode != nil {
cmd.Flags().StringVar(opts.GpuMode, "gpu", "auto", "Specify GPU support (none|auto|cuda|rocm|musa|cann)")
}
if opts.Backend != nil {
cmd.Flags().StringVar(opts.Backend, "backend", "", backendUsage)
}
if opts.DoNotTrack != nil {
cmd.Flags().BoolVar(opts.DoNotTrack, "do-not-track", false, "Do not track models usage in Docker Model Runner")
}
if opts.Debug != nil {
cmd.Flags().BoolVar(opts.Debug, "debug", false, "Enable debug logging")
}
}
2 changes: 1 addition & 1 deletion cmd/cli/docs/reference/docker_model_reinstall-runner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ options:
- option: gpu
value_type: string
default_value: auto
description: Specify GPU support (none|auto|cuda|musa|rocm|cann)
description: Specify GPU support (none|auto|cuda|rocm|musa|cann)
deprecated: false
hidden: false
experimental: false
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/docs/reference/docker_model_restart-runner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ options:
- option: gpu
value_type: string
default_value: auto
description: Specify GPU support (none|auto|cuda|musa|rocm|cann)
description: Specify GPU support (none|auto|cuda|rocm|musa|cann)
deprecated: false
hidden: false
experimental: false
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/docs/reference/docker_model_start-runner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ options:
- option: gpu
value_type: string
default_value: auto
description: Specify GPU support (none|auto|cuda|musa|rocm|cann)
description: Specify GPU support (none|auto|cuda|rocm|musa|cann)
deprecated: false
hidden: false
experimental: false
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/docs/reference/model_reinstall-runner.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Reinstall Docker Model Runner (Docker Engine only)
| `--backend` | `string` | | Specify backend (llama.cpp\|vllm). Default: llama.cpp |
| `--debug` | `bool` | | Enable debug logging |
| `--do-not-track` | `bool` | | Do not track models usage in Docker Model Runner |
| `--gpu` | `string` | `auto` | Specify GPU support (none\|auto\|cuda\|musa\|rocm\|cann) |
| `--gpu` | `string` | `auto` | Specify GPU support (none\|auto\|cuda\|rocm\|musa\|cann) |
| `--host` | `string` | `127.0.0.1` | Host address to bind Docker Model Runner |
| `--port` | `uint16` | `0` | Docker container port for Docker Model Runner (default: 12434 for Docker Engine, 12435 for Cloud mode) |

Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/docs/reference/model_restart-runner.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Restart Docker Model Runner (Docker Engine only)
|:-----------------|:---------|:------------|:-------------------------------------------------------------------------------------------------------|
| `--debug` | `bool` | | Enable debug logging |
| `--do-not-track` | `bool` | | Do not track models usage in Docker Model Runner |
| `--gpu` | `string` | `auto` | Specify GPU support (none\|auto\|cuda\|musa\|rocm\|cann) |
| `--gpu` | `string` | `auto` | Specify GPU support (none\|auto\|cuda\|rocm\|musa\|cann) |
| `--host` | `string` | `127.0.0.1` | Host address to bind Docker Model Runner |
| `--port` | `uint16` | `0` | Docker container port for Docker Model Runner (default: 12434 for Docker Engine, 12435 for Cloud mode) |

Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/docs/reference/model_start-runner.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Start Docker Model Runner (Docker Engine only)
| `--backend` | `string` | | Specify backend (llama.cpp\|vllm). Default: llama.cpp |
| `--debug` | `bool` | | Enable debug logging |
| `--do-not-track` | `bool` | | Do not track models usage in Docker Model Runner |
| `--gpu` | `string` | `auto` | Specify GPU support (none\|auto\|cuda\|musa\|rocm\|cann) |
| `--gpu` | `string` | `auto` | Specify GPU support (none\|auto\|cuda\|rocm\|musa\|cann) |
| `--port` | `uint16` | `0` | Docker container port for Docker Model Runner (default: 12434 for Docker Engine, 12435 for Cloud mode) |


Expand Down
19 changes: 0 additions & 19 deletions pkg/distribution/distribution/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,3 @@ var (
ErrUnsupportedFormat = errors.New("safetensors models are not currently supported - this runner only supports GGUF format models")
ErrConflict = errors.New("resource conflict")
)

// ReferenceError represents an error related to an invalid model reference
type ReferenceError struct {
Reference string
Err error
}

func (e *ReferenceError) Error() string {
return fmt.Sprintf("invalid model reference %q: %v", e.Reference, e.Err)
}

func (e *ReferenceError) Unwrap() error {
return e.Err
}

// Is implements error matching for ReferenceError
func (e *ReferenceError) Is(target error) bool {
return target == ErrInvalidReference
}
20 changes: 11 additions & 9 deletions pkg/distribution/internal/gguf/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@ func NewModel(path string) (*Model, error) {

created := time.Now()
return &Model{
configFile: types.ConfigFile{
Config: configFromFile(path),
Descriptor: types.Descriptor{
Created: &created,
},
RootFS: v1.RootFS{
Type: "rootfs",
DiffIDs: diffIDs,
BaseModel: partial.BaseModel{
ModelConfigFile: types.ConfigFile{
Config: configFromFile(path),
Descriptor: types.Descriptor{
Created: &created,
},
RootFS: v1.RootFS{
Type: "rootfs",
DiffIDs: diffIDs,
},
},
LayerList: layers,
},
layers: layers,
}, nil
}

Expand Down
Loading
Loading