Skip to content

Commit aaf52a6

Browse files
committed
Move more normalization into the model-runner backend
model-runner daemon is more well equipped to identify between model name and model id. Signed-off-by: Eric Curtin <[email protected]>
1 parent b51ca01 commit aaf52a6

File tree

16 files changed

+349
-96
lines changed

16 files changed

+349
-96
lines changed

cmd/cli/commands/compose.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,12 @@ func newUpCommand() *cobra.Command {
7575
// Build speculative config if any speculative flags are set
7676
var speculativeConfig *inference.SpeculativeDecodingConfig
7777
if draftModel != "" || numTokens > 0 || minAcceptanceRate > 0 {
78-
normalizedDraftModel := dmrm.NormalizeModelName(draftModel)
7978
speculativeConfig = &inference.SpeculativeDecodingConfig{
80-
DraftModel: normalizedDraftModel,
79+
DraftModel: draftModel,
8180
NumTokens: numTokens,
8281
MinAcceptanceRate: minAcceptanceRate,
8382
}
84-
sendInfo(fmt.Sprintf("Enabling speculative decoding with draft model: %s", normalizedDraftModel))
83+
sendInfo(fmt.Sprintf("Enabling speculative decoding with draft model: %s", draftModel))
8584
}
8685

8786
for _, model := range models {

cmd/cli/commands/configure.go

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

66
"github.com/docker/model-runner/cmd/cli/commands/completion"
77
"github.com/docker/model-runner/pkg/inference"
8-
"github.com/docker/model-runner/pkg/inference/models"
8+
99
"github.com/docker/model-runner/pkg/inference/scheduling"
1010
"github.com/spf13/cobra"
1111
)
@@ -39,15 +39,15 @@ func newConfigureCmd() *cobra.Command {
3939
argsBeforeDash)
4040
}
4141
}
42-
opts.Model = models.NormalizeModelName(args[0])
42+
opts.Model = args[0]
4343
opts.RuntimeFlags = args[1:]
4444
return nil
4545
},
4646
RunE: func(cmd *cobra.Command, args []string) error {
4747
// Build the speculative config if any speculative flags are set
4848
if draftModel != "" || numTokens > 0 || minAcceptanceRate > 0 {
4949
opts.Speculative = &inference.SpeculativeDecodingConfig{
50-
DraftModel: models.NormalizeModelName(draftModel),
50+
DraftModel: draftModel,
5151
NumTokens: numTokens,
5252
MinAcceptanceRate: minAcceptanceRate,
5353
}

cmd/cli/commands/inspect.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +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"
9+
1010
"github.com/spf13/cobra"
1111
)
1212

@@ -48,8 +48,7 @@ func newInspectCmd() *cobra.Command {
4848
}
4949

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

cmd/cli/commands/list.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,13 @@ func listModels(openai bool, desktopClient *desktop.Client, quiet bool, jsonForm
7272
}
7373

7474
if modelFilter != "" {
75-
// Normalize the filter to match stored model names
75+
// Normalize the filter to match stored model names (backend normalizes when storing)
7676
normalizedFilter := dmrm.NormalizeModelName(modelFilter)
7777
var filteredModels []dmrm.Model
7878
for _, m := range models {
7979
hasMatchingTag := false
8080
for _, tag := range m.Tags {
81+
// Tags are stored in normalized format by the backend
8182
if tag == normalizedFilter {
8283
hasMatchingTag = true
8384
break

cmd/cli/commands/package.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/docker/model-runner/pkg/distribution/registry"
1717
"github.com/docker/model-runner/pkg/distribution/tarball"
1818
"github.com/docker/model-runner/pkg/distribution/types"
19-
"github.com/docker/model-runner/pkg/inference/models"
19+
2020
"github.com/google/go-containerregistry/pkg/name"
2121
"github.com/spf13/cobra"
2222

@@ -325,6 +325,7 @@ func packageModel(cmd *cobra.Command, opts packageOptions) error {
325325
}
326326

327327
cmd.PrintErrln("Model variant created successfully")
328+
return nil // Return early to avoid the Build operation in lightweight case
328329
} else {
329330
// Process directory tar archives
330331
if len(opts.dirTarPaths) > 0 {
@@ -412,9 +413,7 @@ func newModelRunnerTarget(client *desktop.Client, tag string) (*modelRunnerTarge
412413
}
413414
if tag != "" {
414415
var err error
415-
// Normalize the tag to add default namespace (ai/) and tag (:latest) if missing
416-
normalizedTag := models.NormalizeModelName(tag)
417-
target.tag, err = name.NewTag(normalizedTag)
416+
target.tag, err = name.NewTag(tag)
418417
if err != nil {
419418
return nil, fmt.Errorf("invalid tag: %w", err)
420419
}

cmd/cli/commands/pull.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +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"
9+
1010
"github.com/mattn/go-isatty"
1111
"github.com/spf13/cobra"
1212
)
@@ -42,8 +42,6 @@ func newPullCmd() *cobra.Command {
4242
}
4343

4444
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)
4745
var progress func(string)
4846
if isatty.IsTerminal(os.Stdout.Fd()) {
4947
progress = TUIProgress

cmd/cli/commands/push.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +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"
8+
99
"github.com/spf13/cobra"
1010
)
1111

@@ -35,8 +35,6 @@ func newPushCmd() *cobra.Command {
3535
}
3636

3737
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)
4038
response, progressShown, err := desktopClient.Push(model, TUIProgress)
4139

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

cmd/cli/commands/rm.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +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"
7+
88
"github.com/spf13/cobra"
99
)
1010

@@ -28,12 +28,7 @@ func newRemoveCmd() *cobra.Command {
2828
if _, err := ensureStandaloneRunnerAvailable(cmd.Context(), cmd); err != nil {
2929
return fmt.Errorf("unable to initialize standalone model runner: %w", err)
3030
}
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)
31+
response, err := desktopClient.Remove(args, force)
3732
if response != "" {
3833
cmd.Print(response)
3934
}

cmd/cli/commands/run.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +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"
18+
1919
"github.com/fatih/color"
2020
"github.com/spf13/cobra"
2121
"golang.org/x/term"
@@ -586,8 +586,7 @@ func newRunCmd() *cobra.Command {
586586
}
587587
},
588588
RunE: func(cmd *cobra.Command, args []string) error {
589-
// Normalize model name to add default org and tag if missing
590-
model := models.NormalizeModelName(args[0])
589+
model := args[0]
591590
prompt := ""
592591
argsLen := len(args)
593592
if argsLen > 1 {

cmd/cli/commands/tag.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +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"
9+
1010
"github.com/google/go-containerregistry/pkg/name"
1111
"github.com/spf13/cobra"
1212
)
@@ -37,10 +37,6 @@ func newTagCmd() *cobra.Command {
3737
}
3838

3939
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-
// Normalize target model name to add default org and tag if missing
43-
target = models.NormalizeModelName(target)
4440
// Ensure tag is valid
4541
tag, err := name.NewTag(target)
4642
if err != nil {

0 commit comments

Comments
 (0)