Skip to content

feat(server): support per-model backend device selection - #973

Merged
0xShug0 merged 3 commits into
0xShug0:mainfrom
railep:codex/per-model-cuda-device
Oct 18, 2026
Merged

0xShug0 merged 3 commits into
0xShug0:mainfrom
railep:codex/per-model-cuda-device

Conversation

@railep

@railep railep commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add an optional per-model device override for configured and dynamically loaded server models
  • apply the effective device consistently to session creation, memory checks, reload detection, and GET /v1/models
  • preserve an existing model's device assignment when a dynamic reload omits the field
  • harden CUDA reusable sampling buffers and ISTFT cleanup for serving threads that alternate between devices
  • document whole-model multi-device placement and its residency semantics

The field is opt-in. Existing configurations without models[].device continue to use the server-wide device.

This allows multi-GPU systems to keep different models resident on different devices—for example, a large synthesis model on one GPU and smaller supporting models on another. It improves VRAM utilization, avoids unnecessary unload/reload cycles, and lets independent models use the available GPUs concurrently.

Example

{
  "backend": "cuda",
  "device": 0,
  "max_loaded_models": 0,
  "models": [
    {"id": "speech", "family": "kokoro_tts", "path": "models/kokoro.gguf", "device": 0},
    {"id": "music", "family": "stable_audio", "path": "models/stable-audio", "device": 1}
  ]
}

This assigns each complete model to one backend device. It does not split a single model across GPUs, and max_loaded_models remains a server-wide limit.

Validation

Tested on Windows with CUDA 13.1 using:

  • NVIDIA GeForce RTX 5090 as CUDA device 0
  • NVIDIA GeForce RTX 5060 Ti as CUDA device 1
  • AMD Ryzen 9 3950X with the AVX2 CPU profile

Full CUDA build:

.\scripts\build_windows.ps1 -Preset windows-cuda-debug -Target audiocpp_server -CpuArch avx2 -ModelSet full -Jobs 12

Successful tests:

server_parallel_lifecycle_test.exe
server_runtime_selection_test.exe
server_config_test.exe
torch_random_test.exe
torch_random_cuda_multi_device_test.exe
backend_device_resolution_test.exe
audiocpp_server.exe --list-devices

The multi-device CUDA test alternates 0 -> 1 -> 0 -> 1 on one serving thread and covers allocation, reuse, release, and reallocation of device-specific buffers. The server lifecycle test covers global-device fallback, per-model override propagation to SessionOptions, effective-device model listings, assignment-preserving reloads, and rejection of negative dynamic device indices.

A CUDA Release server build also completed successfully before the final rebase; the full Debug build and all tests above were repeated after rebasing onto current main.

Compatibility and scope

  • single-device and existing configurations retain their previous behavior
  • no NCCL dependency is introduced because this is whole-model placement rather than distributed execution
  • invalid positive indices continue to be reported by the selected backend when the model loads
  • GET /v1/models gains the additive device field
  • per-thread CUDA staging allocations are retained per device to avoid unsafe cross-device pointer reuse

@0xShug0
0xShug0 merged commit ff202c0 into 0xShug0:main Oct 18, 2026
@0xShug0

0xShug0 commented Oct 18, 2026

Copy link
Copy Markdown
Owner

@railep Thanks for adding this great extension! PR merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants