-
Notifications
You must be signed in to change notification settings - Fork 84
feature: Kthena runtime adaptation for sglang #812
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -17,7 +17,10 @@ limitations under the License. | |||||
| package sglang | ||||||
|
|
||||||
| import ( | ||||||
| "encoding/json" | ||||||
| "fmt" | ||||||
| "io" | ||||||
| "net/http" | ||||||
|
|
||||||
| dto "github.com/prometheus/client_model/go" | ||||||
| corev1 "k8s.io/api/core/v1" | ||||||
|
|
@@ -29,6 +32,7 @@ import ( | |||||
| var ( | ||||||
| GPUCacheUsage = "sglang:token_usage" | ||||||
| RequestWaitingNum = "sglang:num_queue_reqs" | ||||||
| RequestRunningNum = "sglang:num_running_reqs" | ||||||
| TPOT = "sglang:time_per_output_token_seconds" | ||||||
| TTFT = "sglang:time_to_first_token_seconds" | ||||||
| ) | ||||||
|
|
@@ -37,6 +41,7 @@ var ( | |||||
| CounterAndGaugeMetrics = []string{ | ||||||
| GPUCacheUsage, | ||||||
| RequestWaitingNum, | ||||||
| RequestRunningNum, | ||||||
| } | ||||||
|
|
||||||
| HistogramMetrics = []string{ | ||||||
|
|
@@ -47,11 +52,20 @@ var ( | |||||
| mapOfMetricsName = map[string]string{ | ||||||
| GPUCacheUsage: utils.GPUCacheUsage, | ||||||
| RequestWaitingNum: utils.RequestWaitingNum, | ||||||
| RequestRunningNum: utils.RequestRunningNum, | ||||||
| TPOT: utils.TPOT, | ||||||
| TTFT: utils.TTFT, | ||||||
| } | ||||||
| ) | ||||||
|
|
||||||
| type Model struct { | ||||||
| ID string `json:"id"` | ||||||
| } | ||||||
|
|
||||||
| type ModelList struct { | ||||||
| Data []Model `json:"data"` | ||||||
| } | ||||||
|
Comment on lines
+61
to
+67
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. These |
||||||
|
|
||||||
| type sglangEngine struct { | ||||||
| // The address of sglang's query metrics is http://{model server}:MetricPort/metrics | ||||||
| // Default is 30000 | ||||||
|
|
@@ -83,7 +97,15 @@ func (engine *sglangEngine) GetCountMetricsInfo(allMetrics map[string]*dto.Metri | |||||
| continue | ||||||
| } | ||||||
| for _, metric := range metricInfo.Metric { | ||||||
| metricValue := metric.GetCounter().GetValue() | ||||||
| var metricValue float64 | ||||||
| switch metricInfo.GetType() { | ||||||
|
Member
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. the reason for adding this switch statement is i'm not actually sure what kind of metricsType i am going to get like |
||||||
| case dto.MetricType_GAUGE: | ||||||
| metricValue = metric.GetGauge().GetValue() | ||||||
| case dto.MetricType_COUNTER: | ||||||
| metricValue = metric.GetCounter().GetValue() | ||||||
| default: | ||||||
| continue | ||||||
| } | ||||||
| wantMetrics[mapOfMetricsName[metricName]] = metricValue | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -115,7 +137,33 @@ func (engine *sglangEngine) GetHistogramPodMetrics(allMetrics map[string]*dto.Me | |||||
| return wantMetrics, histogramMetrics | ||||||
| } | ||||||
|
|
||||||
| // TODO: Methods to get Models from sglang | ||||||
| // GetPodModels retrieves the list of models from a pod running the sglang engine. | ||||||
| func (engine *sglangEngine) GetPodModels(pod *corev1.Pod) ([]string, error) { | ||||||
| return nil, nil | ||||||
| url := fmt.Sprintf("http://%s:%d/v1/models", pod.Status.PodIP, engine.MetricPort) | ||||||
|
Member
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. can we abstract a common helper function from vllm backend, |
||||||
| resp, err := http.Get(url) | ||||||
|
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. The call to
Suggested change
Member
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. +1 |
||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
|
Comment on lines
+142
to
+146
|
||||||
| defer resp.Body.Close() | ||||||
|
|
||||||
| if resp.StatusCode != http.StatusOK { | ||||||
| return nil, fmt.Errorf("failed to get models from pod %s/%s: HTTP %d", pod.GetNamespace(), pod.GetName(), resp.StatusCode) | ||||||
| } | ||||||
|
|
||||||
| body, err := io.ReadAll(resp.Body) | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
|
|
||||||
| var modelList ModelList | ||||||
| err = json.Unmarshal(body, &modelList) | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
|
|
||||||
| models := make([]string, 0, len(modelList.Data)) | ||||||
| for _, model := range modelList.Data { | ||||||
| models = append(models, model.ID) | ||||||
| } | ||||||
| return models, nil | ||||||
| } | ||||||
|
Comment on lines
141
to
169
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. This function |
||||||
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.
this metric has been replaced by
sglang:inter_token_latency_secondshttps://github.com/sgl-project/sglang/blob/385a35bd118d2e420be1fd6978c703d22a3bcc77/python/sglang/srt/observability/metrics_collector.py#L188