voicebox icon indicating copy to clipboard operation
voicebox copied to clipboard

feat(windows): DirectML GPU acceleration for Intel iGPU (Iris/UHD/Arc)

Open RajeshKumar11 opened this issue 6 months ago β€’ 2 comments

Closes #628

Summary

Add torch-directml support so Windows users with Intel integrated graphics (Iris Xe, UHD Graphics, Arc) get hardware-accelerated TTS/STT without needing NVIDIA CUDA.

Changes

backend/backends/base.py

  • Add _detect_iris_igpu() using WMI to identify Intel iGPU by name
  • Add allow_directml parameter to get_torch_device() with priority chain: CUDA > XPU > DirectML > MPS > CPU

backend/backends/pytorch_backend.py

  • Pass allow_directml=True in TTS and STT backends so DirectML is used automatically on eligible hardware

backend/requirements.txt

  • Add torch-directml>=0.2.0 ; platform_system == "Windows" (Windows-only PEP 508 marker)

backend/tests/test_directml_iris.py (new)

  • Windows-only tests for DirectML import, device count, device creation, tensor ops, memory management, and Iris iGPU WMI detection

Test plan

  • [ ] get_torch_device(allow_directml=True) returns a DirectML device on Windows with Intel iGPU
  • [ ] Server log shows "Using DirectML device" on Intel Iris/UHD/Arc hardware
  • [ ] Existing CUDA path unaffected (allow_directml only activates when CUDA/XPU are absent)
  • [ ] pytest backend/tests/test_directml_iris.py -v passes on Windows with torch-directml installed

Hardware tested

Intel 12th-gen i5 + Iris Xe Graphics, Windows 11, CPU-only PyTorch + torch-directml 0.2.5

πŸ€– Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added Windows DirectML support with automatic detection of Intel integrated GPUs (Iris/UHD/Arc) and improved selection of GPU acceleration.
  • Documentation

    • Clarified device selection priority order: CUDA > XPU > DirectML > CPU.
  • Chores

    • Added optional Windows DirectML dependency.
  • Tests

    • Added Windows-only tests validating DirectML availability, Intel iGPU detection, device selection, basic tensor ops, and model load/unload on DirectML.

Review Change Stack

RajeshKumar11 avatar May 17 '26 17:05 RajeshKumar11

[!NOTE]

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • [ ] ▢️ Resume reviews
  • [ ] πŸ” Trigger review
πŸ“ Walkthrough

Walkthrough

This PR adds Windows DirectML support with Intel Iris/iGPU detection. It introduces a WMI-based Iris detection helper, reworks DirectML device selection with device count validation and targeted logging, updates backend docstrings to clarify device priority, adds torch-directml as a Windows-only dependency, and provides a comprehensive test suite covering DirectML availability, device creation, tensor operations, and model loading.

Changes

Windows DirectML and Intel Iris iGPU Support

Layer / File(s) Summary
Iris Detection and DirectML Device Selection
backend/backends/base.py, backend/backends/pytorch_backend.py
_detect_iris_igpu() uses WMI to detect Intel Iris/UHD/Arc GPUs on Windows. get_torch_device() now checks torch_directml.device_count() before selecting device(0), logs whether Iris was detected versus generic DirectML acceleration, and improves error handling for missing or failing torch_directml. Backend _get_device() docstrings document priority order: CUDA > XPU > DirectML > CPU.
Windows DirectML Requirement and Test Suite
backend/requirements.txt, backend/tests/test_directml_iris.py
Adds torch-directml>=0.2.0 for Windows systems. New test module exercises DirectML import, device count/creation, Iris detection, tensor operations and memory management on DirectML, and async smoke tests for loading/unloading Whisper STT and Qwen TTS models; tests skip gracefully when DirectML is unavailable or when network/environment issues prevent model downloads.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • #628: Directly addresses the feature request for Windows DirectML support to expand iGPU acceleration for Intel Iris/Arc GPUs as an alternative to dedicated NVIDIA hardware.

Poem

🐰 Iris gleams on Windows' field tonight,
WMI listens, names the iGPU right,
DirectML wakes and shifts the tiny load,
Models load, then leap along the road,
Hooray β€” a rabbit hops where CPUs once toiled.

πŸš₯ Pre-merge checks | βœ… 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 79.17% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
βœ… Passed checks (4 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed The PR title clearly summarizes the main change: adding DirectML GPU acceleration for Intel iGPU on Windows, which aligns with the primary feature introduced in the changeset.
Linked Issues check βœ… Passed The PR successfully implements Intel iGPU acceleration via DirectML with detection logic, device priority handling, and comprehensive tests, directly addressing the core objectives from #628.
Out of Scope Changes check βœ… Passed All changes are directly related to adding DirectML support for Intel iGPU on Windows; no unrelated or out-of-scope modifications were introduced.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
πŸ§ͺ Generate unit tests (beta)
  • [ ] Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar May 17 '26 17:05 coderabbitai[bot]

The powershell command used to detect the AMD device on Windows does not work for me, using RX 7900 XTX:

Image

The powershell command in question is found in backend/utils/platform_detect.py on line 40:

def is_amd_gpu_windows() -> bool:
    [...]

    try:
        result = subprocess.run(
            [
                "powershell",
                "-Command",
                "Get-CimInstance Win32_VideoController | "
                "Where-Object {$_.AdapterCompatibility -like '*AMD*'} | "
                "Measure-Object | Select-Object -ExpandProperty Count",
            ],
            capture_output=True,
            text=True,
            check=True,
        )

    [...]

Since the powershell searches for AdapterCompatibility with -like '*AMD*', my GPU is not recognized because the value is "Advanced Micro Devices, Inc.".

To fix this, I believe the test should also try '*Advanced Micro Devices*' or use one of the following other values from the Win32_VideoController output:

  • Caption: AMD Radeon RX 7900 XTX
  • Description: AMD Radeon RX 7900 XTX
  • Name: AMD Radeon RX 7900 XTX
  • Video Processor: AMD Radeon Processor (0x744C)
  • InfSection: ati2mtag_Navi31
  • InstalledDisplayDrivers: ...amdxx64.dll... (this is a long string)

Ced-Sharp avatar Jul 05 '26 01:07 Ced-Sharp