mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-12-05 08:03:01 +00:00
feat: sample immediate task successes in model performance metrics (#8067)
This commit is contained in:
1 parent
fcc241cdf8
commit
e449cc700e
3 files changed
+55
-9
No files matched your search
@@ -732,6 +732,7 @@ func executeTaskSubmissionWith(
|
||||
diagnostics.failed("settle", "billing_error", taskErr, true)
|
||||
return nil, taskErr
|
||||
}
|
||||
perfmetrics.RecordImmediateTaskResult(relayInfo, result.Immediate)
|
||||
if task.Status != model.TaskStatusFailure {
|
||||
service.MarkRequestPolicySuccess(c, nil)
|
||||
} else {
|
||||
|
||||
@@ -104,6 +104,24 @@ func RecordTaskResult(task *model.Task, result *relaycommon.TaskInfo) {
|
||||
Record(sample)
|
||||
}
|
||||
|
||||
// Immediate failures are submit failures, which are not health samples.
|
||||
func RecordImmediateTaskResult(info *relaycommon.RelayInfo, result *relaycommon.TaskInfo) {
|
||||
if result == nil || result.Status != model.TaskStatusSuccess {
|
||||
return
|
||||
}
|
||||
sample := Sample{
|
||||
Model: info.OriginModelName,
|
||||
Group: info.UsingGroup,
|
||||
LatencyMs: time.Since(info.StartTime).Milliseconds(),
|
||||
Success: true,
|
||||
}
|
||||
if tokens := int64(cmp.Or(result.TotalTokens, result.CompletionTokens)); tokens > 0 {
|
||||
sample.OutputTokens = tokens
|
||||
sample.GenerationMs = sample.LatencyMs
|
||||
}
|
||||
Record(sample)
|
||||
}
|
||||
|
||||
func Record(sample Sample) {
|
||||
setting := perf_metrics_setting.GetSetting()
|
||||
if !setting.Enabled || sample.Model == "" {
|
||||
|
||||
@@ -139,22 +139,49 @@ func TestRecordTaskResultSamplesTerminalTasks(t *testing.T) {
|
||||
}, relaycommon.FailTaskInfo("boom"))
|
||||
RecordTaskResult(&model.Task{Status: model.TaskStatusSuccess, FinishTime: now}, nil)
|
||||
|
||||
assert.Equal(t, map[bucketKey]counters{
|
||||
{model: "video-model", group: "a"}: {
|
||||
requestCount: 2,
|
||||
successCount: 1,
|
||||
totalLatencyMs: 180000,
|
||||
outputTokens: 5000,
|
||||
generationMs: 100000,
|
||||
},
|
||||
}, mergedHotBuckets())
|
||||
}
|
||||
|
||||
// Immediate submit results: only successes are sampled, timed from relay start.
|
||||
func TestRecordImmediateTaskResultSamplesSuccessOnly(t *testing.T) {
|
||||
hotBuckets.Clear()
|
||||
t.Cleanup(func() { hotBuckets.Clear() })
|
||||
info := &relaycommon.RelayInfo{OriginModelName: "image-model", UsingGroup: "a", StartTime: time.Now().Add(-2 * time.Second)}
|
||||
RecordImmediateTaskResult(info, &relaycommon.TaskInfo{Status: model.TaskStatusSuccess, TotalTokens: 4096})
|
||||
RecordImmediateTaskResult(info, relaycommon.FailTaskInfo("boom"))
|
||||
RecordImmediateTaskResult(info, &relaycommon.TaskInfo{Status: model.TaskStatusInProgress})
|
||||
RecordImmediateTaskResult(info, nil)
|
||||
|
||||
merged := mergedHotBuckets()
|
||||
require.Len(t, merged, 1)
|
||||
got := merged[bucketKey{model: "image-model", group: "a"}]
|
||||
assert.GreaterOrEqual(t, got.totalLatencyMs, int64(2000))
|
||||
assert.Equal(t, counters{
|
||||
requestCount: 1,
|
||||
successCount: 1,
|
||||
totalLatencyMs: got.totalLatencyMs,
|
||||
outputTokens: 4096,
|
||||
generationMs: got.totalLatencyMs,
|
||||
}, got)
|
||||
}
|
||||
|
||||
func mergedHotBuckets() map[bucketKey]counters {
|
||||
merged := map[bucketKey]counters{}
|
||||
hotBuckets.Range(func(key, value any) bool {
|
||||
k := key.(bucketKey)
|
||||
require.Equal(t, "video-model", k.model)
|
||||
require.Equal(t, "a", k.group)
|
||||
k.bucketTs = 0
|
||||
mergeCounters(merged, k, value.(*atomicBucket).snapshot())
|
||||
return true
|
||||
})
|
||||
assert.Equal(t, counters{
|
||||
requestCount: 2,
|
||||
successCount: 1,
|
||||
totalLatencyMs: 180000,
|
||||
outputTokens: 5000,
|
||||
generationMs: 100000,
|
||||
}, merged[bucketKey{model: "video-model", group: "a"}])
|
||||
return merged
|
||||
}
|
||||
|
||||
// TEST_PERF_MYSQL_DSN / TEST_PERF_POSTGRES_DSN optionally run the aggregation
|
||||
|
||||
Reference in new issue
Block a user