setup_torch
zocrates.rag.setup_torch ¶
setup_torch.py โ Multi-vendor GPU hardware detection and PyTorch installer.
Supported hardware platforms
- NVIDIA CUDA: โข Compute Capability < 7.5 (e.g., MX250, GTX 10xx sm_61/sm_60/sm_50) -> cu118 wheel index โข Compute Capability >= 7.5 (e.g., RTX 20xx/30xx/40xx, A100 sm_75+) -> cu121/cu126 wheel index
- AMD ROCm (Linux): โข Detects via rocm-smi -> PyTorch ROCm wheel index (https://download.pytorch.org/whl/rocm6.2)
- Apple Silicon (macOS): โข Metal Performance Shaders (MPS) -> Standard PyTorch macOS wheel (built-in MPS support)
- Intel XPU (Arc / Data Center GPUs): โข Intel OneAPI XPU -> Standard / XPU wheel index
- Fallback: โข CPU wheel index
detect_hardware_vendor ¶
Detect the system hardware accelerator vendor.
Returns:
| Type | Description |
|---|---|
str
|
A 3-tuple of |
str
|
|
float | None
|
|
Source code in zocrates/rag/setup_torch.py
get_torch_index_url ¶
Return the appropriate PyTorch wheel index URL for the given vendor and compute capability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vendor
|
str
|
Accelerator vendor string: |
required |
cc
|
float | None
|
NVIDIA compute capability (e.g. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
PyTorch |
str | None
|
(standard PyPI wheels include built-in MPS support). |
Source code in zocrates/rag/setup_torch.py
main ¶
Detect system hardware and install the appropriate PyTorch wheel.
Performs the following steps
- Detect the GPU vendor (NVIDIA, AMD, Apple, Intel, or CPU-only).
- Select the matching PyTorch wheel index URL.
- If the current PyTorch build is already functional, exit early.
- Otherwise install the appropriate wheel via
uv pip install. - Re-test acceleration and report the outcome.
Source code in zocrates/rag/setup_torch.py
test_torch_acceleration ¶
Test whether PyTorch hardware acceleration is functional in the current environment.
Runs a minimal tensor operation in an isolated subprocess for each backend (CUDA/ROCm, Apple MPS, Intel XPU) to avoid polluting the calling process.
Returns:
| Type | Description |
|---|---|
bool
|
A 2-tuple of |
str
|
|
tuple[bool, str]
|
is a human-readable label (e.g. |