Add protocol performance profiles

This commit is contained in:
2026-09-12 11:50:30 +02:00
parent e2a0434941
commit 77be2b39ff
8 changed files with 131 additions and 1 deletions
+5
View File
@@ -16,6 +16,7 @@ import yaml
from mka.application.config import AppSettings
from mka.application.glossary import GlossaryRepository, render_glossary_terms
from mka.application.performance import DEFAULT_PERFORMANCE_PROFILE, resolve_ollama_num_thread
STAGES = ("preparing", "transcription", "diarization", "protocol_generation")
@@ -65,6 +66,7 @@ class ParticipantInput:
class ProcessingOptions:
diarization_enabled: bool = False
audio_normalization: bool = True
performance_profile: str = DEFAULT_PERFORMANCE_PROFILE
@dataclass(frozen=True)
@@ -229,6 +231,7 @@ class MeetingProcessingService:
"model": self.settings.protocol_model,
"ollama_endpoint": self.settings.ollama_endpoint,
"protocol_num_ctx": self.settings.protocol_num_ctx,
"protocol_num_thread": resolve_ollama_num_thread(options.performance_profile),
"protocol_safe_input_token_budget": (
self.settings.protocol_safe_input_token_budget
),
@@ -357,6 +360,7 @@ class MeetingProcessingService:
run_dir: Path,
speaker_mappings: dict[str, str],
progress_sink: Callable[[AppProgressEvent], None] | None = None,
performance_profile: str = DEFAULT_PERFORMANCE_PROFILE,
) -> ProcessingOutcome:
"""Persist confirmed mappings and regenerate only the direct protocol."""
review = self.load_speaker_mapping_review(run_dir)
@@ -401,6 +405,7 @@ class MeetingProcessingService:
model=self.settings.protocol_model,
ollama_endpoint=self.settings.ollama_endpoint,
protocol_num_ctx=self.settings.protocol_num_ctx,
protocol_num_thread=resolve_ollama_num_thread(performance_profile),
protocol_safe_input_token_budget=(self.settings.protocol_safe_input_token_budget),
)
protocol_path = Path(result.protocol_path)
+23
View File
@@ -0,0 +1,23 @@
"""Abstract performance profiles resolved to current backend runtime options."""
from __future__ import annotations
DEFAULT_PERFORMANCE_PROFILE = "auto"
PERFORMANCE_PROFILES = ("auto", "fast", "efficient", "powersave")
_OLLAMA_THREADS_BY_PROFILE = {
"fast": 16,
"efficient": 10,
"powersave": 4,
}
def resolve_ollama_num_thread(profile: str) -> int | None:
"""Resolve a profile, leaving automatic thread selection to Ollama for Auto."""
if profile == "auto":
return None
try:
return _OLLAMA_THREADS_BY_PROFILE[profile]
except KeyError as exc:
allowed = ", ".join(PERFORMANCE_PROFILES)
raise ValueError(f"Unknown performance profile {profile!r}; expected: {allowed}.") from exc
+16 -1
View File
@@ -34,6 +34,7 @@ from mka.application.people_yaml import (
export_people_yaml,
import_people_yaml,
)
from mka.application.performance import DEFAULT_PERFORMANCE_PROFILE, PERFORMANCE_PROFILES
from mka.application.run_inputs import (
RunInputJsonError,
RunInputState,
@@ -495,7 +496,13 @@ def _render_result() -> None:
):
try:
with st.spinner("Regenerating protocol without rerunning audio processing..."):
regenerated = service.regenerate_protocol(outcome.run_dir, selections)
regenerated = service.regenerate_protocol(
outcome.run_dir,
selections,
performance_profile=st.session_state.get(
"performance_profile", DEFAULT_PERFORMANCE_PROFILE
),
)
except (OSError, RuntimeError, ValueError) as exc:
st.error(f"Protocol regeneration failed: {exc}")
else:
@@ -551,6 +558,13 @@ def main() -> None:
participants = _render_participants()
st.header("Processing options")
performance_profile = st.selectbox(
"Performance profile",
options=PERFORMANCE_PROFILES,
format_func=str.title,
key="performance_profile",
help="Controls protocol-generation performance using an abstract runtime profile.",
)
audio_normalization = st.checkbox(
"Audio normalization",
value=True,
@@ -619,6 +633,7 @@ def main() -> None:
ProcessingOptions(
diarization_enabled=diarization_enabled,
audio_normalization=audio_normalization,
performance_profile=performance_profile,
),
progress_sink=callback,
)