Spaces:
Running
Running
fix adapter save path, smart LM fallback, compact training UI, remove Server Status
Browse filesFiles changed (2)
- app.py+22-35
- train_engine.py+6-9
670 unmodified lines6716726736746756766776786798 unmodified lines688689690688691692693694229 unmodified lines9249259269249259279269289299303 unmodified lines9349359369369379389399409419429379389399409479489499509519529419549559569579589429439449459469479489499609509519529539549559564 unmodified lines961962963971972973974975976977978979980981982964965966967968969970971972670 unmodified lines full_path, timeout=600, cancel_check=lambda: _training_cancel.is_set(), ) if not caption_data: use_understand = False _log(f" {audio_fname}: GGUF LM too slow, switching to librosa for remaining files") if caption_data: bpm_s = caption_data.get("bpm", "?") key_s = caption_data.get("keyscale", caption_data.get("key", "?"))8 unmodified lines fallback = {"caption": "", "bpm": bpm_val, "key": "", "signature": "", "lyrics": ""} with open(sidecar_json, "w") as cj: json.dump(fallback, cj) _log(f" {audio_fname}: librosa fallback BPM={bpm_val}") _log(f" {audio_fname}: librosa BPM={bpm_val}") except Exception as cap_exc: _log(f" {audio_fname}: caption failed: {cap_exc}") yield _log_text(), gr.Button(visible=False), gr.Button(visible=True), gr.File()229 unmodified lines value=DEFAULT_LM, scale=1, )
with gr.Row(elem_classes="compact-row"): gen_btn = gr.Button("Generate Music", variant="primary", scale=2) gen_btn = gr.Button("Generate Music", variant="primary") status_btn = gr.Button("Server Status", scale=1)
gen_btn.click( fn=generate_music,3 unmodified lines api_name="generate", )
status_btn.click( fn=get_server_status, inputs=[], outputs=[status], api_name="server_status", )
# ============================================================ # Tab 2: Train LoRA # ============================================================ with gr.Tab("Train LoRA"): gr.Markdown( "### LoRA Training\n" "Fine-tune ACE-Step on your audio. " "CPU training is slow -- ace-server stops during training." )
with gr.Row(elem_classes="compact-row"): with gr.Column(scale=2): train_audio = gr.File( label="Training Audio + Caption Files", file_count="multiple", file_types=["audio", ".txt", ".json"], with gr.Column(scale=3): train_log = gr.Textbox( label="Training Log", interactive=False, lines=12, elem_classes="status-box", ) train_output_file = gr.File(label="Trained LoRA (download)", visible=False) with gr.Column(scale=1): with gr.Column(scale=2): with gr.Row(elem_classes="compact-row"): train_btn = gr.Button("Train", variant="primary", scale=2) cancel_btn = gr.Button("Cancel Training", variant="stop", visible=False, scale=1) lora_name = gr.Textbox(label="LoRA Name", value="my-lora") train_epochs = gr.Slider( label="Epochs", minimum=1, maximum=1000,4 unmodified lines label="Rank (r)", minimum=1, maximum=128, value=32, step=1, )
with gr.Row(elem_classes="compact-row"): train_btn = gr.Button("Train", variant="primary", scale=2) cancel_btn = gr.Button("Cancel Training", variant="stop", visible=False, scale=1)
train_output_file = gr.File(label="Trained LoRA (download)", visible=False) train_log = gr.Textbox( label="Training Log", interactive=False, lines=10, elem_classes="status-box", ) train_audio = gr.File( label="Training Audio (optional caption .txt)", file_count="multiple", file_types=["audio", ".txt", ".json"], height=120, )
# Button swap on click (separate handler, like rvc-beatrice) # This fires immediately so user sees Cancel even if training2538 unmodified lines2539254025412542254225442545254325442545254625475 unmodified lines255325542555255725562559256025572558255925602561157 unmodified lines27192720272127242722272327262724272827252726272727282538 unmodified lines if _training_cancel.is_set(): _training_cancel.clear() if epoch > start_epoch: early_path = str(out_path / "early_exit") model.decoder.eval() save_lora_adapter(model, early_path) yield f"[OK] Cancelled at epoch {epoch + 1}, saved to {early_path}" save_lora_adapter(model, str(out_path)) yield f"[OK] Cancelled at epoch {epoch + 1}, adapter saved" else: yield f"[CANCELLED] Stopped before any epoch completed" yield "[DONE]"5 unmodified lines # Timeout check elapsed = time.time() - train_start if elapsed > MAX_TRAINING_TIME: early_path = str(out_path / "timeout_exit") model.decoder.eval() save_lora_adapter(model, early_path) yield f"[WARN] Training timed out after {int(elapsed)}s, saved to {early_path}" save_lora_adapter(model, str(out_path)) yield f"[WARN] Training timed out after {int(elapsed)}s, adapter saved" yield "[DONE]" _cuda_sync(device) unload_models(model)157 unmodified lines f"Loss: {avg_epoch_loss:.4f}{best_str}" )
# Save best # Save best (directly to output dir so ace-server finds it) if is_best and epoch + 1 >= 10: best_path = str(out_path / "best") model.decoder.eval() save_lora_adapter(model, best_path) save_lora_adapter(model, str(out_path)) model.decoder.train() yield f"[OK] Best model saved (epoch {epoch + 1}, loss: {best_loss:.4f})"
app.py+22-35
train_engine.py+6-9