Skip to content

PyTorch version parsing fails for source builds due to non-numeric suffixes #112

@TheTrustedComputer

Description

@TheTrustedComputer

Describe the bug
The PyTorch version checking code does not correctly handle versions built from source; I am one of those affected. For example, pip shows an installation of the release build of PyTorch 2.5.1 as 2.5.0a0+gita8d6afb. However, the code attempts to convert 0a0 to an integer, which is obviously invalid due to the a character, producing the following error:

2025-02-16 05:07:44 | INFO | configs.config | Found GPU AMD Radeon RX 5500 XT
2025-02-16 05:07:44 | INFO | configs.config | Half-precision floating-point: True, device: cuda:0
Traceback (most recent call last):
  File "/home/rdna1_rocm-5.4_container/Software/RVC-Fumiama/web.py", line 15, in <module>
    from infer.modules.uvr5.modules import uvr
  File "/home/rdna1_rocm-5.4_container/Software/RVC-Fumiama/infer/modules/uvr5/modules.py", line 14, in <module>
    config = Config()
             ^^^^^^^^
  File "/home/rdna1_rocm-5.4_container/Software/RVC-Fumiama/configs/config.py", line 30, in __call__
    cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rdna1_rocm-5.4_container/Software/RVC-Fumiama/configs/config.py", line 55, in __init__
    self.x_pad, self.x_query, self.x_center, self.x_max = self.device_config()
                                                          ^^^^^^^^^^^^^^^^^^^^
  File "/home/rdna1_rocm-5.4_container/Software/RVC-Fumiama/configs/config.py", line 228, in device_config
    if tuple(map(int, torch.__version__.split("+")[0].split("."))) >= (2, 6, 0):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: '0a0'

To Reproduce
Create the PyTorch wheel locally, install it with pip, and run the following command:

python web.py

Expected behavior
The code should further initialize and load any required components without this error appearing.

Screenshots
Not applicable.

Desktop (please complete the following information):

  • OS and version: Debian 12 Docker
  • Python version: 3.11.2
  • Commit/Tag with the issue: dev

Additional context
This current method is ineffective because development versions of PyTorch include non-numeric suffixes that break the int() conversion. The fix is rather simple: use the packaging.version module for a more robust solution. This prevents issues for users who build PyTorch or install nightly builds. Here is a proposed fix:

from packaging import version

if version.parse(torch.__version__) >= version.parse("2.6.0"):

This approach ensures compatibility with all PyTorch versions regardless of their origin.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions