-
Notifications
You must be signed in to change notification settings - Fork 51
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
feat: support vllm in controller #635
Open
zhuangqh
wants to merge
2
commits into
main
Choose a base branch
from
controller-support-vllm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ package model | |
|
||
import ( | ||
"time" | ||
|
||
"github.com/kaito-project/kaito/pkg/utils" | ||
) | ||
|
||
type Model interface { | ||
|
@@ -13,23 +15,141 @@ type Model interface { | |
SupportTuning() bool | ||
} | ||
|
||
// RuntimeName is LLM runtime name. | ||
type RuntimeName string | ||
|
||
const ( | ||
RuntimeNameHuggingfaceTransformers RuntimeName = "transformers" | ||
RuntimeNameVLLM RuntimeName = "vllm" | ||
|
||
InferenceFileHuggingface = "/workspace/tfs/inference_api.py" | ||
InferenceFileVLLM = "/workspace/vllm/inference_api.py" | ||
) | ||
|
||
// PresetParam defines the preset inference parameters for a model. | ||
type PresetParam struct { | ||
ModelFamilyName string // The name of the model family. | ||
ImageAccessMode string // Defines where the Image is Public or Private. | ||
DiskStorageRequirement string // Disk storage requirements for the model. | ||
GPUCountRequirement string // Number of GPUs required for the Preset. Used for inference. | ||
TotalGPUMemoryRequirement string // Total GPU memory required for the Preset. Used for inference. | ||
PerGPUMemoryRequirement string // GPU memory required per GPU. Used for inference. | ||
TuningPerGPUMemoryRequirement map[string]int // Min GPU memory per tuning method (batch size 1). Used for tuning. | ||
TorchRunParams map[string]string // Parameters for configuring the torchrun command. | ||
TorchRunRdzvParams map[string]string // Optional rendezvous parameters for distributed training/inference using torchrun (elastic). | ||
BaseCommand string // The initial command (e.g., 'torchrun', 'accelerate launch') used in the command line. | ||
ModelRunParams map[string]string // Parameters for running the model training/inference. | ||
Tag string // The model image tag | ||
ModelFamilyName string // The name of the model family. | ||
ImageAccessMode string // Defines where the Image is Public or Private. | ||
|
||
DiskStorageRequirement string // Disk storage requirements for the model. | ||
GPUCountRequirement string // Number of GPUs required for the Preset. Used for inference. | ||
TotalGPUMemoryRequirement string // Total GPU memory required for the Preset. Used for inference. | ||
PerGPUMemoryRequirement string // GPU memory required per GPU. Used for inference. | ||
TuningPerGPUMemoryRequirement map[string]int // Min GPU memory per tuning method (batch size 1). Used for tuning. | ||
WorldSize int // Defines the number of processes required for distributed inference. | ||
|
||
RuntimeParam | ||
|
||
// ReadinessTimeout defines the maximum duration for creating the workload. | ||
// This timeout accommodates the size of the image, ensuring pull completion | ||
// even under slower network conditions or unforeseen delays. | ||
ReadinessTimeout time.Duration | ||
WorldSize int // Defines the number of processes required for distributed inference. | ||
Tag string // The model image tag | ||
} | ||
|
||
// RuntimeParam defines the llm runtime parameters. | ||
type RuntimeParam struct { | ||
Transformers HuggingfaceTransformersParam | ||
VLLM VLLMParam | ||
} | ||
|
||
type HuggingfaceTransformersParam struct { | ||
BaseCommand string // The initial command (e.g., 'torchrun', 'accelerate launch') used in the command line. | ||
TorchRunParams map[string]string // Parameters for configuring the torchrun command. | ||
TorchRunRdzvParams map[string]string // Optional rendezvous parameters for distributed training/inference using torchrun (elastic). | ||
ModelRunParams map[string]string // Parameters for running the model training/inference. | ||
} | ||
|
||
type VLLMParam struct { | ||
BaseCommand string | ||
// The model name used in the openai serving API. | ||
// see https://platform.openai.com/docs/api-reference/chat/create#chat-create-model. | ||
ModelName string | ||
// Parameters for distributed inference. | ||
DistributionParams map[string]string | ||
// Parameters for running the model training/inference. | ||
ModelRunParams map[string]string | ||
} | ||
|
||
func (p *PresetParam) DeepCopy() *PresetParam { | ||
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. we may update some params according to the node counts. Thus, we must deepcopy it at first. |
||
if p == nil { | ||
return nil | ||
} | ||
out := new(PresetParam) | ||
*out = *p | ||
out.RuntimeParam = p.RuntimeParam.DeepCopy() | ||
out.TuningPerGPUMemoryRequirement = make(map[string]int, len(p.TuningPerGPUMemoryRequirement)) | ||
for k, v := range p.TuningPerGPUMemoryRequirement { | ||
out.TuningPerGPUMemoryRequirement[k] = v | ||
} | ||
return out | ||
} | ||
|
||
func (rp *RuntimeParam) DeepCopy() RuntimeParam { | ||
if rp == nil { | ||
return RuntimeParam{} | ||
} | ||
out := RuntimeParam{} | ||
out.Transformers = rp.Transformers.DeepCopy() | ||
out.VLLM = rp.VLLM.DeepCopy() | ||
return out | ||
} | ||
|
||
func (h *HuggingfaceTransformersParam) DeepCopy() HuggingfaceTransformersParam { | ||
if h == nil { | ||
return HuggingfaceTransformersParam{} | ||
} | ||
out := HuggingfaceTransformersParam{} | ||
out.BaseCommand = h.BaseCommand | ||
out.TorchRunParams = make(map[string]string, len(h.TorchRunParams)) | ||
for k, v := range h.TorchRunParams { | ||
out.TorchRunParams[k] = v | ||
} | ||
out.TorchRunRdzvParams = make(map[string]string, len(h.TorchRunRdzvParams)) | ||
for k, v := range h.TorchRunRdzvParams { | ||
out.TorchRunRdzvParams[k] = v | ||
} | ||
out.ModelRunParams = make(map[string]string, len(h.ModelRunParams)) | ||
for k, v := range h.ModelRunParams { | ||
out.ModelRunParams[k] = v | ||
} | ||
return out | ||
} | ||
|
||
func (v *VLLMParam) DeepCopy() VLLMParam { | ||
if v == nil { | ||
return VLLMParam{} | ||
} | ||
out := VLLMParam{} | ||
out.BaseCommand = v.BaseCommand | ||
out.ModelName = v.ModelName | ||
out.DistributionParams = make(map[string]string, len(v.DistributionParams)) | ||
for k, v := range v.DistributionParams { | ||
out.DistributionParams[k] = v | ||
} | ||
out.ModelRunParams = make(map[string]string, len(v.ModelRunParams)) | ||
for k, v := range v.ModelRunParams { | ||
out.ModelRunParams[k] = v | ||
} | ||
return out | ||
} | ||
|
||
// builds the container command: | ||
// eg. torchrun <TORCH_PARAMS> <OPTIONAL_RDZV_PARAMS> baseCommand <MODEL_PARAMS> | ||
func (p *PresetParam) GetInferenceCommand(runtime RuntimeName, skuNumGPUs string) []string { | ||
switch runtime { | ||
case RuntimeNameHuggingfaceTransformers: | ||
torchCommand := utils.BuildCmdStr(p.Transformers.BaseCommand, p.Transformers.TorchRunParams, p.Transformers.TorchRunRdzvParams) | ||
modelCommand := utils.BuildCmdStr(InferenceFileHuggingface, p.Transformers.ModelRunParams) | ||
return utils.ShellCmd(torchCommand + " " + modelCommand) | ||
case RuntimeNameVLLM: | ||
if p.VLLM.ModelName != "" { | ||
p.VLLM.ModelRunParams["served-model-name"] = p.VLLM.ModelName | ||
} | ||
p.VLLM.ModelRunParams["tensor-parallel-size"] = skuNumGPUs | ||
modelCommand := utils.BuildCmdStr(InferenceFileVLLM, p.VLLM.ModelRunParams) | ||
return utils.ShellCmd(p.VLLM.BaseCommand + " " + modelCommand) | ||
default: | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this tag field get used