Allow explicit shared CPU cores for Qwen and record streaming comparison

This commit is contained in:
Mikei386 committed 2026-10-22 14:32:09 +02:00
1 parent ba4904ea78
commit 746009b676
12 files changed
+833 -20

No files matched your search

@@ -0,0 +1,93 @@
# Two exclusive plus two shared TTS cores ·22 October2026
Michael explicitly requested two physical cores exclusively available to TTS
relative to Strata, plus two physical cores shared by both workloads. Strata
retains its four-core CPU range. Saved Linux logical CPUs on Ryzen5 5600:
| Range | Physical cores | Logical CPUs |
| --- | --- | --- |
| Strata only |0–1|0,1,6,7|
| Shared |2–3|2,3,8,9|
| TTS only |4–5|4,5,10,11|
CPU quota12/RAM59GiB, Strata0.1.47 IQ3 dual-slot profile, GPU split/reserves,
Qwen0.6B Q4/codec/Anna,2generation+2codec threads, CPU-Flash-Attention off,
Nice10 and160ms codec blocks remain unchanged. No Hermes/VPN changes.
This is process/thread affinity, not a host-wide exclusive CPU partition.
## Persistent implementation
`cpu_partition.py` accepts the optional `shared_cpus` list only when it exactly
matches the overlap of the Strata and TTS lists. Runtime topology validation
still requires complete physical SMT pairs; sharing only opposite SMT siblings
is rejected. Missing `shared_cpus` retains the previous strict-disjoint behavior.
The existing validated encrypted settings backup carries the same file;
actual shared-file settings restoration was tested.35focused tests passed.
Active image:`athena-deck-standalone:8cf88a02e30444e8`. Only the CPU policy module
changed in the application; a code-only layer reused the existing runtime.
No model/runtime rebuild or new package/service. Activation checked ordinary
authenticated status twice for0active requests and preserved the exact prior
CPU file/install manifest for automatic rollback. The original dual profile
reloaded normally:HTTP200,46.282s including load. Both workload masks were
observed under load. TTS ran on shared CPUs8/9(and occasionally2/3), while
Strata stayed off4/5/10/11. Previous stopped maintenance container is removed
after acceptance; previous image remains available.
## Streaming results
The same synthetic German passage is sent to the normal PCM speech endpoint.
The measurement client counts/discards PCM and inspects no conversational user
content. Deck's normal synthetic-job output/history behavior is unchanged. Separate bounded
synthetic Strata requests continue until TTS completes. `llm_coverage` measures
overlap from each request's first content to its end; brief gaps remain between
requests. No actual Conduit call or phone playback was triggered.
| Condition | Audio | Total | RTF | First PCM | Required additional startup buffer |
| --- | ---: | ---: | ---: | ---: | ---: |
| Initial exclusive baseline,1024-token cap |17.76s|26.346s|1.483|0.563s|8.122s|
| Shared run1,1024-token cap |17.76s|21.975s|1.237|0.610s|3.765s|
| Shared run2,1024-token cap |17.76s|21.130s|1.190|0.569s|2.920s|
| Matched exclusive,512-token cap |17.76s|23.744s|1.337|0.767s|5.396s|
| Matched shared,512-token cap |17.76s|21.957s|1.236|0.537s|3.779s|
The initial before/after has a restart between conditions and varying LLM output
counts(566or1024); do not interpret its full difference as a causal speedup.
The additional matched pair uses the same loaded Strata and Qwen processes,
identical512-token limits(all five LLM requests reached512in each arm), and
changes only the live affinity of the owned Qwen threads. It narrows TTS to its
exclusive CPUs temporarily, then restores the requested shared CPU range in a
finally block. The saved production policy is never narrowed. LLM coverage
was91.0% versus90.0%; sampling is100ms and is not exact CPU-time attribution.
That matched pair reduces generation wall time by7.5% and calculated startup
buffer by1.62s. Longest packet gap is0.444s exclusive versus0.505s shared, so
not every jitter measure improves. Single ordered pair, no randomization or
quality scoring; no universal throughput or phone-playback guarantee.
**The new allocation helps modestly but remains slower than realtime.**
## Reproduction, native restore and rollback
`bench.py` records only technical counts/timings/masks, consumes the existing API
credential as stdin JSON, and stores results beside itself. Never pass/store the
credential in arguments, Git or logs. It refuses to start while normal API
requests are active. Current reproduction targets Athena's explicit profile IDs,
loopback ports and existing voice; those are qualification conditions, not
generic installation defaults. Synthetic output is bounded per request and
the load loop stops once the speech request ends. The committed script uses
the512-token matched limit; initial runs used1024.
For today's container it discovers the managed Deck PID with Docker. For a
native Debian/systemd Deck, supply `--deck-pid MAIN_PID` from that service;
worker discovery and affinity observation then require only Linux `/proc`.
Restore the updated Deck source including the CPU policy module and the saved
`cpu-partition.json`, validate the new host's topology, preserve file owner/
mode0600, and permit all configured CPUs in the parent service(1200%quota on
this host). No worker requires Docker. Full host/native restore qualification
remains the existing open installation task.
Rollback at idle:restore `qwen_tts:[4,5,10,11]`, remove `shared_cpus`, preserve
the other settings, and reload the workers. Restore that old file before an
older image that rejects the shared field. No model, profile or voice deletion.
Scoped maintenance directory:`/opt/athena-deck-dev/tts-shared-cpu-20261022`.
See[configuration and native installation](../../CPU_PARTITION.md).
@@ -0,0 +1,109 @@
{
"arm": "before",
"tts": {
"seconds": 26.345561609981814,
"first_pcm_seconds": 0.5629670549824368,
"audio_seconds": 17.76,
"rtf": 1.4834212618233003,
"bytes": 852480,
"packets": 119,
"longest_packet_gap_seconds": 0.42372539098141715,
"required_buffer_after_first_pcm_seconds": 8.121515240014997
},
"llm_rounds": [
{
"seconds": 11.776726370997494,
"completion_tokens": 1024
},
{
"seconds": 10.466018856997835,
"completion_tokens": 1024
},
{
"seconds": 9.945477088011103,
"completion_tokens": 1024
}
],
"llm_overlap_seconds": 25.03941150996252,
"llm_coverage": 0.9504223853962399,
"thread_affinities": {
"qwen_tts": [
{
"name": "python",
"cpus": "4-5,10-11"
}
],
"strata": [
{
"name": "cuda-EvtHandlr",
"cpus": "6-9"
},
{
"name": "cuda00001400006",
"cpus": "6-9"
},
{
"name": "strata",
"cpus": "6-9"
},
{
"name": "strata-adapt",
"cpus": "6-9"
},
{
"name": "strata-host",
"cpus": "0"
},
{
"name": "strata-io",
"cpus": "6-9"
},
{
"name": "strata-lookahea",
"cpus": "6-9"
},
{
"name": "strata-pool-0",
"cpus": "1"
},
{
"name": "strata-pool-1",
"cpus": "2"
},
{
"name": "strata-pool-2",
"cpus": "3"
},
{
"name": "strata-stage",
"cpus": "6-9"
},
{
"name": "strata-stdin",
"cpus": "6-9"
},
{
"name": "strata-watchdog",
"cpus": "6-9"
}
]
},
"running_cpu_samples": {
"strata": {
"0": 304,
"1": 302,
"2": 302,
"3": 302,
"8": 32,
"6": 70,
"9": 13,
"7": 48
},
"qwen_tts": {
"5": 201,
"10": 209,
"11": 207,
"4": 208
}
}
}
@@ -0,0 +1,93 @@
"""Bounded synthetic load and PCM arrival timing; no user text/audio is read."""
import concurrent.futures,json,subprocess,sys,threading,time,urllib.request
from pathlib import Path
key=json.load(sys.stdin)['key'];stage=Path(__file__).resolve().parent
arm=sys.argv[1];base='http://127.0.0.1:8120/v1/'
headers={'Authorization':'Bearer '+key,'Content-Type':'application/json'}
def api(name,body):return urllib.request.urlopen(urllib.request.Request(base+name,data=json.dumps(body).encode(),headers=headers),timeout=180)
def idle():
req=urllib.request.Request('http://127.0.0.1:8108/api/v1/status',headers=headers)
with urllib.request.urlopen(req,timeout=10) as r:
if json.load(r)['endpoint']['active_requests']!=0:raise RuntimeError('Real request active; test deferred')
def processes():
root=int(sys.argv[sys.argv.index('--deck-pid')+1]) if '--deck-pid' in sys.argv else json.loads(subprocess.check_output(['docker','inspect','athena-deck-dev']))[0]['State']['Pid'];pending=[root];seen=set();out={}
while pending:
pid=pending.pop()
if pid in seen:continue
seen.add(pid)
try:
for child_list in Path(f'/proc/{pid}/task').glob('*/children'):
try:pending.extend(int(n) for n in child_list.read_text().split())
except OSError:pass
cmd=Path(f'/proc/{pid}/cmdline').read_bytes().split(b'\0')
role='qwen_tts' if any(a.endswith(b'/qwen_native_worker.py') for a in cmd) else 'strata' if cmd[0].endswith(b'/engine/strata') else None
if role:out[role]=pid
except (OSError,ValueError):pass
return out
def observe(pids):
found={}
for role,pid in pids.items():
for f in Path(f'/proc/{pid}/task').glob('*/status'):
try:
d={s.split(':',1)[0]:s.split(':',1)[1].strip() for s in f.read_text().splitlines() if ':' in s}
found.setdefault(role,set()).add((d['Name'],d['Cpus_allowed_list']))
except (OSError,KeyError):pass
return found
idle();pids=processes()
if set(pids)!={'strata','qwen_tts'}:raise RuntimeError('Expected both warm workers')
masks={};running_cpus={};stop=threading.Event();stop_load=threading.Event();ready=threading.Event();state={};rounds=[]
def monitor():
while not stop.is_set():
for role,values in observe(pids).items():masks.setdefault(role,set()).update(values)
for role,pid in pids.items():
for f in Path(f'/proc/{pid}/task').glob('*/stat'):
try:
fields=f.read_text().rsplit(')',1)[1].split()
if fields[0]=='R':
n=int(fields[36]);counts=running_cpus.setdefault(role,{})
counts[n]=counts.get(n,0)+1
except (OSError,ValueError,IndexError):pass
stop.wait(.1)
def llm():
deadline=time.monotonic()+90
for n in range(8):
if stop_load.is_set():break
if time.monotonic()>deadline:raise RuntimeError('Synthetic load deadline')
start=time.monotonic();first=None;tokens=0
try:
with api('chat/completions',dict(model='flash-next-strata-iq3-dual',messages=[dict(role='user',content='Zähle alle ganzen Zahlen von eins bis fünfhundert vollständig in deutschen Wörtern auf. Lasse keine aus, benutze keine Abkürzung und keine Erklärung. Runde '+str(n+1)+'.')],max_tokens=512,reasoning_effort='none',temperature=0,stream=True,stream_options=dict(include_usage=True))) as r:
for line in r:
if not line.startswith(b'data: ') or line.strip()==b'data: [DONE]':continue
d=json.loads(line[6:]);tokens=(d.get('usage') or {}).get('completion_tokens',tokens)
if any(c.get('delta',{}).get('content') for c in d.get('choices',[])) and first is None:
first=time.monotonic();ready.set()
rounds.append(dict(start=start,end=time.monotonic(),first=first,completion_tokens=tokens))
except Exception:
state['load_failed']=True;ready.set();raise
if not stop_load.is_set():raise RuntimeError('Synthetic load ended before TTS')
def tts():
if not ready.wait(100) or state.get('load_failed'):raise RuntimeError('LLM did not begin')
start=time.monotonic();state['tts_start']=start;first=None;received=0;latest=None;maxgap=0;deficit=0;chunks=0
with api('audio/speech',dict(model='qwen-06b-q4-anna-cpu',voice='default',response_format='pcm',input='Dies ist ein Test mit fest aufgeteilten Prozessorkernen. Während Strata eine Antwort berechnet, erzeugt Anna diese Sprachausgabe. Wir prüfen, ob die Sprache gleichmäßig und schneller als in Echtzeit ankommt.')) as r:
while True:
b=r.read1(16384)
if not b:break
now=time.monotonic()
if first is None:first=now
else:
maxgap=max(maxgap,now-latest);deficit=max(deficit,now-first-received/48000)
received+=len(b);latest=now;chunks+=1
end=time.monotonic();state['tts_end']=end
if received%2 or not received:raise RuntimeError('Invalid complete PCM stream')
return dict(seconds=end-start,first_pcm_seconds=first-start,audio_seconds=received/48000,rtf=(end-start)/(received/48000),bytes=received,packets=chunks,longest_packet_gap_seconds=maxgap,required_buffer_after_first_pcm_seconds=max(0,deficit))
thread=threading.Thread(target=monitor,daemon=True);thread.start()
try:
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as pool:
lf=pool.submit(llm)
try:speech=tts()
finally:stop_load.set()
lf.result()
overlap=sum(max(0,min(r['end'],state['tts_end'])-max(r['first'] or r['end'],state['tts_start'])) for r in rounds)
result=dict(arm=arm,tts=speech,llm_rounds=[dict(seconds=r['end']-r['start'],completion_tokens=r['completion_tokens']) for r in rounds],llm_overlap_seconds=overlap,llm_coverage=overlap/speech['seconds'],thread_affinities={role:[dict(name=n,cpus=c) for n,c in sorted(values)] for role,values in masks.items()},running_cpu_samples=running_cpus)
(stage/(arm+'.json')).write_text(json.dumps(result,indent=2));print(json.dumps(result),flush=True)
finally:stop.set();thread.join(2)
@@ -0,0 +1,117 @@
{
"arm": "matched-exclusive",
"tts": {
"seconds": 23.743657894985517,
"first_pcm_seconds": 0.7674097220005933,
"audio_seconds": 17.76,
"rtf": 1.3369176742672024,
"bytes": 852480,
"packets": 126,
"longest_packet_gap_seconds": 0.4438720670004841,
"required_buffer_after_first_pcm_seconds": 5.395635766985361
},
"llm_rounds": [
{
"seconds": 5.7061521190044004,
"completion_tokens": 512
},
{
"seconds": 5.374325632001273,
"completion_tokens": 512
},
{
"seconds": 5.474937899009092,
"completion_tokens": 512
},
{
"seconds": 5.4010014990053605,
"completion_tokens": 512
},
{
"seconds": 5.133676943019964,
"completion_tokens": 512
}
],
"llm_overlap_seconds": 21.610080538026523,
"llm_coverage": 0.9101411683744993,
"thread_affinities": {
"qwen_tts": [
{
"name": "python",
"cpus": "4-5,10-11"
}
],
"strata": [
{
"name": "cuda-EvtHandlr",
"cpus": "6-9"
},
{
"name": "cuda00001400006",
"cpus": "6-9"
},
{
"name": "strata",
"cpus": "6-9"
},
{
"name": "strata-adapt",
"cpus": "6-9"
},
{
"name": "strata-host",
"cpus": "0"
},
{
"name": "strata-io",
"cpus": "6-9"
},
{
"name": "strata-lookahea",
"cpus": "6-9"
},
{
"name": "strata-pool-0",
"cpus": "1"
},
{
"name": "strata-pool-1",
"cpus": "2"
},
{
"name": "strata-pool-2",
"cpus": "3"
},
{
"name": "strata-stage",
"cpus": "6-9"
},
{
"name": "strata-stdin",
"cpus": "6-9"
},
{
"name": "strata-watchdog",
"cpus": "6-9"
}
]
},
"running_cpu_samples": {
"strata": {
"0": 250,
"1": 254,
"2": 254,
"3": 254,
"6": 25,
"7": 83,
"8": 19,
"9": 8
},
"qwen_tts": {
"4": 209,
"10": 196,
"11": 208,
"5": 185
}
}
}
@@ -0,0 +1,121 @@
{
"arm": "matched-shared",
"tts": {
"seconds": 21.956582993996562,
"first_pcm_seconds": 0.536884569999529,
"audio_seconds": 17.76,
"rtf": 1.2362940874998063,
"bytes": 852480,
"packets": 126,
"longest_packet_gap_seconds": 0.5047344529884867,
"required_buffer_after_first_pcm_seconds": 3.778704298009398
},
"llm_rounds": [
{
"seconds": 5.1832967049849685,
"completion_tokens": 512
},
{
"seconds": 5.291258624987677,
"completion_tokens": 512
},
{
"seconds": 5.315704726002878,
"completion_tokens": 512
},
{
"seconds": 5.303939313016599,
"completion_tokens": 512
},
{
"seconds": 5.165245231008157,
"completion_tokens": 512
}
],
"llm_overlap_seconds": 19.75242526596412,
"llm_coverage": 0.8996128983897399,
"thread_affinities": {
"qwen_tts": [
{
"name": "python",
"cpus": "2-5,8-11"
}
],
"strata": [
{
"name": "cuda-EvtHandlr",
"cpus": "6-9"
},
{
"name": "cuda00001400006",
"cpus": "6-9"
},
{
"name": "strata",
"cpus": "6-9"
},
{
"name": "strata-adapt",
"cpus": "6-9"
},
{
"name": "strata-host",
"cpus": "0"
},
{
"name": "strata-io",
"cpus": "6-9"
},
{
"name": "strata-lookahea",
"cpus": "6-9"
},
{
"name": "strata-pool-0",
"cpus": "1"
},
{
"name": "strata-pool-1",
"cpus": "2"
},
{
"name": "strata-pool-2",
"cpus": "3"
},
{
"name": "strata-stage",
"cpus": "6-9"
},
{
"name": "strata-stdin",
"cpus": "6-9"
},
{
"name": "strata-watchdog",
"cpus": "6-9"
}
]
},
"running_cpu_samples": {
"strata": {
"0": 244,
"1": 243,
"2": 243,
"3": 243,
"9": 7,
"6": 64,
"7": 18,
"8": 16
},
"qwen_tts": {
"5": 29,
"10": 138,
"11": 131,
"4": 166,
"8": 92,
"9": 143,
"3": 1,
"2": 2
}
}
}
@@ -0,0 +1,117 @@
{
"arm": "shared-1",
"tts": {
"seconds": 21.97487347997958,
"first_pcm_seconds": 0.6096372389874887,
"audio_seconds": 17.76,
"rtf": 1.2373239572060573,
"bytes": 852480,
"packets": 133,
"longest_packet_gap_seconds": 0.443657378986245,
"required_buffer_after_first_pcm_seconds": 3.7645343580120247
},
"llm_rounds": [
{
"seconds": 8.477586665016133,
"completion_tokens": 566
},
{
"seconds": 6.108662295999238,
"completion_tokens": 566
},
{
"seconds": 6.029036216990789,
"completion_tokens": 566
},
{
"seconds": 5.958051610010443,
"completion_tokens": 566
}
],
"llm_overlap_seconds": 20.280136793968268,
"llm_coverage": 0.9228784326082552,
"thread_affinities": {
"qwen_tts": [
{
"name": "python",
"cpus": "2-5,8-11"
}
],
"strata": [
{
"name": "cuda-EvtHandlr",
"cpus": "6-9"
},
{
"name": "cuda00001400006",
"cpus": "6-9"
},
{
"name": "strata",
"cpus": "6-9"
},
{
"name": "strata-adapt",
"cpus": "6-9"
},
{
"name": "strata-host",
"cpus": "0"
},
{
"name": "strata-io",
"cpus": "6-9"
},
{
"name": "strata-lookahea",
"cpus": "6-9"
},
{
"name": "strata-pool-0",
"cpus": "1"
},
{
"name": "strata-pool-1",
"cpus": "2"
},
{
"name": "strata-pool-2",
"cpus": "3"
},
{
"name": "strata-stage",
"cpus": "6-9"
},
{
"name": "strata-stdin",
"cpus": "6-9"
},
{
"name": "strata-watchdog",
"cpus": "6-9"
}
]
},
"running_cpu_samples": {
"strata": {
"0": 246,
"1": 248,
"2": 248,
"3": 248,
"6": 43,
"8": 31,
"7": 42,
"9": 19
},
"qwen_tts": {
"9": 100,
"11": 87,
"10": 140,
"2": 1,
"5": 126,
"4": 129,
"8": 108,
"3": 1
}
}
}
@@ -0,0 +1,112 @@
{
"arm": "shared-2",
"tts": {
"seconds": 21.12998080998659,
"first_pcm_seconds": 0.5687970180006232,
"audio_seconds": 17.76,
"rtf": 1.1897511717334792,
"bytes": 852480,
"packets": 144,
"longest_packet_gap_seconds": 0.4439345129940193,
"required_buffer_after_first_pcm_seconds": 2.9201214499957864
},
"llm_rounds": [
{
"seconds": 6.088351852988126,
"completion_tokens": 566
},
{
"seconds": 6.236085355019895,
"completion_tokens": 566
},
{
"seconds": 10.668124029994942,
"completion_tokens": 1024
}
],
"llm_overlap_seconds": 19.980737588979537,
"llm_coverage": 0.9456107778165188,
"thread_affinities": {
"qwen_tts": [
{
"name": "python",
"cpus": "2-5,8-11"
}
],
"strata": [
{
"name": "cuda-EvtHandlr",
"cpus": "6-9"
},
{
"name": "cuda00001400006",
"cpus": "6-9"
},
{
"name": "strata",
"cpus": "6-9"
},
{
"name": "strata-adapt",
"cpus": "6-9"
},
{
"name": "strata-host",
"cpus": "0"
},
{
"name": "strata-io",
"cpus": "6-9"
},
{
"name": "strata-lookahea",
"cpus": "6-9"
},
{
"name": "strata-pool-0",
"cpus": "1"
},
{
"name": "strata-pool-1",
"cpus": "2"
},
{
"name": "strata-pool-2",
"cpus": "3"
},
{
"name": "strata-stage",
"cpus": "6-9"
},
{
"name": "strata-stdin",
"cpus": "6-9"
},
{
"name": "strata-watchdog",
"cpus": "6-9"
}
]
},
"running_cpu_samples": {
"strata": {
"0": 210,
"1": 213,
"2": 213,
"3": 213,
"8": 13,
"7": 37,
"9": 1,
"6": 59
},
"qwen_tts": {
"9": 167,
"4": 125,
"5": 68,
"10": 100,
"8": 103,
"11": 110,
"3": 2
}
}
}