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 lines6716726736746756768 unmodified lines685686687688689690691229 unmodified lines9219229239249259269279289293 unmodified lines9339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629634 unmodified lines968969970971972973974975976977978979980981982983984985670 unmodified linesfull_path, timeout=600,cancel_check=lambda: _training_cancel.is_set(),)if caption_data:bpm_s = caption_data.get("bpm", "?")key_s = caption_data.get("keyscale", caption_data.get("key", "?"))8 unmodified linesfallback = {"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}")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 linesvalue=DEFAULT_LM, scale=1,)with gr.Row(elem_classes="compact-row"):gen_btn = gr.Button("Generate Music", variant="primary", scale=2)status_btn = gr.Button("Server Status", scale=1)gen_btn.click(fn=generate_music,3 unmodified linesapi_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=1):lora_name = gr.Textbox(label="LoRA Name", value="my-lora")train_epochs = gr.Slider(label="Epochs", minimum=1, maximum=1000,4 unmodified lineslabel="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",)# Button swap on click (separate handler, like rvc-beatrice)# This fires immediately so user sees Cancel even if training670 unmodified lines6716726736746756766776786798 unmodified lines688689690691692693694229 unmodified lines9249259269279289299303 unmodified lines9349359369379389399409419429439449459469479489499509519529539549559564 unmodified lines961962963964965966967968969970971972670 unmodified linesfull_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 linesfallback = {"caption": "", "bpm": bpm_val, "key": "", "signature": "", "lyrics": ""}with open(sidecar_json, "w") as cj:json.dump(fallback, cj)_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 linesvalue=DEFAULT_LM, scale=1,)gen_btn = gr.Button("Generate Music", variant="primary")gen_btn.click(fn=generate_music,3 unmodified linesapi_name="generate",)# ============================================================# Tab 2: Train LoRA# ============================================================with gr.Tab("Train LoRA"):with gr.Row(elem_classes="compact-row"):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=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 lineslabel="Rank (r)", minimum=1, maximum=128,value=32, step=1,)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 training
2538 unmodified lines25392540254125422543254425452546254725485 unmodified lines2554255525562557255825592560256125622563157 unmodified lines272127222723272427252726272727282729273027312538 unmodified linesif _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}"else:yield f"[CANCELLED] Stopped before any epoch completed"yield "[DONE]"5 unmodified lines# Timeout checkelapsed = time.time() - train_startif 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}"yield "[DONE]"_cuda_sync(device)unload_models(model)157 unmodified linesf"Loss: {avg_epoch_loss:.4f}{best_str}")# Save bestif is_best and epoch + 1 >= 10:best_path = str(out_path / "best")model.decoder.eval()save_lora_adapter(model, best_path)model.decoder.train()yield f"[OK] Best model saved (epoch {epoch + 1}, loss: {best_loss:.4f})"2538 unmodified lines2539254025412542254325442545254625475 unmodified lines255325542555255625572558255925602561157 unmodified lines27192720272127222723272427252726272727282538 unmodified linesif _training_cancel.is_set():_training_cancel.clear()if epoch > start_epoch:model.decoder.eval()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 checkelapsed = time.time() - train_startif elapsed > MAX_TRAINING_TIME:model.decoder.eval()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 linesf"Loss: {avg_epoch_loss:.4f}{best_str}")# Save best (directly to output dir so ace-server finds it)if is_best and epoch + 1 >= 10:model.decoder.eval()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