%global pypi_name torchvision %bcond_with gitcommit %if %{with gitcommit} # The ToT %global commit0 2c4665ffbb64f03f5d18016d3398af4ac4da5f03 %global shortcommit0 %(c=%{commit0}; echo ${c:0:7}) %global date0 20240326 %global pypi_version 0.19.0a0 %else %global pypi_version 0.27.1 %endif # check takes too long, make optional %bcond_with test # torch toolchain %global toolchain gcc Name: python-%{pypi_name} %if %{with gitcommit} Version: %{pypi_version}^git%{date0}.%{shortcommit0} %else Version: %{pypi_version} %endif # Fedora's own release is 6; 6.1 sorts above it so this build wins on f45 and # rawhide until Fedora fixes the import (see Patch2), and loses to its -7. Release: 6.1%{?dist} Summary: Image and video datasets for torch deep learning License: BSD-3-Clause AND BSD-2-Clause AND MIT URL: https://github.com/pytorch/vision %if %{with gitcommit} Source0: %{url}/archive/%{commit0}/vision-%{shortcommit0}.tar.gz %else Source0: %{url}/archive/refs/tags/v%{version}.tar.gz#/vision-v%{version}.tar.gz %endif # get the hip version, step on the cuda version Patch1: python-torchvision-fedora-better-cuda-version.patch # Fedora's Patch1 registers torchvision::_cuda_version only under WITH_HIP, but # extension.py calls it unconditionally, so `import torchvision` raises # AttributeError on every build without HIP (Fedora f45/rawhide, 0.27.1-6). # Register the op always. Drop this when Fedora's python-torchvision imports. Patch2: python-torchvision-always-register-cuda-version.patch # Limit to these because that is what torch is on ExclusiveArch: aarch64 x86_64 BuildRequires: gcc-c++ BuildRequires: ffmpeg-free BuildRequires: ffmpeg-free-devel BuildRequires: libavcodec-free-devel BuildRequires: libavformat-free-devel BuildRequires: libavutil-free-devel BuildRequires: libjpeg-turbo-devel BuildRequires: libpng-devel BuildRequires: libswresample-free-devel BuildRequires: libswscale-free-devel BuildRequires: libwebp-devel BuildRequires: ninja-build BuildRequires: pybind11-devel BuildRequires: python3-devel BuildRequires: zlib-devel BuildRequires: python3dist(numpy) BuildRequires: python3dist(setuptools) %if %{with test} BuildRequires: python3dist(pytest) %endif %ifarch x86_64 BuildRequires: hipblas-devel BuildRequires: hipblaslt-devel BuildRequires: hipsolver-devel BuildRequires: hipsparse-devel BuildRequires: rocm-core-devel BuildRequires: rocprim-devel BuildRequires: rocthrust-devel %endif Requires: python3dist(numpy) Requires: python3dist(pillow) Requires: python3dist(requests) Requires: python3dist(torch) %description The torchvision package consists of popular datasets, model architectures, and common image transformations for computer vision. %package -n python3-%{pypi_name} Summary: Image and video datasets for torch deep learning %description -n python3-%{pypi_name} The torchvision package consists of popular datasets, model architectures, and common image transformations for computer vision. %prep %if %{with gitcommit} %autosetup -p1 -n vision-%{commit0} %else %autosetup -p1 -n vision-%{version} %endif # Need some debug info sed -i -e 's@extra_compile_args["cxx"].append("-g0")@extra_compile_args["cxx"].append("-g")@' setup.py # Find ffmpeg on fedora sed -i -e 's@ffmpeg_include_dir = os.path.join(ffmpeg_root, "include")@ffmpeg_include_dir = os.path.join(ffmpeg_root, "include/ffmpeg")@' setup.py sed -i -e 's@ffmpeg_library_dir = os.path.join(ffmpeg_root, "lib")@ffmpeg_library_dir = os.path.join(ffmpeg_root, "lib64")@' setup.py %generate_buildrequires %pyproject_buildrequires %build # Building uses python3_sitearch/torch/utils/cpp_extension.py # cpp_extension.py does a general linking with all the pytorch libs which # leads warnings being reported by rpmlint. export ROCM_HOME=/usr export TORCHVISION_USE_WEBP=1 %pyproject_wheel %install %pyproject_install %pyproject_save_files %{pypi_name} # exec permission for f in `find %{buildroot}%{python3_sitearch} -name '*.py'`; do if [ ! -x $f ]; then sed -i '1{\@^#!/usr/bin@d}' $f fi done %check # Fedora ships no check, which is how an import-time failure reached users. # Leave the source tree: it holds an unbuilt torchvision/ that shadows the install. cd / PYTHONPATH=%{buildroot}%{python3_sitearch} %{__python3} -c 'import torchvision, torch; print(torchvision.__version__); print(torch.ops.torchvision._cuda_version())' %files -n python3-%{pypi_name} -f %{pyproject_files} %license LICENSE %doc README.md # License details # From license check output # # *No copyright* Creative Commons Attribution-NonCommercial 4.0 # ------------------------------------------------------------- # vision-0.16.0/README.md # # - from this section of README.md # ## Pre-trained Model License # # The pre-trained models provided in this library may have their own licenses or terms and conditions derived from the # dataset used for training. It is your responsibility to determine whether you have permission to use the models for your # use case. # %changelog * Sun Oct 25 2026 Morgan Hough - 0.27.1-6.1 - Rebuild of Fedora's python-torchvision 0.27.1-6 with torchvision::_cuda_version registered on every build, so `import torchvision` works on f45 and rawhide. Adds an import %%check. Unblocks python-fastsurfer and python-deepinv there.