File size: 1,821 Bytes
f730521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""Wait until every baseline copy answers, then take the one-time stall out of each.

Measured in the second run: after every start of the released image on this GPU, the first
reply longer than one token stalls for about 100 s. So each copy is asked for two short
replies here, and the time of each is printed.

  python -m tools.warm_copies 9999 9991 9992
"""
import asyncio
import sys
import time

import aiohttp
import numpy as np

from duplex.spec import SR
from serving.baseline_client import human_turn, stream_chat

NL = chr(10)


async def warm(http, port, t0):
    base = f"http://127.0.0.1:{port}/v1"
    while True:
        try:
            async with http.get(base + "/models") as r:
                if r.status == 200:
                    break
        except aiohttp.ClientError:
            pass
        await asyncio.sleep(5)
    up = time.perf_counter() - t0
    pcm = (np.random.default_rng(port).standard_normal(SR) * 300).astype(np.int16)
    took = []
    for _ in range(2):
        t = time.perf_counter()
        messages = [human_turn(pcm), {"role": "assistant", "content": "<think>" + NL, "eot": False}]
        n = 0
        async for _, text, _ in stream_chat(http, base + "/chat/completions", "Step-Audio-R1.1", messages, max_tokens=24, temperature=0.7):
            n += bool(text)
        took.append(round(time.perf_counter() - t, 1))
    print(f"port {port}: answering after {up:.0f} s; first reply {took[0]} s, second {took[1]} s", flush=True)


async def main():
    t0 = time.perf_counter()
    async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=None)) as http:
        await asyncio.gather(*[warm(http, int(p), t0) for p in sys.argv[1:]])
    print(f"all warm after {time.perf_counter() - t0:.0f} s", flush=True)


if __name__ == "__main__":
    asyncio.run(main())