Skip to content

Commit 92acddb

Browse files
committed
Add model name normalization and display stripping
Add normalization to configure, list, and unload commands Signed-off-by: Eric Curtin <[email protected]>
1 parent abad2d8 commit 92acddb

File tree

16 files changed

+315
-38
lines changed

16 files changed

+315
-38
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ vendor/
1515
# model-distribution
1616
pkg/distribution/bin/
1717
/parallelget
18+
/cli

cmd/cli/commands/configure.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55

66
"github.com/docker/model-runner/cmd/cli/commands/completion"
7+
"github.com/docker/model-runner/pkg/inference/models"
78
"github.com/docker/model-runner/pkg/inference/scheduling"
89
"github.com/spf13/cobra"
910
)
@@ -33,7 +34,7 @@ func newConfigureCmd() *cobra.Command {
3334
argsBeforeDash)
3435
}
3536
}
36-
opts.Model = args[0]
37+
opts.Model = models.NormalizeModelName(args[0])
3738
opts.RuntimeFlags = args[1:]
3839
return nil
3940
},

cmd/cli/commands/inspect.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/docker/model-runner/cmd/cli/commands/completion"
77
"github.com/docker/model-runner/cmd/cli/commands/formatter"
88
"github.com/docker/model-runner/cmd/cli/desktop"
9+
"github.com/docker/model-runner/pkg/inference/models"
910
"github.com/spf13/cobra"
1011
)
1112

@@ -47,7 +48,8 @@ func newInspectCmd() *cobra.Command {
4748
}
4849

4950
func inspectModel(args []string, openai bool, remote bool, desktopClient *desktop.Client) (string, error) {
50-
modelName := args[0]
51+
// Normalize model name to add default org and tag if missing
52+
modelName := models.NormalizeModelName(args[0])
5153
if openai {
5254
model, err := desktopClient.InspectOpenAI(modelName)
5355
if err != nil {

cmd/cli/commands/list.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"fmt"
66
"os"
7-
"slices"
87
"strings"
98
"time"
109

@@ -89,12 +88,20 @@ func listModels(openai bool, backend string, desktopClient *desktop.Client, quie
8988
}
9089

9190
if modelFilter != "" {
91+
// Normalize the filter to match stored model names
92+
normalizedFilter := dmrm.NormalizeModelName(modelFilter)
9293
var filteredModels []dmrm.Model
9394
for _, m := range models {
9495
hasMatchingTag := false
9596
for _, tag := range m.Tags {
97+
if tag == normalizedFilter {
98+
hasMatchingTag = true
99+
break
100+
}
101+
// Also check without the tag part
96102
modelName, _, _ := strings.Cut(tag, ":")
97-
if slices.Contains([]string{modelName, tag + ":latest", tag}, modelFilter) {
103+
filterName, _, _ := strings.Cut(normalizedFilter, ":")
104+
if modelName == filterName {
98105
hasMatchingTag = true
99106
break
100107
}
@@ -165,8 +172,10 @@ func appendRow(table *tablewriter.Table, tag string, model dmrm.Model) {
165172
fmt.Fprintf(os.Stderr, "invalid model ID for model: %v\n", model)
166173
return
167174
}
175+
// Strip default "ai/" prefix and ":latest" tag for display
176+
displayTag := stripDefaultsFromModelName(tag)
168177
table.Append([]string{
169-
tag,
178+
displayTag,
170179
model.Config.Parameters,
171180
model.Config.Quantization,
172181
model.Config.Architecture,

cmd/cli/commands/ps.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ func psTable(ps []desktop.BackendStatus) string {
5454
modelName := status.ModelName
5555
if strings.HasPrefix(modelName, "sha256:") {
5656
modelName = modelName[7:19]
57+
} else {
58+
// Strip default "ai/" prefix and ":latest" tag for display
59+
modelName = stripDefaultsFromModelName(modelName)
5760
}
5861
table.Append([]string{
5962
modelName,

cmd/cli/commands/pull.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/docker/model-runner/cmd/cli/commands/completion"
88
"github.com/docker/model-runner/cmd/cli/desktop"
9+
"github.com/docker/model-runner/pkg/inference/models"
910
"github.com/mattn/go-isatty"
1011
"github.com/spf13/cobra"
1112
)
@@ -41,6 +42,9 @@ func newPullCmd() *cobra.Command {
4142
}
4243

4344
func pullModel(cmd *cobra.Command, desktopClient *desktop.Client, model string, ignoreRuntimeMemoryCheck bool) error {
45+
// Normalize model name to add default org and tag if missing
46+
model = models.NormalizeModelName(model)
47+
4448
var progress func(string)
4549
if isatty.IsTerminal(os.Stdout.Fd()) {
4650
progress = TUIProgress

cmd/cli/commands/push.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/docker/model-runner/cmd/cli/commands/completion"
77
"github.com/docker/model-runner/cmd/cli/desktop"
8+
"github.com/docker/model-runner/pkg/inference/models"
89
"github.com/spf13/cobra"
910
)
1011

@@ -34,6 +35,9 @@ func newPushCmd() *cobra.Command {
3435
}
3536

3637
func pushModel(cmd *cobra.Command, desktopClient *desktop.Client, model string) error {
38+
// Normalize model name to add default org and tag if missing
39+
model = models.NormalizeModelName(model)
40+
3741
response, progressShown, err := desktopClient.Push(model, TUIProgress)
3842

3943
// Add a newline before any output (success or error) if progress was shown.

cmd/cli/commands/rm.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55

66
"github.com/docker/model-runner/cmd/cli/commands/completion"
7+
"github.com/docker/model-runner/pkg/inference/models"
78
"github.com/spf13/cobra"
89
)
910

@@ -27,7 +28,12 @@ func newRemoveCmd() *cobra.Command {
2728
if _, err := ensureStandaloneRunnerAvailable(cmd.Context(), cmd); err != nil {
2829
return fmt.Errorf("unable to initialize standalone model runner: %w", err)
2930
}
30-
response, err := desktopClient.Remove(args, force)
31+
// Normalize model names to add default org and tag if missing
32+
normalizedArgs := make([]string, len(args))
33+
for i, arg := range args {
34+
normalizedArgs[i] = models.NormalizeModelName(arg)
35+
}
36+
response, err := desktopClient.Remove(normalizedArgs, force)
3137
if response != "" {
3238
cmd.Print(response)
3339
}

cmd/cli/commands/run.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/docker/model-runner/cmd/cli/commands/completion"
1616
"github.com/docker/model-runner/cmd/cli/desktop"
1717
"github.com/docker/model-runner/cmd/cli/readline"
18+
"github.com/docker/model-runner/pkg/inference/models"
1819
"github.com/fatih/color"
1920
"github.com/spf13/cobra"
2021
"golang.org/x/term"
@@ -561,7 +562,8 @@ func newRunCmd() *cobra.Command {
561562
return err
562563
}
563564

564-
model := args[0]
565+
// Normalize model name to add default org and tag if missing
566+
model := models.NormalizeModelName(args[0])
565567
prompt := ""
566568
argsLen := len(args)
567569
if argsLen > 1 {

cmd/cli/commands/tag.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/docker/model-runner/cmd/cli/commands/completion"
88
"github.com/docker/model-runner/cmd/cli/desktop"
9+
"github.com/docker/model-runner/pkg/inference/models"
910
"github.com/google/go-containerregistry/pkg/name"
1011
"github.com/spf13/cobra"
1112
)
@@ -36,6 +37,9 @@ func newTagCmd() *cobra.Command {
3637
}
3738

3839
func tagModel(cmd *cobra.Command, desktopClient *desktop.Client, source, target string) error {
40+
// Normalize source model name to add default org and tag if missing
41+
source = models.NormalizeModelName(source)
42+
3943
// Ensure tag is valid
4044
tag, err := name.NewTag(target)
4145
if err != nil {

0 commit comments

Comments
 (0)