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): update ai-video selection suspension #3033

Merged

Conversation

ad-astra-video
Copy link
Collaborator

@ad-astra-video ad-astra-video commented Apr 28, 2024

What does this pull request do? Explain your changes. (required)

Suspension was not working because the penalty was always 3. This logic was a carryover from transcoding where the suspender always started at a refresh count of 0 because a new session manager was created with each stream. For AI, we are reusing the session manager and the suspender so the refresh count does not reset between requests. The fix to suspension is to consider the current refresh count when calculating the penalty so it is 3 more than the current refresh count in the suspender.

There was also an issue where the discoveryPoolSize was always 100 and with limited orchestrators providing models a refresh of sessions was being done with every request. I added an initialPoolSize field to track the last refresh pool size to use with the shouldRefreshSessions logic rather than 100. This stabilizes the suspender to allow more orchestrators to be tried with each Select call.

Last update was moving the signalRefresh() for the suspender that increments the refresh counter in the suspender to the Refresh function makes it more stable that every time we refresh sessions we add to the suspender refresh count

Happy to segregate some of these changes to separate PRs. The suspension fixes can be added separately without dependency on ai-worker PR.

Specific updates (required)

  • Updates suspender to use the current refresh count of the suspender in the selector.
  • Moves penalty to the AISessionSelector to make it easier to update and available for calculations on the suspension needed
  • releases all Os when there are none in the warm and cold pool
  • Adds option to not use managed containers.

How did you test each of these updates (required)

I have been running these updates on my gateway. Tested 1-200 requests with 5-10 workers sending to gateway. All completed with 1-2 orchestrators providing Bytedance model.

Does this pull request close any open issues?

Checklist:

@github-actions github-actions bot added the AI Issues and PR related to the AI-video branch. label Apr 28, 2024
@ad-astra-video ad-astra-video force-pushed the ai-video-fix-selection-pr branch 2 times, most recently from 494b5d9 to 2504355 Compare May 7, 2024 11:24
@ad-astra-video ad-astra-video force-pushed the ai-video-fix-selection-pr branch from 2504355 to 959ae10 Compare July 20, 2024 10:54
@ad-astra-video ad-astra-video marked this pull request as ready for review July 22, 2024 12:19
@ad-astra-video ad-astra-video requested a review from rickstaa as a code owner July 22, 2024 12:19
@ad-astra-video ad-astra-video force-pushed the ai-video-fix-selection-pr branch from 187dcd4 to d94d62b Compare July 22, 2024 12:23
@ad-astra-video ad-astra-video changed the title Ai video fix selection pr fix(ai): update ai-video selection suspension Aug 27, 2024
Copy link
Member

@victorges victorges left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel like I don't have context to officially approve this, but left some comments. Only nits tho, the implementation makes sense for the PR description.

server/ai_session.go Outdated Show resolved Hide resolved
server/ai_session.go Outdated Show resolved Hide resolved
server/ai_session.go Show resolved Hide resolved
// penalty needs to consider the current suspender count to set the penalty
last_count, ok := pool.suspender.list[sess.Transcoder()]
if ok {
penalty = pool.suspender.count - last_count + pool.penalty
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little lost with this suspension logic. So, I see that:

  • the pool.suspender.count is increased every time signalRefresh() is called
  • pool.penalty is always set to 3
  • last_count is always set to suspender.count + 3

So, that logic would mean that we're not taking the suspended orchestrator until 3 times the signalRefresh() is called. Is this the idea of this suspension mechanism? That we don't allow the given O to get selected in the 3 refresh sessions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes thats right. A small penalty to take the orchestrator out of the working set for short period. With transcoding the refresh count starts at 0 for each new session. For AI the session pools are used across requests and are not reset. If we don't add the current suspender refresh count it wont suspend any orchestrators.

// if there are no orchestrators in the pools
clog.Infof(ctx, "refreshing sessions, no orchestrators in pools")
for i := 0; i < sel.penalty; i++ {
sel.suspender.signalRefresh()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

release all orchestrators

shouldn't we then just remove them from the suspender.list() rather than calling signalRefresh()? My understanding is that if penalty = 3, then we would need to call signalRefresh() 3 times in order to "release all orchestrators from suspension".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it this way thinking that there could be more than 3 orchestrators suspended so it would be less loops to just signalRefresh() 3 times. An alternative would be to just create a new suspender for the selector to clear it or kick all the orchs out of the suspended list (will require new function to do second option).

@leszko leszko deleted the branch livepeer:master November 7, 2024 08:26
@leszko leszko closed this Nov 7, 2024
@rickstaa rickstaa reopened this Nov 13, 2024
@rickstaa rickstaa changed the base branch from ai-video to master November 13, 2024 21:47
@rickstaa
Copy link
Member

rickstaa commented Nov 13, 2024

@leszko Are we still planning to merge these fixes? They help alleviate some of the orchestrator stickiness issues we've observed over the past few months.

@leszko
Copy link
Contributor

leszko commented Nov 14, 2024

@leszko Are we still planning to merge these fixes? They help alleviate some of the orchestrator stickiness issues we've observed over the past few months.

Well...if it helps Orchestrators, then yes. Why not? 🙃 Please address the PR review comments and re-request review :)

@ad-astra-video ad-astra-video force-pushed the ai-video-fix-selection-pr branch from 6dae336 to 9eeacac Compare January 14, 2025 18:55
@ad-astra-video
Copy link
Collaborator Author

ad-astra-video commented Jan 14, 2025

@rickstaa i have updated this PR.

I also think adding something like this would be beneficial for Gateway operators to see the current AI session pool state. WYDT? ad-astra-video@9d42251

EDIT: we included the /getAISessionsPoolInfo endpoint on the gateway cli webserver to provide data about AI pools.

Copy link

codecov bot commented Jan 14, 2025

Codecov Report

Attention: Patch coverage is 15.62500% with 81 lines in your changes missing coverage. Please review.

Project coverage is 32.15960%. Comparing base (390af43) to head (af7434f).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
server/handlers.go 2.27273% 42 Missing and 1 partial ⚠️
server/ai_session.go 0.00000% 35 Missing ⚠️
server/ai_process.go 81.25000% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                 Coverage Diff                 @@
##              master       #3033         +/-   ##
===================================================
- Coverage   32.18835%   32.15960%   -0.02875%     
===================================================
  Files            147         147                 
  Lines          40670       40753         +83     
===================================================
+ Hits           13091       13106         +15     
- Misses         26807       26874         +67     
- Partials         772         773          +1     
Files with missing lines Coverage Δ
server/webserver.go 95.87629% <100.00000%> (+0.04296%) ⬆️
server/ai_process.go 1.66945% <81.25000%> (+1.07723%) ⬆️
server/ai_session.go 2.33333% <0.00000%> (-0.18466%) ⬇️
server/handlers.go 52.19092% <2.27273%> (-1.77991%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 390af43...af7434f. Read the comment docs.

Files with missing lines Coverage Δ
server/webserver.go 95.87629% <100.00000%> (+0.04296%) ⬆️
server/ai_process.go 1.66945% <81.25000%> (+1.07723%) ⬆️
server/ai_session.go 2.33333% <0.00000%> (-0.18466%) ⬇️
server/handlers.go 52.19092% <2.27273%> (-1.77991%) ⬇️

@ad-astra-video ad-astra-video requested a review from leszko January 29, 2025 05:50
@ad-astra-video ad-astra-video force-pushed the ai-video-fix-selection-pr branch 2 times, most recently from cfa53c5 to 80b7531 Compare February 2, 2025 18:12
@ad-astra-video
Copy link
Collaborator Author

@rickstaa this is ready for review. Titan did some testing and the suspension was working as expected.

pool_info_1000.json

pool_info_1_orch.json

Copy link
Contributor

@leszko leszko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added two comments. My suggestion is also to maybe split this PR to make it smaller, because I think it includes some unrelated changes.

  1. Wrt reserving capacity inside CheckAICapacity(), it looks counter-intuitive, but I may not have the full context. It raises a lot of questions in my head, like what if we reserved the capacity, but the request failed at some point. Won't O stop working? Maybe we need to have some timeout to release it?
  2. Wrt: penalty mechanism, any chance it's possible to send this change in its own separate PR (or is it related to reserve capacity change?).

core/ai_orchestrator.go Outdated Show resolved Hide resolved
core/ai_orchestrator.go Outdated Show resolved Hide resolved
@rickstaa
Copy link
Member

rickstaa commented Feb 5, 2025

Added two comments. My suggestion is also to maybe split this PR to make it smaller, because I think it includes some unrelated changes.

  1. Wrt reserving capacity inside CheckAICapacity(), it looks counter-intuitive, but I may not have the full context. It raises a lot of questions in my head, like what if we reserved the capacity, but the request failed at some point. Won't O stop working? Maybe we need to have some timeout to release it?
  2. Wrt: penalty mechanism, any chance it's possible to send this change in its own separate PR (or is it related to reserve capacity change?).

@ad-astra-video I agree with @leszko if we can have the suspense fix in a seperate pull request we can move quicker since that part is more battle tested and reviewd 🙏🏻.

@ad-astra-video ad-astra-video force-pushed the ai-video-fix-selection-pr branch from e478dd0 to b97c3b8 Compare February 5, 2025 16:05
@ad-astra-video ad-astra-video force-pushed the ai-video-fix-selection-pr branch from b97c3b8 to 7636d8e Compare February 5, 2025 16:11
@ad-astra-video
Copy link
Collaborator Author

I have split the PR. If want split another way please tell me specifically which parts want in separate PRs. To me, all the remaining changes are needed to stablize orchestrator pools for batch jobs so I have left in this PR.

I retested all batch pipelines after splitting PR.

@leszko
Copy link
Contributor

leszko commented Feb 6, 2025

I have split the PR. If want split another way please tell me specifically which parts want in separate PRs. To me, all the remaining changes are needed to stablize orchestrator pools for batch jobs so I have left in this PR.

I retested all batch pipelines after splitting PR.

Where is the other PR? Could you share the link?

Copy link
Contributor

@leszko leszko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@leszko
Copy link
Contributor

leszko commented Feb 6, 2025

@rickstaa do you want to review or should I merge?

server/ai_http.go Outdated Show resolved Hide resolved
Copy link
Member

@rickstaa rickstaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ad-astra-video, I made some small code improvements in ad-astra-video#32. Once those are merged, we're good to go. I thoroughly battle-tested it, trying to break it, but couldn't. 🚀

server/ai_session.go Outdated Show resolved Hide resolved
rickstaa and others added 3 commits February 12, 2025 19:37
* refactor: some minor code changes
* refactor: fix transient error naming
* refactor: make isRetryableError case insensitive
@ad-astra-video ad-astra-video merged commit 1c1c280 into livepeer:master Feb 13, 2025
16 of 17 checks passed
@ad-astra-video ad-astra-video deleted the ai-video-fix-selection-pr branch February 13, 2025 03:14
leszko added a commit that referenced this pull request Feb 14, 2025
leszko added a commit that referenced this pull request Feb 14, 2025
@ad-astra-video ad-astra-video restored the ai-video-fix-selection-pr branch February 14, 2025 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AI Issues and PR related to the AI-video branch.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants