Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.

Conversation

@xenoscopic
Copy link
Contributor

@xenoscopic xenoscopic commented Jun 26, 2025

This PR adds a docker model configure command that can set runtime configuration for a model. Right now it uses the -- terminator convention to delineate runtime flags.

This supports the new models: spec in Compose.

This requires an update to the github.com/docker/model-runner dep, hence the large dependency updates; this update includes docker/model-runner#95, so I've opened it in draft for now until we can get that (and anything else we want) into main in that repo (and then do a final go mod update).

@xenoscopic xenoscopic requested review from a team and ndeloof June 26, 2025 22:56
var opts scheduling.ConfigureRequest

c := &cobra.Command{
Use: "configure [--context-size=<n>] MODEL [-- <runtime-flags...>]",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need -- here? As model is a required argument, everything after could be considered runtime flags (comparable to docker run IMAGE <command...>

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need it so we can pass runtime flags that start with -- so they're not treated as flags for the configure command itself.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. docker run doesn't require this and I can't see any magic code for this purpose on https://github.com/docker/cli/blob/master/cli/command/container/run.go#L36

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but the command doesn't usually contain "--" so it's parsed as a flag.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not:

$ docker run alpine/curl --help
Usage: curl [options...] <url>
 -d, --data <data>           HTTP POST data
...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, nice! Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the -- terminator is a de facto standard (in GNU getopt, Cobra, Argparse, etc.) indicating the end of flag parsing, let's go with it for now and then we can potentially make it optional in the future (see, e.g., git help log, where -- is recommended but optional in certain cases).

This will give us the most flexibility later to evolve the command (e.g. supporting multiple model specifications), because honestly this command is being added with a little less design time than we'd ideally like.

For now though, it's the most unambiguous option and doesn't risk breaking in the future since it's a multi-decade convention.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you declare this command with this syntax this will have to stay forever, otherwise Compose integration will be broken

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with it staying forever, it's been in use as a parsing convention for several decades now and it's baked into the APIs and CLIs of many libraries and tools. In git for example, anything taking arbitrary pathspecs uses a -- convention (because that's the GNU convention for arbitrary args). It doesn't cost anything to support it and there's no risk of support for it being removed from argument parsing libraries.

If we didn't use it though, we wouldn't have any way to (in the future) support an arbitrary number of model specs (because we'd have no way of knowing when the model specs ended and the runtime flags began). So I think leaning into the standard here gives us more flexibility with the command design. Doing a clever parsing heuristic now would give us far less flexibility in the other direction.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok makes sense

)
}
opts.Model = args[0]
opts.RuntimeFlags = args[1:]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-- will be part of the sub-slice

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't, it's parsed and excluded automatically by cobra.

Args: func(cmd *cobra.Command, args []string) error {
argsBeforeDash := cmd.ArgsLenAtDash()
if argsBeforeDash == -1 {
// No "--" used, so we need exactly 1 total argument.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flags are not included, they're not counted.

@xenoscopic xenoscopic marked this pull request as ready for review June 27, 2025 15:08
@xenoscopic xenoscopic merged commit 2759382 into main Jun 27, 2025
6 checks passed
@xenoscopic xenoscopic deleted the configure-command branch June 27, 2025 15:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants