From 6535844394ec91edc4687fbee0dfceb1d13a54cd Mon Sep 17 00:00:00 2001 From: Rick Staa Date: Wed, 5 Jun 2024 13:41:22 +0200 Subject: [PATCH] feat(ai): account for num_inference_steps inT2I latency inference score calculation (#3074) * fix(ai): Fix accuracy of T2I latency score when num_inference_steps provided * refactor(ai): update numInferenceSteps default This commit ensures that the same numInferenceSteps default value is used as the one set in https://github.com/livepeer/ai-worker/blob/31fe460a45e1d9e908d3a1bdcfdd8822c3889214/runner/app/routes/text_to_image.py#L28. --------- Co-authored-by: Elite Encoder --- server/ai_process.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/server/ai_process.go b/server/ai_process.go index dd4302715d..e851b8d82c 100644 --- a/server/ai_process.go +++ b/server/ai_process.go @@ -110,12 +110,18 @@ func submitTextToImage(ctx context.Context, params aiRequestParams, sess *AISess balUpdate.Status = ReceivedChange } - // TODO: Refine this rough estimate in future iterations - numImages := 1 + // TODO: Refine this rough estimate in future iterations. + // TODO: Default values for the number of images and inference steps are currently hardcoded. + // These should be managed by the nethttpmiddleware. Refer to issue LIV-412 for more details. + numImages := float64(1) if req.NumImagesPerPrompt != nil { - numImages = *req.NumImagesPerPrompt + numImages = float64(*req.NumImagesPerPrompt) + } + numInferenceSteps := float64(50) + if req.NumInferenceSteps != nil { + numInferenceSteps = float64(*req.NumInferenceSteps) } - sess.LatencyScore = took.Seconds() / float64(outPixels) / float64(numImages) + sess.LatencyScore = took.Seconds() / float64(outPixels) / (numImages * numInferenceSteps) return resp.JSON200, nil }