Add GPU distribution and sampling controls to chat profiles

This commit is contained in:
Mikei386
2026-09-28 19:51:49 +02:00
parent e2b521fcaa
commit 8d03a9a979
4 changed files with 68 additions and 9 deletions
+18 -3
View File
@@ -7,11 +7,24 @@ import uuid
from pathlib import Path
SCHEMAS={
'chat':{'context':(512,2097152,8192),'slots':(1,16,1),'threads':(1,256,6),'batch':(1,8192,512),'ubatch':(1,8192,128)},
'chat':{'context':(512,2097152,8192),'slots':(1,16,1),'threads':(1,256,6),'batch':(1,8192,512),'ubatch':(1,8192,128),'temperature':(0,5,.8),'top_p':(0,1,.95),'top_k':(0,1000,40)},
'image':{'width':(256,2048,1024),'height':(256,2048,1024),'steps':(1,100,25),'seed':(-1,2147483647,-1),'guidance':(0,30,1)},
'audio':{'speed':(.25,4,1)},
'video':{'width':(256,1920,768),'height':(256,1088,512),'frames':(1,241,33),'fps':(1,60,24),'steps':(1,100,20),'seed':(-1,2147483647,-1)}
}
CHAT_GPU_DEFAULTS={'gpu_devices':[], 'split_mode':'none', 'tensor_split':[]}
CHAT_SAMPLING={'temperature':.8,'top_p':.95,'top_k':40}
def chat_parameters(params):
params={**CHAT_GPU_DEFAULTS,**CHAT_SAMPLING,**params}
devices=params['gpu_devices'];split=params['tensor_split']
if not isinstance(devices,list) or len(devices)>16 or any(not isinstance(v,str) or not re.fullmatch(r'GPU-[0-9a-fA-F-]{36}',v) for v in devices) or len(set(devices))!=len(devices):raise ValueError('GPUs müssen als eindeutige, geordnete GPU-UUIDs angegeben werden.')
if params['split_mode'] not in ('none','layer','row'):raise ValueError('Ungültiger GPU-Split-Modus.')
if not isinstance(split,list) or any(isinstance(v,bool) or not isinstance(v,(int,float)) or not 0<v<=100 for v in split):raise ValueError('GPU-Verteilung: positive Gewichte bis 100 verwenden.')
if split and (len(split)!=len(devices) or len(devices)<2 or params['split_mode']=='none'):raise ValueError('GPU-Verteilung benötigt mehrere ausgewählte GPUs und einen Split-Modus; je GPU einen Wert angeben.')
if len(devices)>1 and params['split_mode']=='none':raise ValueError('Bei mehreren GPUs Layer- oder Row-Split auswählen.')
return params
# Explicit model-card recipe. This is a source recommendation, not a runtime test.
QWEN_REPO='abenzerps/Qwen-Image-2.1-Uncensored-GGUF'
QWEN_COMPONENTS={
@@ -27,6 +40,7 @@ class Profiles:
with self.lock:
rows=json.loads(json.dumps(self.rows))
for p in rows:
if p['kind']=='chat':p['parameters']={**CHAT_GPU_DEFAULTS,**CHAT_SAMPLING,**p['parameters']}
try:
p['model']=self.catalog.entry(p['model_id'])
p['blockers']=['Für dieses Profil ist noch kein ausführbarer Worker angebunden.']
@@ -47,10 +61,11 @@ class Profiles:
model=self.catalog.entry(data['model_id'])
if model['repo']==QWEN_REPO and any(model['file'] in r['files'] for r in QWEN_COMPONENTS.values()):raise ValueError('Textencoder und VAE werden über Komponenten zugeordnet, nicht als Hauptmodell.')
if model['kind']!=kind or not model['profile_eligible']:raise ValueError('Eine Gewichtsdatei dieses Bereichs auswählen, keine Konfiguration.')
if not isinstance(params,dict) or set(params)!=set(SCHEMAS[kind]):raise ValueError('Unvollständige oder unbekannte Profilparameter.')
if kind=='chat' and isinstance(params,dict):params=chat_parameters(params)
if not isinstance(params,dict) or set(params)!=(set(SCHEMAS[kind]) | (set(CHAT_GPU_DEFAULTS) if kind=='chat' else set())):raise ValueError('Unvollständige oder unbekannte Profilparameter.')
for key,(lo,hi,_) in SCHEMAS[kind].items():
value=params[key]
floating=key in ('guidance','speed')
floating=key in ('guidance','speed','temperature','top_p')
if isinstance(value,bool) or not isinstance(value,(float,int) if floating else int) or not lo<=value<=hi:raise ValueError('Ungültiger Parameter: '+key)
if kind in ('image','video') and (params['width']%64 or params['height']%64):raise ValueError('Breite und Höhe müssen durch 64 teilbar sein.')
if kind=='chat' and params['ubatch']>params['batch']:raise ValueError('Microbatch darf nicht größer als Batch sein.')