# SlicerPyTorch: the PyTorchUtils module that other Slicer extensions use to get # PyTorch (20 extensions in the ExtensionsIndex list "PyTorch" as a dependency: # NNUNet, MONAIAuto3DSeg, TotalSegmentator-style AI modules, ...). Upstream # downloads a PyTorch wheel with light-the-torch, matched to the NVIDIA driver. # # Here PyTorch is the python3-torch RPM, and Patch0 turns PyTorchUtils into a # reporter for it: it never downloads PyTorch, says which backend Fedora's build # has (CPU, or ROCm), and says plainly that NVIDIA GPUs are not used, because # Fedora's PyTorch has no CUDA. PURE-SCRIPTED: nothing to compile. %global commit 74f8216f4841d84b8ceca3026aa18d022be78e78 %global shortcommit %(c=%{commit}; echo ${c:0:8}) %global snapdate 20260730 %global slicer_inst %{_prefix}/lib/slicer %global slicer_subdir Slicer-5.12 %global qtsm %{slicer_inst}/lib/%{slicer_subdir}/qt-scripted-modules Name: 3dslicer-pytorch Version: 0 Release: 0.1.%{snapdate}git%{shortcommit}%{?dist} Summary: PyTorch for 3D Slicer extensions, from Fedora's python3-torch # The extension ships 3D Slicer's own License.txt, which 3dslicer.spec records as BSD-3-Clause. License: BSD-3-Clause URL: https://github.com/fepegar/SlicerPyTorch Source0: %{url}/archive/%{commit}/SlicerPyTorch-%{shortcommit}.tar.gz # Use the system PyTorch; never download one: # - torchInstalled(): upstream read importlib.metadata.files('torch'), which is None for # the RPM (its dist-info has no RECORD), and raised TypeError. Now an import test. # - installTorch(): returns the system torch when it meets the version requirement, # otherwise raises with a "dnf install python3-torch" hint. No light-the-torch. # - uninstallTorch(): refuses; dnf owns PyTorch. # - getCompatibleComputationBackends(): the installed build's backend (cpu or rocm). # - The version text names the backend and says NVIDIA GPUs are not used (no CUDA). Patch0: 3dslicer-pytorch-fedora-torch.patch BuildArch: noarch Requires: 3dslicer Requires: python3-torch Requires: python3-torchvision Requires: python3-packaging %description SlicerPyTorch provides the PyTorchUtils module, which other 3D Slicer extensions use to get PyTorch. In this package PyTorch is Fedora's python3-torch: the module reports that installation, never downloads PyTorch, and states which backend it has. Fedora's PyTorch runs on the CPU, or on AMD GPUs through ROCm; it has no CUDA support, so NVIDIA GPUs are not used. %prep %autosetup -n SlicerPyTorch-%{commit} -p1 %build # Pure-scripted: nothing to compile. %install # Install exactly what PyTorchUtils/CMakeLists.txt lists, at the paths # slicerMacroBuildScriptedModule uses. _mod=PyTorchUtils; _n=0 for _f in $(sed -n '/^set(MODULE_PYTHON_\(SCRIPTS\|RESOURCES\)$/,/^ )$/p' $_mod/CMakeLists.txt \ | grep -vE '^set\(|^ \)$' | sed -e 's/^ *//' -e "s/\${MODULE_NAME}/$_mod/g"); do test -f "$_mod/$_f" || { echo "ERROR: $_mod lists $_f, which is missing" >&2; exit 1; } install -Dpm0644 "$_mod/$_f" "%{buildroot}%{qtsm}/$_f" _n=$((_n + 1)) done test "$_n" -eq 3 || { echo "ERROR: installed $_n PyTorchUtils files, expected 3" >&2; exit 1; } ! grep -q 'light_the_torch._patch' <(sed -n '/def installTorch/,/^ def uninstallTorch/p' %{buildroot}%{qtsm}/PyTorchUtils.py | sed -n '1,/^ return torch$/p') \ || { echo "ERROR: installTorch can still reach light-the-torch" >&2; exit 1; } %files %license LICENSE %doc README.md %{qtsm}/PyTorchUtils.py %{qtsm}/Resources/Icons/PyTorchUtils.png %{qtsm}/Resources/UI/PyTorchUtils.ui %changelog * Sat Oct 10 2026 Morgan Hough - 0-0.1.20260730git74f8216f - Initial package. SlicerPyTorch's PyTorchUtils on Fedora's python3-torch: no download path, backend and no-CUDA stated (Patch0).