Skip to content

Refine device operations into a unified DeviceManager and ARDevice abstraction - #2344

Open
lvliang-intel wants to merge 4 commits into
mainfrom
lvl/refine_device_class
Open

lvliang-intel wants to merge 4 commits into
mainfrom
lvl/refine_device_class

Conversation

@lvliang-intel

Copy link
Copy Markdown
Contributor

Description

Refine device operations into a unified DeviceManager / ARDevice abstraction so that (1) adding a new device is cheap and
(2) every device PyTorch supports works automatically with no per-device code.

a) Discovery is now data-driven. Backends are found via torch.accelerator, the PrivateUse1 registration, and a generic is_available() probe, and fall back to a preferred-order hint on older PyTorch. AR_DEVICE_BACKENDS= is an escape hatch for brand-new backends with zero code change.
b) Capability flags replace device-type branches. ARDevice now declares visible_devices_env_var, supports_pipeline_parallel, supports_multi_card_tuning, supports_empty_cache, supports_device_map_dispatch, and auto_select_by_default.
c) New APIs: register_ar_device() and get_active_device(), and a CudaARDevice/XpuARDevice handle for the built-in backends.
Route remaining torch.cuda.* call sites (hadamard, spinquant, calibration, convert_model) through the device manager.

Type of Change

Enhancement

Related Issues

#1788

Checklist Before Submitting

  • My code has been tested locally.
  • Documentation has been updated as needed.
  • New or updated tests are included where applicable.
  • The CUDA CI has passed. You can trigger it by commenting /azp run Unit-Test-CUDA-AutoRound.

@lvliang-intel
lvliang-intel marked this pull request as ready for review September 15, 2026 08:31
@AutoRoundBot

Copy link
Copy Markdown
Collaborator

CI Failure Analysis Report (Unit-Test-AutoRound)

New Issues (3)

No.1 — 3 occurrence(s)

🔍 AssertionError: assert None == '0'

📝 Basic info

  • Affected tests (3): TestSetCudaVisibleDevices.test_without_existing_cuda_visible_devices, TestSetCudaVisibleDevicesExtra.test_combined_with_spaces_in_index, TestSetCudaVisibleDevicesExtra.test_no_existing_env_var
  • Logs (1): unittest_test_common_utils.log

🖥️ Log excerpt

unit/common/utils/test_device.py:486: in test_without_existing_cuda_visible_devices
    assert os.environ.get("CUDA_VISIBLE_DEVICES") == "0"
E   AssertionError: assert None == '0'
E    +  where None = get('CUDA_VISIBLE_DEVICES')
E    +    where get = environ({'UT_MODE': '0', 'HOSTNAME': 'e9b04053db06', 'FILTER_CHANGED_TESTS': 'true', 'COVERAGE_RCFILE': '/auto-round/.azure-pipelines/scripts/ut/coveragerc/cpu.coveragerc', 'FORCE_BF16': '1', 'PWD': '/auto-round/test', 'TZ': 'Asia/Shanghai', 'HOME': '/home/hostuser', 'LANG': 'C.UTF-8', 'VIRTUAL_ENV': '/home/hostuser/.venv', 'UV_LINK_MODE': 'copy', 'SYSTEM_JOBATTEMPT': '1', 'SYSTEM_PULLREQUEST_TARGETBRANCH': 'main', 'ZE_AFFINITY_MASK': '', 'NUMA_CPUSET': '0-15', 'TQDM_MININTERVAL': '120', 'UV_NO_PROGRESS': '1', 'BUILD_REASON': 'PullRequest', 'HF_HUB_DISABLE_PROGRESS_BARS': '1', 'SHLVL': '1', 'LD_LIBRARY_PATH': '/home/hostuser/.venv/lib/:', 'NUMA_NODE': '0', 'PATH': '/home/hostuser/.venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'OLDPWD': '/auto-round', '_': '/usr/bin/numactl', 'PYTEST_VERSION': '9.1.1', 'TORCHINDUCTOR_CACHE_DIR': '/tmp/torchinductor_hostuser', 'KMP_DUPLICATE_LIB_OK': 'True', 'KMP_INIT_AT_FORK': 'FALSE', 'TOKENIZERS_PARALLELISM': 'false', 'CUBLAS_WORKSPACE_CONFIG': ':4096:8', 'PT_HPU_LAZY_MODE': '1', 'PYTEST_CURRENT_TEST': 'unit/common/utils/test_device.py::TestSetCudaVisibleDevices::test_without_existing_cuda_visible_devices (call)'}).get
E    +      where environ({'UT_MODE': '0', 'HOSTNAME': 'e9b04053db06', 'FILTER_CHANGED_TESTS': 'true', 'COVERAGE_RCFILE': '/auto-round/.azure-pipelines/scripts/ut/coveragerc/cpu.coveragerc', 'FORCE_BF16': '1', 'PWD': '/auto-round/test', 'TZ': 'Asia/Shanghai', 'HOME': '/home/hostuser', 'LANG': 'C.UTF-8', 'VIRTUAL_ENV': '/home/hostuser/.venv', 'UV_LINK_MODE': 'copy', 'SYSTEM_JOBATTEMPT': '1', 'SYSTEM_PULLREQUEST_TARGETBRANCH': 'main', 'ZE_AFFINITY_MASK': '', 'NUMA_CPUSET': '0-15', 'TQDM_MININTERVAL': '120', 'UV_NO_PROGRESS': '1', 'BUILD_REASON': 'PullRequest', 'HF_HUB_DISABLE_PROGRESS_BARS': '1', 'SHLVL': '1', 'LD_LIBRARY_PATH': '/home/hostuser/.venv/lib/:', 'NUMA_NODE': '0', 'PATH': '/home/hostuser/.venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'OLDPWD': '/auto-round', '_': '/usr/bin/numactl', 'PYTEST_VERSION': '9.1.1', 'TORCHINDUCTOR_CACHE_DIR': '/tmp/torchinductor_hostuser', 'KMP_DUPLICATE_LIB_OK': 'True', 'KMP_INIT_AT_FORK': 'FALSE', 'TOKENIZERS_PARALLELISM': 'false', 'CUBLAS_WORKSPACE_CONFIG': ':4096:8', 'PT_HPU_LAZY_MODE': '1', 'PYTEST_CURRENT_TEST': 'unit/common/utils/test_device.py::TestSetCudaVisibleDevices::test_without_existing_cuda_visible_devices (call)'}) = os.environ

✨ AI analysis

  • Category: Code Regression

  • Confidence: high

  • Root cause: The refactor changed set_cuda_visible_devices into an alias that does not explicitly select CUDA. For numeric inputs such as "0" or "5", set_visible_devices infers the current backend; in this CI environment that resolves to HPU or CPU, so CUDA_VISIBLE_DEVICES is never set.

  • Suggested fix: Pass device_type="cuda" from the backward-compatible set_cuda_visible_devices wrapper so it preserves its original CUDA-specific behavior.

  • Patch:

    diff --git a/auto_round/utils/device.py b/auto_round/utils/device.py
    --- a/auto_round/utils/device.py
    +++ b/auto_round/utils/device.py
    @@ -369,7 +369,7 @@ def set_visible_devices(device: str, device_type: Optional[str] = None) -> None:
     def set_cuda_visible_devices(device: str):
         """Backward-compatible alias of :func:`set_visible_devices`."""
    -    set_visible_devices(device)
    +    set_visible_devices(device, device_type="cuda")

No.2 — 1 occurrence(s)

🔍 AssertionError: assert '0,1,2,3' == '0,2'

📝 Basic info

  • Affected tests (1): TestSetCudaVisibleDevices.test_multiple_devices
  • Logs (1): unittest_test_common_utils.log

🖥️ Log excerpt

unit/common/utils/test_device.py:434: in test_multiple_devices
    assert os.environ.get("CUDA_VISIBLE_DEVICES") == "0,2"
E   AssertionError: assert '0,1,2,3' == '0,2'
E
E     - 0,2
E     + 0,1,2,3

✨ AI analysis

  • Category: Code Regression

  • Confidence: high

  • Root cause: The PR replaced the CUDA-specific implementation with a generic set_visible_devices helper, but the backward-compatible set_cuda_visible_devices alias no longer forces device_type="cuda". On the CPU CI runner, numeric input resolves to the current CPU backend, whose visibility variable is unset, so the function becomes a no-op and does not remap or validate CUDA_VISIBLE_DEVICES.

  • Suggested fix: Pass device_type="cuda" from set_cuda_visible_devices so the compatibility wrapper retains its original CUDA-specific behavior.

  • Patch:

    diff --git a/auto_round/utils/device.py b/auto_round/utils/device.py
    --- a/auto_round/utils/device.py
    +++ b/auto_round/utils/device.py
    @@ -367,7 +367,7 @@ def set_visible_devices(device: str, device_type: Optional[str] = None) -> None:
     def set_cuda_visible_devices(device: str):
         """Backward-compatible alias of :func:`set_visible_devices`."""
    -    set_visible_devices(device)
    +    set_visible_devices(device, device_type="cuda")

No.3 — 1 occurrence(s)

🔍 Failed: DID NOT RAISE ValueError

📝 Basic info

  • Affected tests (1): TestSetCudaVisibleDevices.test_invalid_device_index_raises
  • Logs (1): unittest_test_common_utils.log

🖥️ Log excerpt

unit/common/utils/test_device.py:470: in test_invalid_device_index_raises
    with pytest.raises(ValueError):
         ^^^^^^^^^^^^^^^^^^^^^^^^^
E   Failed: DID NOT RAISE ValueError

✨ AI analysis

  • Category: Code Regression

  • Confidence: high

  • Root cause: The PR changed set_cuda_visible_devices to delegate without specifying CUDA. On CPU CI, get_current_device_type() returns cpu, whose backend has no visibility environment variable, so the function returns without inspecting CUDA_VISIBLE_DEVICES and does not raise for index 5.

  • Suggested fix: Preserve the backward-compatible CUDA-specific behavior by explicitly passing device_type="cuda" from set_cuda_visible_devices.

  • Patch:

    diff --git a/auto_round/utils/device.py b/auto_round/utils/device.py
    --- a/auto_round/utils/device.py
    +++ b/auto_round/utils/device.py
    @@ -368,7 +368,7 @@
     def set_cuda_visible_devices(device: str):
         """Backward-compatible alias of :func:`set_visible_devices`."""
    -    set_visible_devices(device)
    +    set_visible_devices(device, device_type="cuda")

Notes

  • Only top-3 issues receive AI analysis.
  • To request an additional fix from Copilot, use "Quote reply" on the PR comment and @mention Copilot.

@AutoRoundBot

Copy link
Copy Markdown
Collaborator

CI Failure Analysis Report (Unit-Test-XPU-AutoRound)

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