Skip to content

Commit

Permalink
fix(ai): improve AI selection algorithm (#3030)
Browse files Browse the repository at this point in the history
* fix(ai): improve selection algorithm

This commit modifies the selection algorithm to continue retrying for a
duration of one second instead of stopping after four attempts. This
change addresses issues encountered with the current algorithm's
performance in environments with 15 nodes on the network, ensuring more
robust and reliable operation until further optimizations can be
implemented.

* refactor(ai): enhance selection algorithm retry logic

This commit replaces the time-based for-loop in the selection
algorithm's retry logic with a more context-aware approach.
  • Loading branch information
rickstaa committed May 2, 2024
1 parent 93caa3b commit bbda633
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions server/ai_process.go
Expand Up @@ -12,6 +12,7 @@ import (
"net/http"
"path/filepath"
"strings"
"time"

"github.com/livepeer/ai-worker/worker"
"github.com/livepeer/go-livepeer/clog"
Expand All @@ -21,7 +22,7 @@ import (
"github.com/livepeer/lpms/stream"
)

const maxProcessingRetries = 4
const processingRetryTimeout = 2 * time.Second
const defaultTextToImageModelID = "stabilityai/sdxl-turbo"
const defaultImageToImageModelID = "stabilityai/sdxl-turbo"
const defaultImageToVideoModelID = "stabilityai/stable-video-diffusion-img2vid-xt"
Expand Down Expand Up @@ -311,8 +312,11 @@ func processAIRequest(ctx context.Context, params aiRequestParams, req interface

var resp *worker.ImageResponse

cctx, cancel := context.WithTimeout(context.Background(), processingRetryTimeout)
defer cancel()

tries := 0
for tries < maxProcessingRetries {
for {
tries++

sess, err := params.sessManager.Select(ctx, cap, modelID)
Expand All @@ -334,6 +338,10 @@ func processAIRequest(ctx context.Context, params aiRequestParams, req interface
clog.Infof(ctx, "Error submitting request cap=%v modelID=%v try=%v orch=%v err=%v", cap, modelID, tries, sess.Transcoder(), err)

params.sessManager.Remove(ctx, sess)

if cctx.Err() == context.DeadlineExceeded {
break
}
}

if resp == nil {
Expand Down

0 comments on commit bbda633

Please sign in to comment.