Spaces:
Running
Running
Fix Zero GPU runtime: duration 60s, test fixes, LoKr PeftModel guard
Browse files
acestep/core/generation/handler/lora/lifecycle.py
CHANGED
|
@@ -176,7 +176,7 @@ def add_lora(self, lora_path: str, adapter_name: str | None = None) -> str:
|
|
| 176 |
|
| 177 |
try:
|
| 178 |
decoder = self.model.decoder
|
| 179 |
-
is_peft = isinstance(decoder, PeftModel)
|
| 180 |
|
| 181 |
if not is_peft:
|
| 182 |
# First LoRA: backup base once, then wrap with PEFT
|
|
|
|
| 176 |
|
| 177 |
try:
|
| 178 |
decoder = self.model.decoder
|
| 179 |
+
is_peft = PeftModel is not None and isinstance(decoder, PeftModel)
|
| 180 |
|
| 181 |
if not is_peft:
|
| 182 |
# First LoRA: backup base once, then wrap with PEFT
|
acestep/core/generation/handler/lora/lifecycle_test.py
CHANGED
|
@@ -55,6 +55,10 @@ class _DummyHandler:
|
|
| 55 |
last_scale_report={},
|
| 56 |
)
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
def _ensure_lora_registry(self):
|
| 59 |
"""Satisfy lifecycle hook without side effects."""
|
| 60 |
return None
|
|
@@ -99,7 +103,8 @@ class LifecycleTests(unittest.TestCase):
|
|
| 99 |
with patch("acestep.core.generation.handler.lora.lifecycle._load_lokr_adapter") as mock_load_lokr:
|
| 100 |
message = lifecycle.load_lora(handler, str(adapter_dir))
|
| 101 |
|
| 102 |
-
self.
|
|
|
|
| 103 |
mock_load_lokr.assert_called_once_with(handler.model.decoder, str(weights))
|
| 104 |
|
| 105 |
def test_load_lora_invalid_adapter_message_mentions_lokr(self):
|
|
|
|
| 55 |
last_scale_report={},
|
| 56 |
)
|
| 57 |
|
| 58 |
+
def add_lora(self, lora_path: str, adapter_name: str | None = None) -> str:
|
| 59 |
+
"""Delegate to lifecycle mixin so load_lora can call self.add_lora."""
|
| 60 |
+
return lifecycle.add_lora(self, lora_path, adapter_name)
|
| 61 |
+
|
| 62 |
def _ensure_lora_registry(self):
|
| 63 |
"""Satisfy lifecycle hook without side effects."""
|
| 64 |
return None
|
|
|
|
| 103 |
with patch("acestep.core.generation.handler.lora.lifecycle._load_lokr_adapter") as mock_load_lokr:
|
| 104 |
message = lifecycle.load_lora(handler, str(adapter_dir))
|
| 105 |
|
| 106 |
+
self.assertTrue(message.startswith("✅ LoRA "), f"Expected success message, got: {message}")
|
| 107 |
+
self.assertIn(str(adapter_dir), message)
|
| 108 |
mock_load_lokr.assert_called_once_with(handler.model.decoder, str(weights))
|
| 109 |
|
| 110 |
def test_load_lora_invalid_adapter_message_mentions_lokr(self):
|
acestep/gradio_ui/events/generation_handlers_test.py
CHANGED
|
@@ -45,7 +45,8 @@ class GenerationHandlersTests(unittest.TestCase):
|
|
| 45 |
constrained_decoding_debug=False,
|
| 46 |
)
|
| 47 |
|
| 48 |
-
|
|
|
|
| 49 |
understand_music_mock.assert_not_called()
|
| 50 |
warning_mock.assert_called_once()
|
| 51 |
|
|
@@ -110,6 +111,7 @@ class GenerationHandlersTests(unittest.TestCase):
|
|
| 110 |
|
| 111 |
llm_handler = MagicMock()
|
| 112 |
llm_handler.llm_initialized = True
|
|
|
|
| 113 |
|
| 114 |
# Test with current_batch_size = 5
|
| 115 |
result = generation_handlers.init_service_wrapper(
|
|
@@ -166,6 +168,7 @@ class GenerationHandlersTests(unittest.TestCase):
|
|
| 166 |
|
| 167 |
llm_handler = MagicMock()
|
| 168 |
llm_handler.llm_initialized = True
|
|
|
|
| 169 |
|
| 170 |
# Test with current_batch_size = None (should default to 2)
|
| 171 |
result = generation_handlers.init_service_wrapper(
|
|
|
|
| 45 |
constrained_decoding_debug=False,
|
| 46 |
)
|
| 47 |
|
| 48 |
+
expected_status = "Source file is not valid audio or conversion failed (no audio codes detected)."
|
| 49 |
+
self.assertEqual(result, ("", expected_status, "", "", None, None, "", "", "", False))
|
| 50 |
understand_music_mock.assert_not_called()
|
| 51 |
warning_mock.assert_called_once()
|
| 52 |
|
|
|
|
| 111 |
|
| 112 |
llm_handler = MagicMock()
|
| 113 |
llm_handler.llm_initialized = True
|
| 114 |
+
llm_handler.initialize.return_value = ("Success", True)
|
| 115 |
|
| 116 |
# Test with current_batch_size = 5
|
| 117 |
result = generation_handlers.init_service_wrapper(
|
|
|
|
| 168 |
|
| 169 |
llm_handler = MagicMock()
|
| 170 |
llm_handler.llm_initialized = True
|
| 171 |
+
llm_handler.initialize.return_value = ("Success", True)
|
| 172 |
|
| 173 |
# Test with current_batch_size = None (should default to 2)
|
| 174 |
result = generation_handlers.init_service_wrapper(
|
acestep/gradio_ui/help_content_test.py
CHANGED
|
@@ -17,7 +17,7 @@ import json
|
|
| 17 |
import os
|
| 18 |
import sys
|
| 19 |
import unittest
|
| 20 |
-
from unittest.mock import MagicMock
|
| 21 |
|
| 22 |
# ---------------------------------------------------------------------------
|
| 23 |
# Pre-mock gradio so the acestep.gradio_ui package __init__.py
|
|
@@ -215,33 +215,29 @@ class I18nHelpKeysTests(unittest.TestCase):
|
|
| 215 |
# ---------------------------------------------------------------------------
|
| 216 |
# create_help_button (Gradio is mocked)
|
| 217 |
# ---------------------------------------------------------------------------
|
|
|
|
| 218 |
class CreateHelpButtonTests(unittest.TestCase):
|
| 219 |
"""Tests for create_help_button with mocked Gradio."""
|
| 220 |
|
| 221 |
-
def test_create_help_button_calls_gr_html(self):
|
| 222 |
"""create_help_button should call gr.HTML and return the result."""
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
mock_html = MagicMock()
|
| 226 |
-
gr.HTML.return_value = mock_html
|
| 227 |
|
| 228 |
result = create_help_button("getting_started")
|
| 229 |
|
| 230 |
-
|
| 231 |
-
self.assertEqual(result,
|
| 232 |
|
| 233 |
-
def test_create_help_button_html_contains_modal(self):
|
| 234 |
"""The generated HTML should contain modal markup."""
|
| 235 |
-
import gradio as gr
|
| 236 |
-
|
| 237 |
-
# Capture the value= kwarg passed to gr.HTML
|
| 238 |
captured = {}
|
| 239 |
|
| 240 |
-
def
|
| 241 |
captured.update(kwargs)
|
| 242 |
return MagicMock()
|
| 243 |
|
| 244 |
-
|
| 245 |
create_help_button("getting_started")
|
| 246 |
|
| 247 |
html_value = captured.get("value", "")
|
|
|
|
| 17 |
import os
|
| 18 |
import sys
|
| 19 |
import unittest
|
| 20 |
+
from unittest.mock import MagicMock, patch
|
| 21 |
|
| 22 |
# ---------------------------------------------------------------------------
|
| 23 |
# Pre-mock gradio so the acestep.gradio_ui package __init__.py
|
|
|
|
| 215 |
# ---------------------------------------------------------------------------
|
| 216 |
# create_help_button (Gradio is mocked)
|
| 217 |
# ---------------------------------------------------------------------------
|
| 218 |
+
@patch("acestep.gradio_ui.help_content.gr.HTML")
|
| 219 |
class CreateHelpButtonTests(unittest.TestCase):
|
| 220 |
"""Tests for create_help_button with mocked Gradio."""
|
| 221 |
|
| 222 |
+
def test_create_help_button_calls_gr_html(self, mock_html_cls):
|
| 223 |
"""create_help_button should call gr.HTML and return the result."""
|
| 224 |
+
mock_html_instance = MagicMock()
|
| 225 |
+
mock_html_cls.return_value = mock_html_instance
|
|
|
|
|
|
|
| 226 |
|
| 227 |
result = create_help_button("getting_started")
|
| 228 |
|
| 229 |
+
mock_html_cls.assert_called_once()
|
| 230 |
+
self.assertEqual(result, mock_html_instance)
|
| 231 |
|
| 232 |
+
def test_create_help_button_html_contains_modal(self, mock_html_cls):
|
| 233 |
"""The generated HTML should contain modal markup."""
|
|
|
|
|
|
|
|
|
|
| 234 |
captured = {}
|
| 235 |
|
| 236 |
+
def capture_call(*args, **kwargs):
|
| 237 |
captured.update(kwargs)
|
| 238 |
return MagicMock()
|
| 239 |
|
| 240 |
+
mock_html_cls.side_effect = capture_call
|
| 241 |
create_help_button("getting_started")
|
| 242 |
|
| 243 |
html_value = captured.get("value", "")
|
acestep/inference.py
CHANGED
|
@@ -20,7 +20,7 @@ from acestep.audio_utils import AudioSaver, generate_uuid_from_params, normalize
|
|
| 20 |
# HuggingFace Space environment detection
|
| 21 |
IS_HUGGINGFACE_SPACE = os.environ.get("SPACE_ID") is not None
|
| 22 |
|
| 23 |
-
def _get_spaces_gpu_decorator(duration=
|
| 24 |
"""
|
| 25 |
Get the @spaces.GPU decorator if running in HuggingFace Space environment.
|
| 26 |
Returns identity decorator if not in Space environment.
|
|
@@ -307,7 +307,7 @@ def _update_metadata_from_lm(
|
|
| 307 |
return bpm, key_scale, time_signature, audio_duration, vocal_language, caption, lyrics
|
| 308 |
|
| 309 |
|
| 310 |
-
@_get_spaces_gpu_decorator(duration=
|
| 311 |
def generate_music(
|
| 312 |
dit_handler,
|
| 313 |
llm_handler,
|
|
|
|
| 20 |
# HuggingFace Space environment detection
|
| 21 |
IS_HUGGINGFACE_SPACE = os.environ.get("SPACE_ID") is not None
|
| 22 |
|
| 23 |
+
def _get_spaces_gpu_decorator(duration=60):
|
| 24 |
"""
|
| 25 |
Get the @spaces.GPU decorator if running in HuggingFace Space environment.
|
| 26 |
Returns identity decorator if not in Space environment.
|
|
|
|
| 307 |
return bpm, key_scale, time_signature, audio_duration, vocal_language, caption, lyrics
|
| 308 |
|
| 309 |
|
| 310 |
+
@_get_spaces_gpu_decorator(duration=60)
|
| 311 |
def generate_music(
|
| 312 |
dit_handler,
|
| 313 |
llm_handler,
|