Skip to content

Commit 1a82be8

Browse files
authored
REF: Modified the batch lock logic (#4162)
1 parent 5d6d538 commit 1a82be8

File tree

7 files changed

+13
-10
lines changed

7 files changed

+13
-10
lines changed

xinference/core/model.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,6 @@ def __init__(
206206
):
207207
super().__init__()
208208

209-
from ..model.llm.llama_cpp.core import XllamaCppModel
210-
from ..model.llm.lmdeploy.core import LMDeployModel
211-
from ..model.llm.sglang.core import SGLANGModel
212-
from ..model.llm.transformers.core import PytorchModel
213209
from ..model.llm.vllm.core import VLLMModel
214210

215211
self._supervisor_address = supervisor_address
@@ -223,12 +219,7 @@ def __init__(
223219
self._pending_requests: asyncio.Queue = asyncio.Queue()
224220
self._handle_pending_requests_task = None
225221
self._lock = (
226-
None
227-
if isinstance(
228-
self._model,
229-
(PytorchModel, VLLMModel, SGLANGModel, LMDeployModel, XllamaCppModel),
230-
)
231-
else asyncio.locks.Lock()
222+
None if getattr(self._model, "allow_batch", False) else asyncio.locks.Lock()
232223
)
233224
self._worker_ref = None
234225
self._progress_tracker_ref = None

xinference/model/llm/core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ def get_llm_version_infos():
4545

4646

4747
class LLM(abc.ABC):
48+
allow_batch = False
49+
4850
def __init__(
4951
self,
5052
replica_model_uid: str,

xinference/model/llm/llama_cpp/core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def __init__(self, msg):
4040

4141

4242
class XllamaCppModel(LLM, ChatModelMixin):
43+
allow_batch = True
44+
4345
def __init__(
4446
self,
4547
model_uid: str,

xinference/model/llm/lmdeploy/core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class LMDeployGenerateConfig(TypedDict, total=False):
7373

7474

7575
class LMDeployModel(LLM):
76+
allow_batch = True
77+
7678
def __init__(
7779
self,
7880
model_uid: str,

xinference/model/llm/sglang/core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ class SGLANGGenerateConfig(TypedDict, total=False):
137137

138138

139139
class SGLANGModel(LLM):
140+
allow_batch = True
141+
140142
def __init__(
141143
self,
142144
model_uid: str,

xinference/model/llm/transformers/core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ def decorator(cls):
9191

9292

9393
class PytorchModel(LLM):
94+
allow_batch = True
95+
9496
def __init__(
9597
self,
9698
model_uid: str,

xinference/model/llm/vllm/core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ class VLLMGenerateConfig(TypedDict, total=False):
302302

303303

304304
class VLLMModel(LLM):
305+
allow_batch = True
306+
305307
def __init__(
306308
self,
307309
model_uid: str,

0 commit comments

Comments
 (0)