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

Server: when no slot is available, defer the task instead of returning "slot unavailable" #5018

Merged
merged 2 commits into from
Jan 18, 2024

Conversation

ngxson
Copy link
Collaborator

@ngxson ngxson commented Jan 18, 2024

Motivation

Assuming that there is only one slot in server mode, when trying to send 2 requests at the same time, one request will fail with "slot unavailable" error. This behavior sometimes breaks OpenAI compatibility.

This PR defer the task until one of the slots is available.

On the bright side, request will no longer fail. But on the down side, one request now need to wait for the other one to finish.

@lemmi
Copy link

lemmi commented Jan 18, 2024

I think having a queue is a good idea, but it probably shouldn't be an unbounded queue.

@ngxson
Copy link
Collaborator Author

ngxson commented Jan 18, 2024

I think having a queue is a good idea, but it probably shouldn't be an unbounded queue.

I agree with that. In fact, I suspect that the complexity of the server code comes from the communication between http server thread and the "worker" thread (the one who runs the model).

Nevertheless, having used boost::asio in the product of my company, I'm pretty sure that an async-like approach will the the best. Ideally, we can even remove the queue and all the mutexes.

But that mean re-writing all the server code from zero, and for now I really don't have the time to do so.

Copy link
Owner

@ggerganov ggerganov left a comment

Choose a reason for hiding this comment

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

Good change

Probably you want to std::move(task) to avoid copies

@ggerganov ggerganov merged commit 821f0a2 into ggerganov:master Jan 18, 2024
39 of 44 checks passed
jordankanter pushed a commit to jordankanter/llama.cpp that referenced this pull request Feb 3, 2024
* server: defer task when no slot is available

* remove unnecessary log

---------

Co-authored-by: Xuan Son Nguyen <[email protected]>
hodlen pushed a commit to hodlen/llama.cpp that referenced this pull request Apr 1, 2024
* server: defer task when no slot is available

* remove unnecessary log

---------

Co-authored-by: Xuan Son Nguyen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants