From c3bb09cc50c06ea990cf89fa72265d1a98283254 Mon Sep 17 00:00:00 2001 From: Manan17 Date: Mon, 16 Mar 2026 09:43:18 +0000 Subject: [PATCH] gpt comments --- studio/backend/core/inference/audio_codecs.py | 6 ++++++ studio/backend/core/inference/llama_cpp.py | 11 +++++++++++ studio/backend/routes/inference.py | 12 ++++-------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/studio/backend/core/inference/audio_codecs.py b/studio/backend/core/inference/audio_codecs.py index f033e6c77c..bcf3ec2937 100644 --- a/studio/backend/core/inference/audio_codecs.py +++ b/studio/backend/core/inference/audio_codecs.py @@ -311,10 +311,16 @@ class AudioCodecManager: ) -> Tuple[bytes, int]: """Unified decode — dispatches to the right codec decoder.""" if audio_type == "snac": + if not token_ids: + raise ValueError("SNAC decoding requires token_ids") return self.decode_snac(torch.tensor([token_ids], dtype = torch.long), device) elif audio_type == "bicodec": + if not text: + raise ValueError("BiCodec decoding requires text") return self.decode_bicodec(text, device) elif audio_type == "dac": + if not text: + raise ValueError("DAC decoding requires text") return self.decode_dac(text, device) raise ValueError(f"Cannot decode audio_type: {audio_type}") diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.py index 7a4ebe80d4..12b2495834 100644 --- a/studio/backend/core/inference/llama_cpp.py +++ b/studio/backend/core/inference/llama_cpp.py @@ -732,8 +732,17 @@ class LlamaCppBackend: self._hf_repo = None self._hf_variant = None self._is_vision = False + self._is_audio = False + self._audio_type = None self._port = None self._healthy = False + # Free audio codec GPU memory + if LlamaCppBackend._codec_mgr is not None: + LlamaCppBackend._codec_mgr.unload() + LlamaCppBackend._codec_mgr = None + import torch + if torch.cuda.is_available(): + torch.cuda.empty_cache() return True def _kill_process(self): @@ -1079,6 +1088,7 @@ class LlamaCppBackend: temperature: float = 0.6, top_p: float = 0.95, top_k: int = 50, + min_p: float = 0.0, max_new_tokens: int = 2048, repetition_penalty: float = 1.1, ) -> tuple: @@ -1098,6 +1108,7 @@ class LlamaCppBackend: "temperature": temperature, "top_p": top_p, "top_k": top_k if top_k >= 0 else 0, + "min_p": min_p, "repeat_penalty": repetition_penalty, } if stop: diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.py index f7bd017dba..2d4e3a609b 100644 --- a/studio/backend/routes/inference.py +++ b/studio/backend/routes/inference.py @@ -159,9 +159,7 @@ async def load_model( from utils.models import is_audio_input_type _gguf_audio = llama_backend.detect_audio_type() - _gguf_is_audio = _gguf_audio is not None and _gguf_audio not in ( - "audio_vlm", - ) + _gguf_is_audio = _gguf_audio in ("snac", "bicodec", "dac") llama_backend._is_audio = _gguf_is_audio llama_backend._audio_type = _gguf_audio if _gguf_is_audio: @@ -547,11 +545,9 @@ async def generate_audio( if llama_backend.is_loaded and getattr(llama_backend, "_is_audio", False): model_name = llama_backend.model_identifier gen = lambda: llama_backend.generate_audio_response( - text = text, - audio_type = llama_backend._audio_type, - temperature = payload.temperature, - top_p = payload.top_p, - top_k = payload.top_k, + text = text, audio_type = llama_backend._audio_type, + temperature = payload.temperature, top_p = payload.top_p, + top_k = payload.top_k, min_p = payload.min_p, max_new_tokens = payload.max_tokens or 2048, repetition_penalty = payload.repetition_penalty, )