"tools/train_utils/vscode:/vscode.git/clone" did not exist on "3fa8b5121dba863b101e84f9b58aa7ddb17c7d2b"
middle.py 926 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import asyncio

import uvloop
from triton_distributed_rs import DistributedRuntime, triton_worker

uvloop.install()


class RequestHandler:
    def __init__(self, backend):
        self.backend = backend

    async def generate(self, request):
        request = f"{request}-mid"
        async for output in await self.backend.random(request):
            yield output.get("data")


@triton_worker()
async def worker(runtime: DistributedRuntime):
    # client to backend
    backend = (
        await runtime.namespace("examples/pipeline")
        .component("backend")
        .endpoint("generate")
        .client()
    )

    # create endpoint service for middle component
    component = runtime.namespace("examples/pipeline").component("middle")
    await component.create_service()

    endpoint = component.endpoint("generate")
    await endpoint.serve_endpoint(RequestHandler(backend).generate)


asyncio.run(worker())