Skip to content

Commit

Permalink
fix testing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffwan committed Aug 29, 2024
1 parent 335268c commit 98d9a4c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/requirements-docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ torch
py-cpuinfo
transformers
mistral_common >= 1.3.4
openai # Required by docs/source/serving/openai_compatible_server.md's vllm.entrypoints.openai.cli_args
openai # Required by docs/source/serving/openai_compatible_server.md's vllm.entrypoints.openai.cli_args
2 changes: 1 addition & 1 deletion requirements-common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ librosa # Required for audio processing
soundfile # Required for audio processing
gguf == 0.9.1
importlib_metadata
mistral_common >= 1.3.4
mistral_common >= 1.3.4
1 change: 0 additions & 1 deletion tests/entrypoints/openai/test_serving_engine.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
from http import HTTPStatus
from unittest.mock import MagicMock

Expand Down
4 changes: 3 additions & 1 deletion vllm/entrypoints/openai/serving_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from vllm.sampling_params import LogitsProcessor, SamplingParams
from vllm.sequence import Logprob
from vllm.transformers_utils.tokenizer import AnyTokenizer
from vllm.utils import AtomicCounter

logger = init_logger(__name__)

Expand Down Expand Up @@ -80,6 +81,7 @@ def __init__(

self.served_model_names = served_model_names

self.lora_id_counter = AtomicCounter(0)
self.lora_requests = []
if lora_modules is not None:
self.lora_requests = [
Expand Down Expand Up @@ -457,7 +459,7 @@ async def load_lora_adapter(
return error_check_ret

lora_name, lora_path = request.lora_name, request.lora_path
unique_id = len(self.lora_requests) + 1
unique_id = self.lora_id_counter.inc(1)
self.lora_requests.append(
LoRARequest(lora_name=lora_name,
lora_int_id=unique_id,
Expand Down
25 changes: 25 additions & 0 deletions vllm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1123,3 +1123,28 @@ async def _run_task_with_lock(task: Callable, lock: asyncio.Lock, *args,
def supports_dynamo() -> bool:
base_torch_version = Version(Version(torch.__version__).base_version)
return base_torch_version >= Version("2.4.0")


class AtomicCounter:
"""An atomic, thread-safe counter"""

def __init__(self, initial=0):
"""Initialize a new atomic counter to given initial value"""
self._value = initial
self._lock = threading.Lock()

def inc(self, num=1):
"""Atomically increment the counter by num and return the new value"""
with self._lock:
self._value += num
return self._value

def dec(self, num=1):
"""Atomically decrement the counter by num and return the new value"""
with self._lock:
self._value -= num
return self._value

@property
def value(self):
return self._value

0 comments on commit 98d9a4c

Please sign in to comment.