Repository navigation
Description
Feature request: Add configurable max_concurrency for Unsloth API inference
Summary
Please add a configurable max_concurrency setting for the Unsloth API inference server.
Currently, the API appears to process inference requests with only one active generation at a time. This is safe and stable for many local setups, but it also means users cannot explicitly increase concurrency when their hardware is capable of handling more than one request.
This feature request is not about limiting uncontrolled parallelism. Instead, it is about making the current single-concurrency behavior configurable.
Motivation
Unsloth is increasingly useful as a local API backend for external tools such as:
- coding agents
- IDE assistants
- OpenAI-compatible clients
- automation scripts
- local multi-agent workflows
- custom applications
Some users may run Unsloth on hardware that can handle more than one concurrent inference request, for example:
- high-VRAM GPUs
- multi-GPU setups
- smaller quantized models
- lightweight workloads
- short completion requests
- local services shared by multiple tools
At the moment, if the API only allows one active request at a time, every other request has to wait even when the system has enough resources to process more.
A configurable concurrency setting would let users choose the right tradeoff between stability and throughput.
Proposed solution
Add a setting such as:
UNSLOTH_API_MAX_CONCURRENCY=2or a CLI option:
--api-max-concurrency 2This would control how many inference requests can run at the same time.
For example:
UNSLOTH_API_MAX_CONCURRENCY=1keeps the current safe behavior: only one inference request runs at a time.
UNSLOTH_API_MAX_CONCURRENCY=2allows up to two inference requests to run concurrently.
UNSLOTH_API_MAX_CONCURRENCY=4allows up to four concurrent inference requests, if the backend and hardware can support it.
Default behavior
To preserve current behavior and avoid surprising users, the default should remain:
max_concurrency = 1This keeps Unsloth stable for most local users while allowing advanced users to opt into higher concurrency.
Suggested behavior
When the number of active inference requests is below max_concurrency, the request should start immediately.
When the number of active requests reaches max_concurrency, additional requests could either:
- wait in a queue until a slot becomes available, or
- return
429 Too Many Requests, depending on the selected policy.
A simple first implementation could use queueing by default.
Example:
max_concurrency = 2Request behavior:
Request A -> starts immediately
Request B -> starts immediately
Request C -> waits until A or B finishesOptional queue policy
A future option could allow users to choose how excess requests are handled:
UNSLOTH_API_QUEUE_POLICY=waitor:
UNSLOTH_API_QUEUE_POLICY=rejectPossible modes:
wait
rejectwait
Requests above the concurrency limit wait until a slot becomes available.
reject
Requests above the concurrency limit immediately return:
429 Too Many RequestsExample response:
{
"error": {
"message": "API concurrency limit reached. Please retry later.",
"type": "rate_limit_exceeded",
"code": "max_concurrency_exceeded"
}
}Streaming behavior
For streaming responses, a concurrency slot should remain occupied until the stream is fully completed or cancelled.
The slot should be released when:
- the stream finishes normally
- the client disconnects
- the request is cancelled
- an exception occurs
This is important because a streaming request may keep the model busy for a long time.
Example use cases
Use case 1: Current safe behavior
A user runs Unsloth on a consumer GPU with limited VRAM.
They keep:
UNSLOTH_API_MAX_CONCURRENCY=1Only one inference request runs at a time, matching the current behavior.
Use case 2: More capable hardware
A user runs a small quantized model on a high-VRAM GPU.
They set:
UNSLOTH_API_MAX_CONCURRENCY=2Two short API requests can run at the same time, improving throughput.
Use case 3: External coding agents
A user connects Unsloth to an external coding agent or IDE assistant.
The tool may send multiple requests, such as:
- chat completion
- code edit request
- context summarization
- background analysis
With configurable concurrency, the user can decide whether these should run one at a time or in parallel.
Why this would be useful
This would make Unsloth API more flexible as a local inference backend.
Users with limited hardware can keep the current stable behavior.
Users with stronger hardware can increase concurrency for better throughput.
This also makes the API behavior more explicit and easier to tune for different deployment environments.
Suggested implementation idea
Internally, this could be implemented with an async semaphore or similar concurrency-control mechanism.
Example concept:
api_concurrency_semaphore = asyncio.Semaphore(settings.api_max_concurrency)
async def handle_inference_request(request):
async with api_concurrency_semaphore:
return await run_inference(request)For streaming responses, the semaphore should remain acquired until the generator finishes or the client disconnects.
Backward compatibility
This should be backward compatible if the default remains:
max_concurrency = 1That would preserve the current single-active-request behavior while allowing users to opt into higher concurrency.
Possible configuration names
Environment variable:
UNSLOTH_API_MAX_CONCURRENCY=2CLI option:
--api-max-concurrency 2Config file:
{
"api": {
"max_concurrency": 2
}
}Optional future improvements
This feature could later be extended with:
UNSLOTH_API_QUEUE_POLICY=wait
UNSLOTH_API_QUEUE_POLICY=reject
UNSLOTH_API_QUEUE_SIZE=5
UNSLOTH_API_REQUEST_TIMEOUT=300Possible future additions:
- queue size limit
- request timeout
- per-client concurrency limit
- separate limits for Studio UI and external API requests
- endpoint showing active and queued requests
- documentation with recommended values for different hardware setups
Documentation request
Please also document:
- the default value
- how to configure
max_concurrency - whether extra requests are queued or rejected
- how streaming requests affect concurrency
- recommended values for low-VRAM and high-VRAM setups
Expected benefit
This feature would allow Unsloth API users to explicitly control request parallelism.
It keeps the current stable single-request behavior by default, while enabling higher throughput for users who have enough hardware resources to handle concurrent inference.
Activity
Imagineer99 commentedon Jun 11, 2026
Added via --parallel / -np in #5737
feat: expose UNSLOTH_API_MAX_CONCURRENCY onto existing admission capa…
feat: expose UNSLOTH_API_MAX_CONCURRENCY onto existing admission capa…
feat: expose UNSLOTH_API_MAX_CONCURRENCY onto existing admission capa…
feat: expose UNSLOTH_API_MAX_CONCURRENCY onto existing admission capa…
feat: expose UNSLOTH_API_MAX_CONCURRENCY onto existing admission capa…
feat: expose UNSLOTH_API_MAX_CONCURRENCY onto existing admission capa…
feat: expose UNSLOTH_API_MAX_CONCURRENCY onto existing admission capa…