(value: str)
| 36 | |
| 37 | |
| 38 | def _npu_available() -> bool: |
| 39 | """torch.npu only exists after torch_npu is imported; probe defensively.""" |
| 40 | try: |
| 41 | import torch_npu # noqa: F401 |
| 42 | except ImportError: |
| 43 | return False |
| 44 | return hasattr(torch, "npu") and torch.npu.is_available() |
| 45 | |
| 46 | |
| 47 | def _select_device(value: str) -> torch.device: |