Skip to content

Studio: install the Vulkan audio.cpp build on AMD GPUs - #13298

Merged
danielhanchen merged 3 commits into
mainfrom
studio-audio-cpp-amd-vulkan
Oct 12, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
studio-audio-cpp-amd-vulkan

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

Fixes #13042

On AMD GPUs Studio installs the CPU build of audio.cpp, so audio models run on the CPU even when the GPU runs llama.cpp fine (a 15 s MOSS-Transcribe-Diarize clip took 4:50 on an RX 9070 XT, a 50 s one timed out). The Vulkan bundles are already pinned; detect_accelerator() just never picked them.

Changes

studio/install_audio_cpp_prebuilt.py:

  • detect_accelerator() returns vulkan when an AMD display adapter is present and no NVIDIA card is. AMD is read the way install_llama_prebuilt.py already routes llama.cpp to Vulkan: PCI vendor 0x1002 in Linux DRM sysfs, the Windows display-adapter registry (windows_amd_gpu_in_registry). Any nvidia-smi (or /proc/driver/nvidia/gpus on Linux) keeps the old answer, so NVIDIA hosts, mixed hosts and Macs are unchanged.
  • For an auto request the staged Vulkan server must list a Vulkan GPU (audiocpp_server --list-devices, a Vulkan:<n> row) before it is swapped in. If it lists none (no Vulkan driver, libvulkan.so.1 missing, a software-only ICD), the installer installs the CPU build instead and records the host as detected vulkan, so later setup runs are no-ops rather than re-downloading the Vulkan bundle. This matters because the Vulkan server does not fall back to CPU on its own; it exits with Vulkan backend requested but registry 'Vulkan' has no device 0.
  • An explicit --accelerator vulkan / UNSLOTH_AUDIO_CPP_ACCELERATOR=vulkan is never device-checked or downgraded (a Docker build sees no GPU).

Existing AMD installs were recorded as auto with detected cpu, so the next unsloth studio update / Desktop update sees the new detection and installs the Vulkan bundle. Intel GPUs stay on the CPU build: the Vulkan bundle is only confirmed on AMD so far. The HIP bundle half of the issue is release packaging in unslothai/audio.cpp and is not part of this PR.

Tests

tests/studio/install/test_install_audio_cpp_prebuilt_logic.py: detection on Linux (AMD, AMD + Intel, Intel only, NVIDIA with and without a CUDA version) and Windows (registry yes / no / raising), the --list-devices check (GPU row, CPU only, loader failure, OSError, timeout), and the install flow (AMD auto installs Vulkan; no Vulkan GPU installs CPU once and the rerun makes no lookup; an existing CPU install moves to Vulkan; explicit vulkan is not checked). 10 of the new tests fail on main, 116/116 pass on this branch.

Real bundles on Linux x86_64 (v0.9.0-unsloth.1, detection pinned to "AMD GPU, no NVIDIA"):

Run Installed
main bin-ubuntu-x64-cpu-portable, backend cpu
this PR, Vulkan GPU listed bin-ubuntu-x64-vulkan, backend vulkan
this PR, no Vulkan GPU Vulkan staged, finds no Vulkan GPU on this host; installing the CPU build, backend cpu; rerun already matches
this PR over main's CPU install moves to bin-ubuntu-x64-vulkan; rerun already matches
this PR, explicit --accelerator vulkan, no GPU bin-ubuntu-x64-vulkan as before

MOSS-Transcribe-Diarize q4_k on a 15.9 s clip gives the identical transcript on the CPU and Vulkan bundles.

On real AMD hardware

gfx1151 (Radeon 8060S), same job and box for main (fc5cf50) and this PR (5a7ab58), the real installer with no detection patched (Linux read card1/device/vendor = 0x1002, Windows the display-adapter registry). MOSS-Transcribe-Diarize q4_k on a 15.9 s clip, two repeats:

OS main installs this PR installs --list-devices on this PR main request time this PR request time transcript
Windows 11 windows-x64-cpu-portable.zip windows-x64-vulkan.zip Vulkan:0 "AMD Radeon(TM) 8060S Graphics" [IGPU] 305.1 s, 318.4 s 3.3 s, 1.2 s same words, two timestamps differ by 0.01 to 0.02 s
Linux ubuntu-x64-cpu-portable.tar.gz ubuntu-x64-vulkan.tar.gz Vulkan:0 "AMD Radeon Graphics (RADV GFX1151)" [IGPU] 21.5 s, 21.2 s 2.0 s, 1.3 s identical

The Windows CPU time matches the report (4:50 for a 15 s clip). A second install on every side prints already matches. The Windows runs used a 16 kHz copy of the clip: the MOSS model on the Windows bundles (CPU and Vulkan alike, main included) refuses non-16 kHz input with requires SOXR for non-16-kHz audio, which is separate from this change.

@danielhanchen danielhanchen self-assigned this Oct 11, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-11T10:07:42.659765Z 5a7ab58 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-11T23:22:54.660145Z 153b180 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5a7ab58d95

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +265 to +268
if shutil.which("nvidia-smi"):
return True
try:
return sys.platform.startswith("linux") and bool(os.listdir("/proc/driver/nvidia/gpus"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Detect NVIDIA adapters through DRM sysfs

On Linux systems with both AMD and NVIDIA adapters where NVIDIA uses Nouveau/NVK—or otherwise lacks both nvidia-smi and the proprietary driver's /proc/driver/nvidia/gpus entry—this returns false even though the NVIDIA card is present under DRM as vendor 0x10de. detect_accelerator() consequently selects Vulkan, and the staged check accepts a Vulkan device on either card, so Vulkan can enumerate the NVIDIA adapter first despite the new mixed-host guard. Check DRM vendor IDs for NVIDIA here as well.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing: an NVIDIA card driven by Nouveau/NVK with no proprietary driver next to an AMD GPU is a rare mixed host, and even there the Vulkan build runs on a real GPU, so nothing crashes or returns wrong output. The guard is for the common case, the proprietary driver, which nvidia-smi and /proc/driver/nvidia/gpus cover.



# `--list-devices` prints one `Vulkan:<n> "<name>" [GPU]` row per device ggml-vulkan accepts.
_VULKAN_DEVICE_ROW = re.compile(r"^Vulkan:\d+\s", re.MULTILINE)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Require an AMD device before accepting Vulkan

On an AMD-plus-Intel host, or a Windows Intel-only host with a stale AMD display-adapter registry entry, this accepts an Intel Vulkan:<n> row as proof that the AMD route works. The installed record stores only the Vulkan backend, and normal launches do not select a device, so if Intel is Vulkan device 0 audio.cpp runs on the Intel iGPU instead of the detected AMD GPU. Validate that an enumerated row belongs to AMD and preserve/select that device index rather than accepting any Vulkan device.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing here: on an Intel iGPU plus AMD dGPU host the Vulkan build still runs every model on a GPU, so this is device preference, not a failure or wrong output. Picking a specific Vulkan device would need a recorded device index and a --device at launch in audio_cpp_server.py; that is a separate change if hybrid laptops turn out to need it.

server,
backend = backend,
extra_dirs = _cuda_runtime_dirs(backend),
require_vulkan_device = requested == "auto" and backend == "vulkan",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Revalidate cached auto Vulkan installs

When a previous auto-selected Vulkan install still matches its pins, _pinned_install_matches() returns it before this staged-only device check runs. If the Vulkan device later becomes unavailable while the AMD adapter remains visible in sysfs or the registry—for example after a driver removal, device-permission change, or moving a persisted install into a container—a setup rerun keeps the Vulkan record and every model load still fails instead of installing the CPU fallback. Re-run the device probe before accepting an existing auto Vulkan install.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing: losing the Vulkan driver after a working Vulkan install while the AMD adapter stays is rare, and re-probing devices on every setup run costs every AMD host a server start. That host recovers with --force or UNSLOTH_AUDIO_CPP_ACCELERATOR=cpu, the same as any other install whose driver was removed.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 11, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 11, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5a7ab58d95

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".



# `--list-devices` prints one `Vulkan:<n> "<name>" [GPU]` row per device ggml-vulkan accepts.
_VULKAN_DEVICE_ROW = re.compile(r"^Vulkan:\d+\s", re.MULTILINE)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject CPU-class Vulkan devices

When an AMD adapter lacks a working hardware ICD but a software implementation such as lavapipe or SwiftShader is installed, --list-devices can emit a Vulkan:<n> ... [CPU] row. This prefix-only regex accepts that row as a GPU, so the installer records the Vulkan backend and audio_cpp_server.select_backend() subsequently forces --backend vulkan, running workloads through software Vulkan instead of installing the optimized CPU build. Inspect the device classification suffix and reject CPU-class Vulkan rows.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not reachable: the vendored ggml-vulkan only registers eDiscreteGpu / eIntegratedGpu physical devices (ggml_vk_instance_init) and reports every Vulkan device as GPU or IGPU (ggml_backend_vk_device_get_type), so a Vulkan row is never CPU-class. Checked with the pinned Linux Vulkan bundle and only the lavapipe ICD: it prints 'ggml_vulkan: No devices found.' and lists only CPU:0, so the installer falls back to the CPU build. Matching a [GPU] suffix would also reject AMD APUs, which list as [IGPU].

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Studio] audio.cpp runs on CPU on AMD GPUs: ship ROCm/HIP bundles in unslothai/audio.cpp and fall back to Vulkan

1 participant