vllm.utils.async_utils ¶
Contains helpers related to asynchronous code.
This is similar in concept to the asyncio
module.
AsyncMicrobatchTokenizer ¶
Asynchronous tokenizer with micro-batching.
Pulls pending encode/decode requests from a queue and batches them up to reduce overhead. A single-thread ThreadPoolExecutor is used so the event loop stays responsive.
Source code in vllm/utils/async_utils.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
|
_queues instance-attribute
¶
__call__ async
¶
Source code in vllm/utils/async_utils.py
__del__ ¶
Source code in vllm/utils/async_utils.py
__init__ ¶
Source code in vllm/utils/async_utils.py
_batch_decode_loop async
¶
_batch_decode_loop(queue: Queue)
Batch incoming decode requests for efficiency.
Source code in vllm/utils/async_utils.py
_batch_encode_loop async
¶
Batch incoming encode requests for efficiency.
Source code in vllm/utils/async_utils.py
_get_queue ¶
_get_queue(
loop: AbstractEventLoop, key: tuple
) -> Queue[
tuple[str, dict, Future] | tuple[list[int], Future]
]
Get the request queue for the given operation key, creating a new queue and batcher task if needed.
Source code in vllm/utils/async_utils.py
_queue_key ¶
Return a normalized key describing operation + kwargs.
add_special_tokens
: {True/False}truncation
: {True/False}- If
truncation
is False (max_length
is None), returns a key for a can_batch queue. - If
truncation
is True andmax_length
is None or equalstokenizer.model_max_length
, returns a key for a can_batch queue. - Otherwise, returns a key for a cannot_batch queue.
Examples:
- Decode: ("decode",)
- Encode typical: ("encode", add_special_tokens, bool_truncation, max_length_label)
- Fallback: ("encode", "other")
Source code in vllm/utils/async_utils.py
decode async
¶
Source code in vllm/utils/async_utils.py
collect_from_async_generator async
¶
collect_from_async_generator(
iterator: AsyncGenerator[T, None],
) -> list[T]
Collect all items from an async generator into a list.
in_loop ¶
in_loop(event_loop: AbstractEventLoop) -> bool
make_async ¶
Take a blocking function, and run it on in an executor thread.
This function prevents the blocking function from blocking the asyncio event loop. The code in this function needs to be thread safe.
Source code in vllm/utils/async_utils.py
merge_async_iterators async
¶
merge_async_iterators(
*iterators: AsyncGenerator[T, None],
) -> AsyncGenerator[tuple[int, T], None]
Merge multiple asynchronous iterators into a single iterator.
This method handle the case where some iterators finish before others. When it yields, it yields a tuple (i, item) where i is the index of the iterator that yields the item.
Source code in vllm/utils/async_utils.py
run_in_loop ¶
run_in_loop(
loop: AbstractEventLoop, function: Callable, *args
)