Skip to content

Commit 428f961

Browse files
committedJun 1, 2024
Dynamic gen (async): Forward generator exceptions to receiving jobs
1 parent 18a2580 commit 428f961

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed
 

‎exllamav2/generator/dynamic_async.py

+18-11
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,22 @@ def __init__(self, *args, **kwargs):
1919
self.iteration_task = asyncio.create_task(self._run_iteration())
2020

2121
async def _run_iteration(self):
22-
while True:
23-
async with self.condition:
24-
await self.condition.wait_for(lambda: len(self.jobs) > 0)
25-
results = self.generator.iterate()
26-
for result in results:
27-
job = result["job"]
28-
async_job = self.jobs[job]
29-
await async_job.put_result(result)
30-
if result["eos"]:
31-
del self.jobs[job]
32-
await asyncio.sleep(0)
22+
try:
23+
while True:
24+
async with self.condition:
25+
await self.condition.wait_for(lambda: len(self.jobs) > 0)
26+
results = self.generator.iterate()
27+
for result in results:
28+
job = result["job"]
29+
async_job = self.jobs[job]
30+
await async_job.put_result(result)
31+
if result["eos"]:
32+
del self.jobs[job]
33+
await asyncio.sleep(0)
34+
except Exception as e:
35+
# If the generator throws an exception it won't pertain to any one ongoing job, so push it to all of them
36+
for async_job in self.jobs.values():
37+
await async_job.put_result(e)
3338

3439
def enqueue(self, job: ExLlamaV2DynamicJobAsync):
3540
assert job.job not in self.jobs
@@ -75,6 +80,8 @@ async def put_result(self, result):
7580
async def __aiter__(self):
7681
while True:
7782
result = await self.queue.get()
83+
if isinstance(result, Exception):
84+
raise result
7885
yield result
7986
if result["eos"]:
8087
break

0 commit comments

Comments
 (0)