Shao

Backend Overview

中文 English

This backend is split into three files:

The design is intentionally two-layered:

Request Flow

One frontend request goes through this path:

  1. The frontend sends POST /generate to backend_api.py.
  2. The API normalizes the request, cleans lyrics, creates a job, and either dispatches it immediately or puts it into the queue.
  3. The API sends the worker payload to one or more workers through POST /generate.
  4. backend_worker.py loads or reuses the tokenizer and models, then runs:
    • prompt preparation
    • backbone generation
    • super-resolution
    • decoder waveform reconstruction
    • MP3 export
  5. The worker writes output files under backend/generated_audio/ and returns filenames plus metadata.
  6. The API downloads the generated files from the worker, stores them in memory for the job result, and exposes them through /job/{job_id} and /job/{job_id}/track/{track_idx}/mp3|wav.

File Roles

run_backend.sh

This is the entry point for local or containerized deployment.

It is responsible for:

Important launch controls include:

backend_api.py

This file is the frontend-facing orchestration layer.

It is responsible for:

It does not perform GPU inference itself.

backend_worker.py

This file is the single-GPU inference runtime.

It is responsible for:

Runtime strategy:

How To Run

From the backend directory:

cd backend
bash run_backend.sh

Default behavior:

Common advanced examples:

bash run_backend.sh --gpus 0
bash run_backend.sh --gpus 0,1
bash run_backend.sh --gpus 0,1 --runtime-mode keep_loaded

Stop all backend processes:

bash run_backend.sh stop

Logs

Logs are written to:

Useful commands:

tail -f backend/logs/api.log
tail -f backend/logs/worker_0.log

Output Files

Generated files are written under:

Each request writes:

Common Configuration Changes

Change how many GPUs are used

Pass --gpus to run_backend.sh:

bash run_backend.sh --gpus 0
bash run_backend.sh --gpus 0,1
bash run_backend.sh --gpus 6,7

One worker is started per GPU id. The worker count is derived automatically from the number of ids you provide.

Change runtime mode

Pass --runtime-mode to run_backend.sh:

bash run_backend.sh --runtime-mode one_shot
bash run_backend.sh --runtime-mode keep_loaded

Guidance:

Change ports

Edit these values in run_backend.sh:

Change model checkpoints or tokenizer paths

Edit these values in backend_worker.py:

The public model names exposed by /config are intentionally generic:

Health And Debugging

Worker health

Each worker exposes:

The API polls /health to decide whether a worker is idle, busy, or offline.

If the frontend is stuck on generating

Check these first:

  1. backend/logs/api.log
  2. backend/logs/worker_0.log
  3. GET /status
  4. GET /job/{job_id}

If the worker fails during startup

Common causes:

If generated files are missing

Check: