Skip to content
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

fix(ai): improve AI selection algorithm #3030

Merged
merged 2 commits into from May 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
rickstaa marked this conversation as resolved.
Show resolved Hide resolved
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 {
rickstaa marked this conversation as resolved.
Show resolved Hide resolved
break
}
}

if resp == nil {
Expand Down