pytorch - ✅(Solved) Fix test/test_cpp_extensions_mtia_backend.py RuntimeError: Cannot execute getCurrentDevice() without MTIA backend. [1 pull requests, 3 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#181842Fetched 2026-04-30 06:18:15
View on GitHub
Comments
3
Participants
3
Timeline
47
Reactions
0
Timeline (top)
mentioned ×17subscribed ×17labeled ×8commented ×3

Error Message

2026-04-29T03:03:36.8500824Z _____________ TestCppExtensionMTIABackend.test_default_generators ______________ 2026-04-29T03:03:36.8501330Z Traceback (most recent call last): 2026-04-29T03:03:36.8508104Z File "/var/lib/jenkins/workspace/test/test_cpp_extensions_mtia_backend.py", line 146, in test_default_generators 2026-04-29T03:03:36.8508823Z torch.mtia.current_stream() 2026-04-29T03:03:36.8509804Z File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/mtia/init.py", line 189, in current_stream 2026-04-29T03:03:36.8510519Z device_idx = _get_device_index(device, optional=True) 2026-04-29T03:03:36.8511244Z File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/mtia/_utils.py", line 25, in _get_device_index 2026-04-29T03:03:36.8511892Z return torch._C._mtia_getDevice() 2026-04-29T03:03:36.8512347Z RuntimeError: Cannot execute getCurrentDevice() without MTIA backend. 2026-04-29T03:03:36.8512700Z 2026-04-29T03:03:36.8512907Z To execute this test, run the following from the base repo dir: 2026-04-29T03:03:36.8513810Z PYTORCH_TEST_WITH_ASAN=1 PYTORCH_TEST_WITH_UBSAN=1 python test/test_cpp_extensions_mtia_backend.py TestCppExtensionMTIABackend.test_default_generators 2026-04-29T03:03:36.8514549Z

PR fix notes

PR #178468: [WIP][xpu][test]Generalize common code for distributed test on Intel GPU

Description (problem / solution / changelog)

For https://github.com/pytorch/pytorch/issues/114850, we will port distributed tests to Intel GPU. We could enable Intel GPU with following methods and try the best to keep the original code styles:

  • use "torch.accelerator.current_accelerator()" to determine the accelerator backend
  • enabled XPU for some test path

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo

Changed files

  • torch/_inductor/analysis/device_info.py (modified, +2/-1)
  • torch/_inductor/fx_passes/node_runtime_estimation.py (modified, +4/-4)
  • torch/_inductor/utils.py (modified, +3/-0)
  • torch/_utils_internal.py (modified, +1/-1)
  • torch/distributed/_dist2.py (modified, +29/-0)
  • torch/distributed/_local_tensor/__init__.py (modified, +2/-2)
  • torch/distributed/_shard/sharded_tensor/_ops/binary_cmp.py (modified, +7/-3)
  • torch/distributed/_shard/sharded_tensor/api.py (modified, +3/-3)
  • torch/distributed/_tools/runtime_estimator.py (modified, +6/-6)
  • torch/distributed/collective_utils.py (modified, +1/-1)
  • torch/distributed/distributed_c10d.py (modified, +26/-11)
  • torch/distributed/rpc/backend_registry.py (modified, +13/-8)
  • torch/testing/_internal/common_distributed.py (modified, +7/-3)
  • torch/testing/_internal/common_fsdp.py (modified, +0/-2)
  • torch/testing/_internal/common_utils.py (modified, +12/-8)
  • torch/testing/_internal/distributed/_shard/sharded_tensor/__init__.py (modified, +10/-5)
  • torch/testing/_internal/distributed/_shard/sharded_tensor/_test_ops_common.py (modified, +19/-16)
  • torch/testing/_internal/distributed/_shard/sharded_tensor/_test_st_common.py (modified, +7/-4)
  • torch/testing/_internal/distributed/_shard/test_common.py (modified, +2/-2)
  • torch/testing/_internal/distributed/common_state_dict.py (modified, +3/-1)
  • torch/testing/_internal/distributed/multi_threaded_pg.py (modified, +3/-1)

Code Example

2026-04-29T03:03:36.8500824Z _____________ TestCppExtensionMTIABackend.test_default_generators ______________
2026-04-29T03:03:36.8501330Z Traceback (most recent call last):
2026-04-29T03:03:36.8508104Z   File "/var/lib/jenkins/workspace/test/test_cpp_extensions_mtia_backend.py", line 146, in test_default_generators
2026-04-29T03:03:36.8508823Z     torch.mtia.current_stream()
2026-04-29T03:03:36.8509804Z   File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/mtia/__init__.py", line 189, in current_stream
2026-04-29T03:03:36.8510519Z     device_idx = _get_device_index(device, optional=True)
2026-04-29T03:03:36.8511244Z   File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/mtia/_utils.py", line 25, in _get_device_index
2026-04-29T03:03:36.8511892Z     return torch._C._mtia_getDevice()
2026-04-29T03:03:36.8512347Z RuntimeError: Cannot execute getCurrentDevice() without MTIA backend.
2026-04-29T03:03:36.8512700Z 
2026-04-29T03:03:36.8512907Z To execute this test, run the following from the base repo dir:
2026-04-29T03:03:36.8513810Z     PYTORCH_TEST_WITH_ASAN=1 PYTORCH_TEST_WITH_UBSAN=1 python test/test_cpp_extensions_mtia_backend.py TestCppExtensionMTIABackend.test_default_generators
2026-04-29T03:03:36.8514549Z
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

2026-04-29T03:03:36.8500824Z _____________ TestCppExtensionMTIABackend.test_default_generators ______________
2026-04-29T03:03:36.8501330Z Traceback (most recent call last):
2026-04-29T03:03:36.8508104Z   File "/var/lib/jenkins/workspace/test/test_cpp_extensions_mtia_backend.py", line 146, in test_default_generators
2026-04-29T03:03:36.8508823Z     torch.mtia.current_stream()
2026-04-29T03:03:36.8509804Z   File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/mtia/__init__.py", line 189, in current_stream
2026-04-29T03:03:36.8510519Z     device_idx = _get_device_index(device, optional=True)
2026-04-29T03:03:36.8511244Z   File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/mtia/_utils.py", line 25, in _get_device_index
2026-04-29T03:03:36.8511892Z     return torch._C._mtia_getDevice()
2026-04-29T03:03:36.8512347Z RuntimeError: Cannot execute getCurrentDevice() without MTIA backend.
2026-04-29T03:03:36.8512700Z 
2026-04-29T03:03:36.8512907Z To execute this test, run the following from the base repo dir:
2026-04-29T03:03:36.8513810Z     PYTORCH_TEST_WITH_ASAN=1 PYTORCH_TEST_WITH_UBSAN=1 python test/test_cpp_extensions_mtia_backend.py TestCppExtensionMTIABackend.test_default_generators
2026-04-29T03:03:36.8514549Z

Versions

Found in https://github.com/pytorch/pytorch/pull/178468

cc @janeyx99 @mruberry @egienvalue @albanD @guangyey @EikanWang

extent analysis

TL;DR

The most likely fix is to ensure the MTIA backend is properly initialized before calling torch.mtia.current_stream().

Guidance

  • Verify that the MTIA backend is enabled and configured correctly in the test environment.
  • Check the documentation for torch.mtia to ensure that the current_stream() function is being used correctly.
  • Consider adding a check to ensure that the MTIA backend is available before attempting to use it.
  • Review the test code to ensure that it is properly setting up and tearing down the MTIA backend.

Notes

The error message suggests that the MTIA backend is not available when the current_stream() function is called. This may be due to a configuration issue or a problem with the test setup.

Recommendation

Apply workaround: Ensure that the MTIA backend is properly initialized before calling torch.mtia.current_stream(), as this is likely to resolve the RuntimeError being encountered.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING