duplex-v0 / tools /warm_copies.py
Jr23xd23's picture
RightNow Duplex v0
f730521 verified
Raw History Blame Contribute Delete
1.82 kB
"""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())