Skip to content

Commit

Permalink
feat(ai): Enhance orchestrator selection by incorporating latency
Browse files Browse the repository at this point in the history
This commit introduces latency consideration into the orchestrator
selection process, addressing two key issues. Firstly, it resolves a
minor bug where the algorithm consistently selected known orchestrators
due to a condition that never evaluated to true (see [this
condition](https://github.com/livepeer/go-livepeer/blob/1239b4e56133003fe6a98a863cce6bdd6b5f2532/server/selection.go#L110)).
Secondly, this change ensures that, once all orchestrators have been
evaluated, the one with the fastest response time for a specific job is
chosen. While the current method for calculating latency is somewhat
basic, it sets the foundation for more sophisticated enhancements in the
future.

Co-authored-by: Brad P <[email protected]>
  • Loading branch information
rickstaa and ad-astra-video committed May 6, 2024
1 parent ebd5045 commit b19b097
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions server/ai_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ func submitTextToImage(ctx context.Context, params aiRequestParams, sess *AISess
}
defer completeBalanceUpdate(sess.BroadcastSession, balUpdate)

start := time.Now()
resp, err := client.TextToImageWithResponse(ctx, req, setHeaders)
took := time.Since(start)
if err != nil {
return nil, err
}
Expand All @@ -108,6 +110,13 @@ func submitTextToImage(ctx context.Context, params aiRequestParams, sess *AISess
balUpdate.Status = ReceivedChange
}

// TODO: Refine this rough estimate in future iterations
numImages := 1
if req.NumImagesPerPrompt != nil {
numImages = *req.NumImagesPerPrompt
}
sess.LatencyScore = took.Seconds() / float64(outPixels) / float64(numImages)

return resp.JSON200, nil
}

Expand Down Expand Up @@ -168,7 +177,9 @@ func submitImageToImage(ctx context.Context, params aiRequestParams, sess *AISes
}
defer completeBalanceUpdate(sess.BroadcastSession, balUpdate)

start := time.Now()
resp, err := client.ImageToImageWithBodyWithResponse(ctx, mw.FormDataContentType(), &buf, setHeaders)
took := time.Since(start)
if err != nil {
return nil, err
}
Expand All @@ -183,6 +194,9 @@ func submitImageToImage(ctx context.Context, params aiRequestParams, sess *AISes
balUpdate.Status = ReceivedChange
}

// TODO: Refine this rough estimate in future iterations
sess.LatencyScore = took.Seconds() / float64(outPixels)

return resp.JSON200, nil
}

Expand Down Expand Up @@ -246,7 +260,9 @@ func submitImageToVideo(ctx context.Context, params aiRequestParams, sess *AISes
}
defer completeBalanceUpdate(sess.BroadcastSession, balUpdate)

start := time.Now()
resp, err := client.ImageToVideoWithBody(ctx, mw.FormDataContentType(), &buf, setHeaders)
took := time.Since(start)
if err != nil {
return nil, err
}
Expand All @@ -271,6 +287,9 @@ func submitImageToVideo(ctx context.Context, params aiRequestParams, sess *AISes
return nil, err
}

// TODO: Refine this rough estimate in future iterations
sess.LatencyScore = took.Seconds() / float64(outPixels)

return &res, nil
}

Expand Down

0 comments on commit b19b097

Please sign in to comment.