-
Notifications
You must be signed in to change notification settings - Fork 85
Respect context size from model config #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| package llamacpp | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "runtime" | ||
| "strconv" | ||
|
|
||
| "github.com/docker/model-distribution/types" | ||
| "github.com/docker/model-runner/pkg/inference" | ||
| ) | ||
|
|
||
|
|
@@ -33,10 +35,20 @@ func NewDefaultLlamaCppConfig() *Config { | |
| } | ||
|
|
||
| // GetArgs implements BackendConfig.GetArgs. | ||
| func (c *Config) GetArgs(modelPath, socket string, mode inference.BackendMode) []string { | ||
| func (c *Config) GetArgs(model types.Model, socket string, mode inference.BackendMode, config *inference.BackendConfiguration) ([]string, error) { | ||
| // Start with the arguments from LlamaCppConfig | ||
| args := append([]string{}, c.Args...) | ||
|
|
||
| modelPath, err := model.GGUFPath() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("get gguf path: %v", err) | ||
ekcasey marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| modelCfg, err := model.Config() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("get model config: %v", err) | ||
ekcasey marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // Add model and socket arguments | ||
| args = append(args, "--model", modelPath, "--host", socket) | ||
|
|
||
|
|
@@ -45,7 +57,20 @@ func (c *Config) GetArgs(modelPath, socket string, mode inference.BackendMode) [ | |
| args = append(args, "--embeddings") | ||
| } | ||
|
|
||
| return args | ||
| // Add arguments from model config | ||
| if modelCfg.ContextSize != nil { | ||
| args = append(args, "--ctx-size", strconv.FormatUint(*modelCfg.ContextSize, 10)) | ||
| } | ||
|
|
||
| // Add arguments from backend config | ||
| if config != nil { | ||
| if config.ContextSize > 0 && !containsArg(args, "--ctx-size") { | ||
| args = append(args, "--ctx-size", fmt.Sprintf("%d", config.ContextSize)) | ||
| } | ||
| args = append(args, config.RuntimeFlags...) | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would unify the number-to-string conversion;
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, roger that. |
||
|
|
||
| return args, nil | ||
| } | ||
|
|
||
| // containsArg checks if the given argument is already in the args slice. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.