Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问下这里已经有gpu锁了,同时又没有将多个request_data拼成一个,完成并行的原理到时是啥呀 #2

Open
seetimee opened this issue Jun 26, 2024 · 0 comments

Comments

@seetimee
Copy link

    async def process_requests_by_type(self, requests, request_types, request_ids):
    tasks = []
    for request_data, request_type, request_id in zip(requests, request_types, request_ids):
        if request_type == 'embed':
            task = asyncio.create_task(self.run_with_semaphore(self.model.embed, request_data.sentences, request_id))
        else:  # 'rerank'
            task = asyncio.create_task(self.run_with_semaphore(self.model.rerank, request_data.sentence_pairs, request_id))
        tasks.append(task)
    await asyncio.gather(*tasks)
async def run_with_semaphore(self, func, data, request_id):
    async with self.gpu_lock:  # Wait for sem
        future = self.executor.submit(func, data)
        try:
            result = await asyncio.wait_for(asyncio.wrap_future(future), timeout= gpu_time_out)
            self.response_futures[request_id].set_result(result)
        except asyncio.TimeoutError:
            self.response_futures[request_id].set_exception(TimeoutError("GPU processing timeout"))
        except Exception as e:
            self.response_futures[request_id].set_exception(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant