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

Design for serving models with different backends - #81

Merged
mairin merged 1 commit into
instructlab:mainfrom
alimaredia:ilab-model-serve
Jun 21, 2024
Merged

Design for serving models with different backends#81
mairin merged 1 commit into
instructlab:mainfrom
alimaredia:ilab-model-serve

Conversation

@alimaredia

@alimaredia alimaredia commented Jun 7, 2024

Copy link
Copy Markdown
Contributor

This commit introduces a new design document for the [ilab model serve] command, detailing its
functionality to serve models using different backends, specifically
llama-cpp and vllm. It outlines the command structure, including
backend-specific flags and arguments, and proposes a testing strategy
for new engine integrations.

Co-authored-by: Sébastien Han seb@redhat.com
Signed-off-by: Ali Maredia amaredia@redhat.com

@leseb leseb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for working on this proposal! I envision an ideal scenario where we can determine the appropriate backend solely based on the model input (directory or file). I'm questioning whether this is something users really need to worry about. If we can alleviate this hassle, I believe we should.

Comment thread docs/cli/ilab-model-serve.md Outdated
Comment thread docs/cli/ilab-model-serve.md Outdated
### Llama-cpp backend specific commands

```shell
ilab model serve llama-cpp --model <PATH> --llama-cpp-gpu-layers 4 --llama-cpp-max-ctx-size 1024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A point I've raised before, I'm not sure if it makes sense to prefix everything with --llama-cpp if we know we are using the llama-cpp backend.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The reason I made it so specific is that I'm scarred by the flags for training that exist in the codebase as of 6/7/24. It's not clear which training flags belong with the mac implementation of training vs the linux implementation and on top of that the flags are very similar.

An example of how the flags could be mixed up. Current ilab serve with llama-cpp has a flag for max-ctx-size. vllm has a flag for model context length called --max-model-len (https://docs.vllm.ai/en/latest/serving/openai_compatible_server.html#command-line-arguments-for-the-server).

We could do the following possibilities:

  1. Have a flag for --max-model-len and --max-ctx-size similar to how we have it in current ilab train. I think this option is hardest on the user.

  2. Have one flag for context size called --max-ctx-size whose value is filtered down to each backend. An issue then becomes what do you do with flags that one backend has that one doesn't. Also you've now added this flag into the set of flags that both backends can use.

In my current design I propose we make backend agnostic flags those flags have nothing to do with the configuration of the backend itself and more for the configuration of ilab and what the backends are operating on (like the model path).

  1. Prefix all flags related to a backend with the backend name. I think this is the most clear for the users with the downside that it's more verbose.

@cdoern what do you think about how the flags for training might look. Training will have a similar set of possible subcommands with numerous options.

@n1hility n1hility Jun 7, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In my current design I propose we make backend agnostic flags those flags have nothing to do with the configuration of the backend itself and more for the configuration of ilab and what the backends are operating on (like the model path).

+1 this is the right approach to create and use generic flags yet still have a mechanism for provider specific flags. I also liked how in your draft PR you had a generic --vllm-args concept in there where it's just a passthrough.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think provider specific flags are a good idea from a UX pov because it means naturally users won't try to apply a flag specific to one backend to another. (Again thinking of my ffmpeg nightmares ;-) )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm open to building generic flags, but it feels like we're creating a third layer of abstraction, which might introduce some ambiguity. Users will have to juggle raw flags from llama-cpp, as well as flags from ilab, which could complicate their mental model when writing commands. However, I do like the idea of re-using sensible flags and handling the backend mapping internally.

In the end, we could adopt two strategies:

  • Backend-Agnostic Flags: Select the most common flags that make sense across multiple backends.
  • Backend-Specific Flags: Use --vllm-args (or similar) for backend-specific configurations.

There might still be issues, such as someone passing ilab model serve --backend llama-cpp --llama-cpp-max-ctx-size 1 --llama-cpp-args "llama-cpp-max-ctx-size 2". However, we can address this through proper validation and error messaging.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

After doing some more research I'm removing the backend specific prefixes from the backend specific flags. The way we're using click for subcommands, flags between backends cannot be shared.

So running ilab model serve vllm --help would yield a different message than ilab model serve --help and ilab model serve llama-cpp --help.

For this reason I'm not worried about users mixing up arguments as long as there are subcommands.

This is another reason why I believe going subcommands instead of having a --backend flag to choose the backend.

Comment thread docs/cli/ilab-model-serve.md Outdated
Comment thread docs/cli/ilab-model-serve.md Outdated
Comment thread docs/cli/ilab-model-serve.md Outdated
Comment thread docs/cli/ilab-model-serve.md Outdated
Comment thread docs/cli/ilab-model-serve.md Outdated
Comment thread docs/cli/ilab-model-serve.md Outdated
Comment thread docs/cli/ilab-model-serve.md Outdated
### Llama-cpp backend specific commands

```shell
ilab model serve llama-cpp --model <PATH> --llama-cpp-gpu-layers 4 --llama-cpp-max-ctx-size 1024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think provider specific flags are a good idea from a UX pov because it means naturally users won't try to apply a flag specific to one backend to another. (Again thinking of my ffmpeg nightmares ;-) )

Comment thread docs/cli/ilab-model-serve.md Outdated
Comment thread docs/cli/ilab-model-serve.md Outdated
Comment thread docs/cli/ilab-model-serve.md Outdated
Comment thread docs/cli/ilab-model-serve.md Outdated
Comment thread docs/cli/ilab-model-serve.md Outdated
leseb
leseb previously requested changes Jun 12, 2024
Comment thread docs/cli/ilab-model-serve.md Outdated
@leseb
leseb requested a review from xukai92 June 12, 2024 07:43

@markstur markstur left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

comments inline

Comment thread docs/cli/ilab-model-serve.md Outdated
Comment thread docs/cli/ilab-model-serve.md Outdated

@russellb russellb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I left some minor comments.

It seems the only thing blocking this is whether backend is a positional argument or a flag.

If it was clear we’d have a bunch of backend specific options, I’d lean toward a positional argument to explicitly separate the set of options for each backend.

It seems the doc proposes a generic pass through “—vllm-args” so it seems like differences will be minimal and clear enough.

If I had to pick I’d go with the flag but I’m supportive of either one. We just need to resolve this quickly so implementation can proceed.

Comment thread docs/cli/ilab-model-serve.md Outdated
Comment thread docs/cli/ilab-model-serve.md Outdated
Comment thread docs/cli/ilab-model-serve.md Outdated
Comment thread docs/cli/ilab-model-serve.md Outdated
@n1hility
n1hility self-requested a review June 19, 2024 04:55

@n1hility n1hility left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Temp requesting changes just to verify the backend vs subcommand discussion

@leseb
leseb force-pushed the ilab-model-serve branch from 6871398 to 3ab25a0 Compare June 19, 2024 12:23
@leseb
leseb requested review from markstur, n1hility and russellb June 19, 2024 12:23
@leseb
leseb force-pushed the ilab-model-serve branch 2 times, most recently from 0f87719 to a348dc5 Compare June 19, 2024 12:38
@leseb
leseb force-pushed the ilab-model-serve branch from bfe5949 to 51048f1 Compare June 19, 2024 13:33

@russellb russellb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm good with the direction in general, though I have some comments on the syntax of the --backend-args option.

Comment thread docs/cli/ilab-model-serve-backend.md Outdated
Comment thread docs/cli/ilab-model-serve-backend.md Outdated
@leseb
leseb force-pushed the ilab-model-serve branch from 51048f1 to 264274a Compare June 19, 2024 14:28
@leseb
leseb self-requested a review June 19, 2024 19:11
@alimaredia

alimaredia commented Jun 19, 2024

Copy link
Copy Markdown
Contributor Author

@leseb @russellb @n1hility @mairin Thanks for moving this forward., I think --backend-args is very simple and a way forward.

One question I have is do we need to be able to provide the ability to turn all of the knobs in the CLI that we could in a config file? AKA does every parameter need the ability to be set in the config and on the CLI?

I'm guessing the answer is yes, but if that's not that case why don't we just have:

  1. Backend agnostic flags: ex --model
  2. A flag to specify the backend --backend
  3. A flag to specify the config file --config. We have docs for all of the config file options for each backend, and populate all values in the serve section via the config we generate with ilab config init.

At least with this approach there would be one source of truth, the implementation would be clean and simple, and we would not be passing and parsing flags within flags. I've never seen another project with flags similar to my original --vllm-args flag, or as the all encompassing --backend-args flag. I know it's simple, but my initial reaction is that it seems strange to pass flags within flags.

@mairin

mairin commented Jun 19, 2024 via email

Copy link
Copy Markdown
Contributor

@alimaredia

Copy link
Copy Markdown
Contributor Author

The other thing I would say, is just passing the config file might make the world simpler if we we do default config setting with profiles like @cdoern has proposed. The user would only have to focus their attention on the config file. Charlie if you have any thoughts, please chime in.

@leseb

leseb commented Jun 20, 2024

Copy link
Copy Markdown
Contributor

@alimaredia @mairin @n1hility @russellb, I'd like to hold off on discussing --backend-args until we have more people present. However, it seems we all agree on introducing a new --backend option. Can I get a confirmation on this? All my progress is stuck based on this single decision, and I have several PRs to submit. I'd like to make headway before I go away next week.

Much appreciated.

@n1hility

n1hility commented Jun 20, 2024

Copy link
Copy Markdown
Contributor

@alimaredia @mairin @n1hility @russellb, I'd like to hold off on discussing --backend-args until we have more people present. However, it seems we all agree on introducing a new --backend option. Can I get a confirmation on this? All my progress is stuck based on this single decision, and I have several PRs to submit. I'd like to make headway before I go away next week.

Much appreciated.

Sure but what we merge needs to reflect what we have consensus on. So to defer the backend args we need to revise the text from being a requirement to being informative.

This commit introduces a new design document for the [`ilab model
serve`] command, detailing its
functionality to serve models using different backends, specifically
`llama-cpp` and `vllm`. It outlines the command structure, including
backend-specific flags and arguments, and proposes a testing strategy
for new engine integrations.

Co-authored-by: Sébastien Han <seb@redhat.com>
Co-authored-by: Jason Greene <jason.greene@redhat.com>
Signed-off-by: Ali Maredia <amaredia@redhat.com>
@n1hility
n1hility dismissed stale reviews from leseb and russellb June 21, 2024 04:53

leseb supports the changes

@mairin

mairin commented Jun 21, 2024

Copy link
Copy Markdown
Contributor

I won't hold anything up but I don't agree with making --backend a flag. I have read back through comments here several times and do not see a rationale for this change. I think it is important to understand why we are going from subcommand to flag, as the subcommand approach was discussed extensively in brainstorming this devdoc and reviewed verbally with multiple folks - even rhtdan felt it was the way to go. I would feel better if I understood why we are going to a flag from a subcommand.

My core concern is from the user experience end. The user experience for this project is incredibly important and if we can have a delightful one it will be a differentiator. However, I am not considering other things like what limitations click might have.

I think having --backendargs as a catch all and starting with that for the implemetation is a great idea

Again, I will not hold this one up bc we need to complete this and have smtg working and that is the most important.

@leseb

leseb commented Jun 21, 2024

Copy link
Copy Markdown
Contributor

Since some of the comments are not visible anymore after a push, I'd like to summarize why using a ilab model serve --backend flag is more appropriate than a positional argument like ilab model serve <backend>:

  • Flexibility: Adding new backends or other options becomes more intuitive and consistent when using flags. It avoids the rigidity of positional arguments, making future expansions or modifications seamless. The flag --backend could be ported to other commands later (chat? generate) if we determine it makes sense.

  • Consistency: Following a common pattern in CLI design where options are specified with flags ensures uniformity. This approach is clearer and more extendable, aligning with widely accepted CLI design principles.

  • Clarity: Using --backend makes it immediately apparent that this is an option, enhancing the self-explanatory nature of the command. Users can quickly understand the command's structure and purpose. Also "Flags" signify optional parameters, aligning with the backend's nature as an auto-detected feature. Positional arguments typically indicate required inputs, which could confuse users about the backend's necessity. So the --backend flag help delineate optional from required parameters more effectively.

  • Behavioral Context: Optional parameters, such as --backend, alter the program's behavior without being mandatory. This distinction is better communicated through flags, enhancing user comprehension.

As a side note: I'd argue that the only parameter that should be positional is the model path, as it's essential.

I'd to reference the guide from CLIG.dev:

Prefer flags to args. It’s a bit more typing, but it makes it much clearer what is going on. It also makes it easier to make changes to how you accept input in the future. Sometimes when using args, it’s impossible to add new input without breaking existing behavior or creating ambiguity.

In conclusion, using --backend for the backend ensures flexibility, consistency, clarity, better integration, and aligns with best practices for CLI design.

Thanks!

@mairin I hope this will change your mind :). Are you keeping your request change to express your disagreement with the latest proposal? I'm seeking clarification because your last comment said you won't hold this up. I'm fine if you want to keep it and have someone else merge if this gets other approvals.

@leseb
leseb requested a review from russellb June 21, 2024 12:12
@mairin

mairin commented Jun 21, 2024

Copy link
Copy Markdown
Contributor

Sébastien and I had a call this morning and I am on board with this design now. The rationale had been squashed and he posted it above, and I also misunderstood part of how the flag was proposed to work. I am on board with this now. My main concern was making sure users do not try to use on set of arguments they learned to use with llamacpp and try to xfer them to a vllm or other backend and have a poor experience. Some things we discussed is capturing when that happens and erroring out gracefully, or letting the user know it won't work if we can detect that's going on (with an out to override and try it anyway), and also giving suggesting based on what the argument for backend A is with the equivalent argument for backend B.

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.

6 participants