Documentation

Optional recommendations module

MERT runs audio analysis on your own GPU for radio, mixes, and the library map. The default deployment supports library browsing, playback, history, favourites, uploads, and CPU audio analysis with recommendations disabled.

Enable or disable with the server manager

Use the manager to enable the module:

./caimack.sh recommendations on

The manager picks the GPU configuration and validates it before starting the module. See Automatic GPU selection and AMD for overrides and host requirements. Use ./caimack.sh recommendations off to disable the module. Reload the web app or reopen Android after toggling recommendations. Cached weights and embeddings stay on disk.

Manual Compose setup

On a host with NVIDIA support, add the recommendation module after the base and image files.

docker compose -f docker-compose.yml -f docker-compose.images.yml -f docker-compose.recommendations.yml pull
docker compose -f docker-compose.yml -f docker-compose.images.yml -f docker-compose.recommendations.yml up -d

For source builds, use the base and module files with up -d --build. The module starts MERT and sets RECOMMENDATIONS_ENABLED=true on the API. For an API launched outside Docker, set that flag and MERT_URL explicitly. Without the module, the API reports the capability as disabled and clients hide radio, personalised mixes, the map, recap, and taste controls.

To disable an existing deployment, stop the GPU services explicitly and apply the ordinary configuration again:

docker compose -f docker-compose.yml -f docker-compose.images.yml --profile recommendations stop mert mert-init
docker compose -f docker-compose.yml -f docker-compose.images.yml up -d

Automatic GPU selection and AMD

MERT_GPU_BACKEND=auto (the default) detects NVIDIA or AMD on the local host, preferring NVIDIA if both are present. Set it to nvidia or amd in .env to override, then enable again. The selected files persist in COMPOSE_FILE for subsequent lifecycle commands. The manager checks an actual GPU computation inside the container before loading weights; a failed check restores the previous configuration. Existing weights, model identity and preprocessing are shared by both backends; no retraining or database migration is needed.

AMD uses a separate caimack-mert-rocm image with PyTorch 2.8.0 and ROCm 6.4, while NVIDIA continues to use caimack-mert with CUDA 12.6. These pinned builds follow the PyTorch installation matrix. AMD support requires a Linux Docker host, a compatible amdgpu kernel driver and a GPU supported by that ROCm version. Check the ROCm system requirements. The manager does not install drivers or apply overrides for unsupported cards.

For manual AMD deployment, set the host device group IDs in .env (the manager normally fills these automatically). Obtain them with:

stat -c '%g' /dev/kfd
stat -c '%g' /dev/dri/renderD*

Set MERT_KFD_GID to the first result and MERT_RENDER_GID to the render node group ID. The container maps /dev/kfd and /dev/dri and adds these groups to its non-root user, following the AMD container setup. Then append the AMD override after the recommendation module:

docker compose -f docker-compose.yml -f docker-compose.images.yml -f docker-compose.recommendations.yml -f docker-compose.mert-amd.yml pull
docker compose -f docker-compose.yml -f docker-compose.images.yml -f docker-compose.recommendations.yml -f docker-compose.mert-amd.yml up -d

For source builds, omit docker-compose.images.yml and use up -d --build. ROCm images become available for a release after its image workflow completes; older releases published before AMD support do not contain that image. For manual shutdown, stop mert mert-init with the same AMD Compose file list before returning to the ordinary configuration.

Weights and GPU setup

MERT-Large v1 (330M) uses official ready-made weights from m-a-p/MERT-v1-330M, pinned to revision 5240c2708a5acaee1007f43fb9735c7dcd0b78c9. No training or export happens on the server. The first embedding request downloads about 1.26 GB into MERT_CACHE_PATH (default ./storage/models/mert); subsequent starts reuse the cache. To reuse the earlier benchmark download, set this path to ./storage/experiments/mert/huggingface in .env.

Linux Docker requires a working NVIDIA driver and NVIDIA Container Toolkit. Check nvidia-smi on the host, then configure the Docker runtime using the official installation guide. An error could not select device driver "nvidia" means Docker GPU support has not been configured; it does not prevent running the ordinary CPU deployment.

Behaviour when enabled

The API plans three to eight five-second mono windows at 24 kHz. Very short tracks use fewer windows, down to one when the duration is at most 5.05 seconds. MERT runs serially on the local GPU, producing normalized 1024-dimensional vectors. Tracks with older embeddings are reanalysed automatically. The index accepts only embeddings with a matching model, strategy, dimension, and audio hash. Model loading and transient GPU outages leave library browsing and playback available.

On-demand GPU lifecycle

The HTTP service starts without loading PyTorch or creating a GPU context. The first valid POST /embed starts a single GPU subprocess and returns 503 with Retry-After: 5 while it loads. The backend retains the pending work in the database and retries on its next analysis pass (normally every 30 seconds). It continues CPU audio analysis while MERT is loading or unavailable and preserves existing embeddings until a replacement succeeds. Existing recommendations use saved vectors and do not wake the GPU worker.

Inference runs one request at a time. Concurrent requests receive 503 with Retry-After: 1 while busy; PCM requests are not queued in memory. After five minutes without inference, the subprocess terminates, releasing its GPU context and model memory. The next embedding request wakes a new process using the cached weights. An active inference is never stopped by the idle timer.

Configure the service in the deployment .env:

Variable Default Meaning
MERT_IDLE_TIMEOUT_SECONDS 300 Idle period before releasing the GPU; 0 disables idle shutdown. Loading still starts on demand.
MERT_LOAD_TIMEOUT_SECONDS 1800 Maximum model startup time, including the first weight download.
MERT_INFERENCE_TIMEOUT_SECONDS 90 Maximum wait for an inference result; keep below the API's 120-second HTTP timeout.

Apply changes by recreating mert with your deployment's Compose file list. Keep a nonzero idle timeout above the backend's 30-second polling interval, so the next analysis pass can use a newly loaded worker before it goes to sleep. For a standalone Python service, these environment variables or corresponding --idle-timeout-seconds, --load-timeout-seconds and --inference-timeout-seconds options work as well. --download-only still eagerly loads and validates the model, then exits.

GET /health returns HTTP 200 with model identity and state: sleeping, loading, ready, busy or error. This checks the HTTP service; it never starts the GPU worker or resets the idle timer. error also includes retryAfterSeconds. Once that delay expires, the state returns to sleeping without starting a worker. Failed loads, crashes and inference timeouts stop the GPU worker and apply a retry delay of 30, 60, 120, 240, then at most 300 seconds. Recovery starts only when an embedding request arrives after the delay. A successful inference resets the backoff.

Logs

MERT writes to stderr with UTC timestamps including milliseconds and an explicit +00:00 offset. Backend timestamps may use a different offset; compare the full timestamps when matching events across services.

At INFO, logs describe HTTP readiness, worker starts, model loading stages, loading progress every 30 seconds, GPU readiness, completed embeddings and idle shutdown. Stages distinguish Python imports, GPU initialization, configuration, architecture, checkpoint resolution from cache or download, checksum verification, weight loading and transfer to the GPU. Stage completion includes elapsed_ms; GPU initialization reports device, runtime, vector dimension and allocated/reserved GPU memory. Checkpoint resolution does not claim that cached weights were downloaded.

Each worker lifecycle has a PID and generation number. Idle shutdown reports completed, fragments, idle duration and rejected requests. completed=0 means the model loaded but no inference completed before it went to sleep; a warning explicitly calls out backend retry timing in that case. These counters reset on each worker start. The HTTP health check never resets the idle timer.

Inference results include fragment count, vector dimension, duration and request_id. Responses return this server-generated ID in X-Request-Id; it is also passed to the GPU subprocess so worker errors can be correlated. The request that wakes a worker is identified on its loading events. Request bodies, PCM samples, vectors, headers and raw unknown URLs are not logged.

Ordinary health checks and expected 503 deferrals while loading or busy are DEBUG. Their HTTP events include state, reason and retry_after_secs. Worker failures remain ERROR, with the failing phase/stage, exception, worker PID, retry delay and exit code when available. A failed worker's exception is also reported by the supervisor rather than replaced with a generic loading error.

The specific Hugging Face resume_download deprecation is filtered; other warnings remain visible. The remote model's missing-nnAudio print is DEBUG only when CQT is disabled in the actual configuration. With CQT enabled it remains a warning. Unknown model prints are retained as warning events.

Variable Default Meaning
MERT_LOG_LEVEL INFO DEBUG, INFO, WARNING, ERROR or CRITICAL. Applied in both the HTTP process and GPU worker.
LOG_FORMAT text text for the console or one JSON object per event with json. Compose passes this setting to MERT, backend and migration services.

Change these settings in the deployment .env and recreate the service with your usual Compose file list. Updated Python code requires rebuilding/pulling the MERT image before recreating it. Restarting an existing image alone does not update it.

The CUDA and ROCm images are published with the API and web images on release tags. Model weights are licensed separately under CC BY-NC 4.0.

How recommendations use the analysis

The server builds a recommendation index from compatible audio vectors. Seeded radio searches nearby tracks first, then expands according to the selected focus and applies artist and duplicate limits. The server chooses a batch before ordering it by tempo, key, and loudness transitions. Listening and skips can influence future selections without running more GPU inference. See the library map for the projection and recommendation metrics for feedback from playback.